Esempio n. 1
0
 public (int x, int y) ChooseTarget(GameGrid grid)
 {
     return(_rng.Next(0, grid.Size), _rng.Next(0, grid.Size));
 }
Esempio n. 2
0
        private void ConductRound(IPlayer conductingPlayer, PlayerSrouceEnum playerSrouce, GameGrid enemyPlayerGrid)
        {
            var canContinue = true;

            while (canContinue)
            {
                // Ask player to choose target until they provide a valid one
                var validChoice = false;
                int x = 0, y = 0;
                while (!validChoice)
                {
                    (x, y)      = conductingPlayer.ChooseTarget(enemyPlayerGrid);
                    validChoice = _shootingRule.IsAllowed(enemyPlayerGrid, x, y);
                }

                var hit          = enemyPlayerGrid.Shoot(x, y);
                var anyShipsLeft = enemyPlayerGrid.Ships.Any(x => !x.Sunk);

                canContinue = hit && anyShipsLeft;

                Log(playerSrouce, x, y);
            }
        }