Last active
July 27, 2018 21:26
-
-
Save thai-ng/558235c20a4daf80ee8c9f2212acea6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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