public AnimalProvider(Zoo zoo) { _zoo = zoo; _zoo.Provider = this; for (var i = 0; i < 1000; i++) GenerateAnimal(); }
static void Main(string[] args) { Logger.Log("Starting program"); var thread = new Thread(() => { var zoo = new Zoo(); EarthLiveTicker.LiveTicker.Subscribe(zoo); var animalProvider = new AnimalProvider(zoo); EarthLiveTicker.LiveTicker.Subscribe(animalProvider); }); thread.Start(); Logger.Log("Animan provider started working"); Console.ReadKey(); Console.ReadKey(); }
/* * Interface theInterface; * Zoo theZoo; * * long lastTime; * long elapsedTime; */ static void Main(string[] args) { int CYCLE_TIME = 100; Interface theInterface = new Interface(); Zoo theZoo = new Zoo(theInterface); Boolean isGameAlive = true; DateTime lastTime = DateTime.Now; double elapsedTime; GameState State = GameState.GS_STATUS; Console.WindowHeight = Screen.High + 1; Console.WindowWidth = Screen.Wide; Console.BufferHeight = Screen.High + 1; Console.BufferWidth = Screen.Wide; /* * theInterface.DisplayBanner("Welcome to Zoo Game!"); * theInterface.Write("What is your zoo called?"); * * String tempName = Console.ReadLine(); * if (tempName != "") * { theZoo.name = tempName; * } */ lastTime = DateTime.Now; State = GameState.GS_MAP; //theZoo.AddLion(); for (int i = 0; i < 5; i++) { theZoo.AddZebra(); } //Lion l1 = theZoo.GetAnimalsOfType<Lion>().First<Lion>(); //Zebra z1 = theZoo.GetAnimalsOfType<Zebra>().First<Zebra>(); //l1.MoveTo(40,20); //z1.MoveTo(41,21); while (isGameAlive) { elapsedTime = DateTime.Now.Subtract(lastTime).TotalMilliseconds; if (Console.KeyAvailable) { // check for command ConsoleKeyInfo key = Console.ReadKey(true); switch (key.Key) { // take action case ConsoleKey.Q: isGameAlive = false; break; case ConsoleKey.Z: theZoo.AddZebra(); break; case ConsoleKey.L: theZoo.AddLion(); break; case ConsoleKey.M: if (State == GameState.GS_STATUS) { State = GameState.GS_MAP; } else if (State == GameState.GS_MAP) { State = GameState.GS_STATUS; } break; case ConsoleKey.O: theZoo.map.waterLevel += 0.1; break; case ConsoleKey.P: theZoo.map.waterLevel -= 0.1; break; } } if (elapsedTime > CYCLE_TIME) { theZoo.Update(elapsedTime); if (State == GameState.GS_STATUS) { theInterface.DisplayStatus(theZoo); } else { theInterface.DisplayMap(theZoo); } lastTime = DateTime.Now; } } }
static void Process(int choose) { zoo = new Zoo(); switch (choose) { case 1: { Console.WriteLine("Add a new cage: "); Console.Write("--- Enter the cage's number: "); string str = Console.ReadLine(); while (!int.TryParse(str, out cageNumber)) { Console.Write("Enter again! "); str = Console.ReadLine(); } MenuAnimal(); cage = new Cage(cageNumber); zoo.AddAnimal(cage); } break; case 2: { Console.WriteLine("Enter the cage's number you want to remove: "); string str = Console.ReadLine(); while (!int.TryParse(str, out cageNumber)) { Console.Write("Enter again! "); str = Console.ReadLine(); } zoo.RemoveCage(cageNumber); } break; case 3: { Console.Write("Choose 'dog'(press 1), 'cat' (press 2) or 'tiger' (press 3) to add: "); str = Console.ReadLine(); int child; while (!int.TryParse(str, out child)) { Console.Write("Enter again! "); str = Console.ReadLine(); } switch (child) { case 1: Console.Write("Enter the name of dog: "); string name = Console.ReadLine(); dog = new Dog(name); cage.AddAnimal(dog); break; case 2: Console.Write("Enter the name of cat: "); name = Console.ReadLine(); cat = new Cat(name); cage.AddAnimal(cat); break; case 3: Console.Write("Enter the name of tiger: "); name = Console.ReadLine(); tiger = new Tiger(name); cage.AddAnimal(tiger); break; default: Console.Write("Enter again! "); str = Console.ReadLine(); break; } } break; case 4: { Console.Write("Enter the name of animal you want to remove: "); string name = Console.ReadLine(); cage.RemoveAnimal(name); } break; case 5: { Console.WriteLine("\nIterate animal in the cage:"); Console.Write("Animal"); cage.IterateAnimals(); } break; case 6: Console.WriteLine("Exit."); Environment.Exit(Environment.ExitCode); break; default: Console.WriteLine("Enter 1, 2, 3, 4 or 5: "); Menu(); break; } Menu(); }
public void RenderMap(SCREEN_ELEMENT[,] screen, Zoo theZoo) { CopyTerrainToScreenBuffer(screen); RenderAnimals(screen, theZoo); }