コード例 #1
0
ファイル: Gameplay.cs プロジェクト: wonderplayer/Savannah
 public void NewGame() {
     Animals = new List<IAnimal>();
     var board = new Board();
     board.Create();
     do {
         Play(board);
     } while (Animals.Count > 0);
 }
コード例 #2
0
 public void SetUp() {
     gameplay = new Gameplay {
         Animals = new List<IAnimal>()
     };
     animalActions= new AnimalActions();
     board = new Board();
     board.Create();
 }
コード例 #3
0
ファイル: Gameplay.cs プロジェクト: wonderplayer/Savannah
 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);
 }
コード例 #4
0
 public void SetUp() {
     antilope = new Antilope();
     antilopeActions = new AntilopeActions();
     gameplay = new Gameplay {
         Animals = new List<IAnimal>()
     };
     board = new Board();
     board.Create();
 }
コード例 #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);
     }
 }
コード例 #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;
 }
コード例 #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;
         }
     }
 }
コード例 #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);
     }
 }
コード例 #9
0
 private void MoveCurrentAnimal(Board board, List<IAnimal> animals, IAnimal animal) {
     CalculateCorrectPosition(board, animals, animal);
     MoveToNewPosition(animal);
 }
コード例 #10
0
ファイル: BoardTest.cs プロジェクト: wonderplayer/Savannah
 public void SetUp() {
     board = new Board();
 }