public void RemoveAnimal(AnimalEntity animal) { Species animalX = animal.Species; for (int i = 0; i < _animalList.Count; i++) { if (animal == _animalList[i]) { _animalList.RemoveAt(i); break; } } bool speciesOrphaned = false; for (int i = 0; i < _speciesList.Count; i++) { if (Object.ReferenceEquals(animalX, _speciesList[i])) { speciesOrphaned = true; break; } } if (speciesOrphaned) { _speciesList.Remove(animalX); } }
public void AddAnimal(AnimalEntity animal) { _animalList.Add(animal); for (int i = 0; i < _speciesList.Count; i++) { Species animalX = _speciesList[i]; if (Object.ReferenceEquals(animalX, animal.Species)) { continue; } else if (i == _speciesList.Count) { _speciesList.Add(animalX); } } }
/// <summary> /// Tries the breed with an other animal. /// </summary> /// <returns> /// The newly born animal, if successful. <c>null</c> if no new animal could /// be breeded. /// </returns> /// <param name='other'> /// The other animal. /// </param> /// <param name='allSpecies'> /// All species. /// </param> /// <remarks> /// Breeding may fail if no either the two species can't breed with each other or there is no /// free tile beside the animal. If breeding succeeds, a new animal is created and placed at a random /// neighbouring tile. /// </remarks> /// <returns> /// The newly created animal, if successful. <c>null</c> if breeding failed. /// </returns> public AnimalEntity TryBreedWith(AnimalEntity other) { if (!Species.BreedsWith(other.Species)) { return(null); } Tile newAnimalTile = Tile.FindRandomEmptyNeighbour(); if (null != newAnimalTile) { var child = new AnimalEntity(Species.BreedWith(other.Species, Tile.World.Game.Data.Species, Tile.World.Game.Random)); child.Tile = newAnimalTile; return(child); } return(null); }
/// <summary> /// Eat the specified other animal. /// </summary> /// <param name='other'> /// Other. /// </param> public void Eat(AnimalEntity other) { other.Tile = null; _hunger -= 1; }
static void Main(string[] args) { Console.WindowWidth = 100; Console.WindowHeight = 60; var data = new DataManager(); var balance = new Balancing(); var game = new Game(Console.WindowWidth - 22, Console.WindowHeight - 3, new Vector2(0, 3), balance, data); var menu = new ActionMenu(new Vector2(Console.WindowWidth - 22, 0), 22, 18); var menu2 = new InfoBar(game, new Vector2(0, 0), Console.WindowWidth - 22, 3); var menu3 = new CageMenu(new Vector2(Console.WindowWidth - 22, 18), 22, Console.WindowHeight - 18, game); var watch = new Stopwatch(); var key = new KeyPressManager(Console.WindowWidth - 20, Console.WindowHeight - 3, game); double menuUpdateInterval = 5; double timeSinceLastMenuUpdate = menuUpdateInterval; // Test code var cageType = CageType.ReadFromFile("../../../data/cages/cross.cage"); var species = new Species("Cow"); species.Symbol = 'c'; species.PooPeriod = 2; var cage = new Cage(cageType, new Vector2(3, 3), game, balance, false); game.Cages.SelectedCage = cage; var cow1 = new AnimalEntity(species); var cow2 = new AnimalEntity(species); cow1.Tile = cage.EnclosedTiles[0]; cow2.Tile = cage.EnclosedTiles[2]; // End of test code watch.Start(); while (true) { double dt = 0.001 * (double)watch.ElapsedMilliseconds; watch.Restart(); game.Update(dt); ///<summary> ///key input handling ///</summary> //key.KeyInput(); game.World.Draw(); timeSinceLastMenuUpdate += dt; if (timeSinceLastMenuUpdate >= menuUpdateInterval) { menu.Draw(); menu2.Draw(); menu3.Draw(); timeSinceLastMenuUpdate = 0; } // This is to avoid an 'empty' line at the bottom of the screen Console.SetCursorPosition(0, 0); if (1.0 / _fps * 0.001 > dt) { Thread.Sleep(Math.Max(0, (int)((long)(1.0 / _fps * 1000.0) - watch.ElapsedMilliseconds))); } } }