Skip to content

Instantly share code, notes, and snippets.

@thai-ng
Last active July 27, 2018 21:26
Show Gist options
  • Save thai-ng/558235c20a4daf80ee8c9f2212acea6c to your computer and use it in GitHub Desktop.
Save thai-ng/558235c20a4daf80ee8c9f2212acea6c to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace NetCoreConsolePlayground
{
class Entity
{
public Vector3 Postion;
public Quaternion Rotation;
}
class Player : Entity
{
public string PlayerId;
public IEnumerable<Monster> FindNearbyMonsters()
{
if (Game.Instance == null)
{
throw new Exception("There is no game!");
}
var allMonsters = Game.Instance.Monsters;
return allMonsters.Where(m => Vector3.Distance(m.Postion, this.Postion) < 2).ToList();
}
}
class Monster : Entity
{
public string MonsterType;
}
class Game
{
public Player Player;
public IEnumerable<Monster> Monsters = new List<Monster>();
public static Game Instance = null;
public Game()
{
Instance = this;
}
}
class Program
{
static void Main(string[] args)
{
Game game = new Game();
List<Monster> monsters = new List<Monster>();
monsters.Add(new Monster());
monsters.Add(new Monster());
monsters.Add(new Monster());
monsters.Add(new Monster());
game.Monsters = monsters;
Player player = new Player();
game.Player = player;
var nearbyMonsters = player.FindNearbyMonsters();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment