public void NewGame() { Animals = new List<IAnimal>(); var board = new Board(); board.Create(); do { Play(board); } while (Animals.Count > 0); }
public void SetUp() { gameplay = new Gameplay { Animals = new List<IAnimal>() }; animalActions= new AnimalActions(); board = new Board(); board.Create(); }
private void Play(Board board) { board.FillWithAnimals(Animals); board.Show(); board.Clear(Animals); inGameMenu.Show(this); Console.Clear(); animalActions.Move(board, Animals); animalActions.Die(Animals); }
public void SetUp() { antilope = new Antilope(); antilopeActions = new AntilopeActions(); gameplay = new Gameplay { Animals = new List<IAnimal>() }; board = new Board(); board.Create(); }
private void CalculateCorrectPosition(Board board, List<IAnimal> animals, IAnimal animal) { adderForXPosition = Program.Random.Next(-1, 2); adderForYPosition = Program.Random.Next(-1, 2); while (board.OutOfBounds(adderForXPosition, adderForYPosition, board.Layout, animal) || PlaceIsNotFree(animal, animals) || DidntMove()) { adderForXPosition = Program.Random.Next(-1, 2); adderForYPosition = Program.Random.Next(-1, 2); } }
public bool TryToRunAway(List<IAnimal> animals, Board board, Antilope antilope) { IEnumerable<IAnimal> lionsAround = SearchForLions(animals, antilope); IEnumerable<IAnimal> enumeratedLionsAround = lionsAround as IList<IAnimal> ?? lionsAround.ToList(); if (!enumeratedLionsAround.Any()) { return false; } RunAway(animals, enumeratedLionsAround, board, antilope); return true; }
private void RunAway(List<IAnimal> animals, IEnumerable<IAnimal> lionsAround, Board board, Antilope antilope) { IEnumerable<IAnimal> enumeratedLionsAround = lionsAround as IList<IAnimal> ?? lionsAround.ToList(); for (int y = -1; y <= 1; y++) { for (int x = -1; x <= 1; x++) { if (board.OutOfBounds(x, y, board.Layout, antilope) || !SpaceIsFree(animals, x, y, antilope) || !IsSafePlaceToGo(enumeratedLionsAround, x, y, antilope)) { continue; } MoveTo(x, y, antilope); return; } } }
public void Move(Board boardManager, List<IAnimal> animals) { foreach (IAnimal animal in animals) { if (IsLion(animal)) { var lion = (Lion) animal; var lionActions = new LionActions(); bool ate = lionActions.TryToEat(animals, lion); if (ate) { continue; } } if (IsAntilope(animal)) { var antilope = (Antilope) animal; var antilopeActions = new AntilopeActions(); bool ranAway = antilopeActions.TryToRunAway(animals, boardManager, antilope); if (ranAway) { continue; } } MoveCurrentAnimal(boardManager, animals, animal); } }
private void MoveCurrentAnimal(Board board, List<IAnimal> animals, IAnimal animal) { CalculateCorrectPosition(board, animals, animal); MoveToNewPosition(animal); }
public void SetUp() { board = new Board(); }