Exemplo n.º 1
0
 public void NewGame() {
     Animals = new List<IAnimal>();
     var board = new Board();
     board.Create();
     do {
         Play(board);
     } while (Animals.Count > 0);
 }
Exemplo n.º 2
0
 public void SetUp() {
     gameplay = new Gameplay {
         Animals = new List<IAnimal>()
     };
     animalActions= new AnimalActions();
     board = new Board();
     board.Create();
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 public void SetUp() {
     antilope = new Antilope();
     antilopeActions = new AntilopeActions();
     gameplay = new Gameplay {
         Animals = new List<IAnimal>()
     };
     board = new Board();
     board.Create();
 }
Exemplo n.º 5
0
 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);
     }
 }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
 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;
         }
     }
 }
Exemplo n.º 8
0
 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);
     }
 }
Exemplo n.º 9
0
 private void MoveCurrentAnimal(Board board, List<IAnimal> animals, IAnimal animal) {
     CalculateCorrectPosition(board, animals, animal);
     MoveToNewPosition(animal);
 }
Exemplo n.º 10
0
 public void SetUp() {
     board = new Board();
 }