Beispiel #1
0
		static void Main(string[] args)
		{
			var engine = new Engine();

			var player1 = (Player) engine.CreateEntity<Player>().AddComponent(new GoldComponent(0)).AddComponent(new PeopleComponent(1));
			engine.CreateEntity<Player>().AddComponent(new GoldComponent(0)).AddComponent(new PeopleComponent(2));
			engine.AddSystem(new GoldSystem());

			engine.Start();

			ConsoleKeyInfo key;
			while ((key = Console.ReadKey()).Key != ConsoleKey.Q)
			{
			    if (key.Key == ConsoleKey.H)
			        player1.BuildHouse();

				engine.ProcessSystems();
				foreach (var entity in engine.GetEntitiesByComponents(typeof(GoldComponent)))
				{
					Console.WriteLine($"Entity {entity.Id} =>");
                    Console.WriteLine($"    Gold: {entity.GetComponent<GoldComponent>().Amount} - in {(DateTime.Now - engine.StartTime).TotalSeconds} seconds");
                    Console.WriteLine($"    People: {entity.GetComponent<PeopleComponent>().Amount}");
                    if (entity.HasComponent<HousesComponent>())
                        Console.WriteLine($"    Houses: {entity.GetComponent<HousesComponent>().Amount}");
                }
            }
		}