コード例 #1
0
        private void GetPlayerMap()
        {
            PlayerSea playerMapManualInput = null;

            switch (_introducedMethod)
            {
            case MethodShipsBuild.AutoRandom:
                _playerMap = new Sea(10);
                _playerMap.BuildAllTypeOfShips();
                break;

            case MethodShipsBuild.Manual:
                playerMapManualInput = new PlayerSea(10);

                bool        isPossibleSetting;
                int         shipCount = 1;
                TypeOfShips deckCount = TypeOfShips.FourDecker;

                Console.Clear();

                for (int i = 0; i < RandomCoords.COUNT_OF_SHIPS_TYPE; i++)
                {
                    for (int j = 0; j < shipCount; j++)
                    {
                        UserInterface.PrintManualInputShips(playerMapManualInput);
                        Console.SetCursorPosition(0, 0);
                        Direction shipDirection;
                        Position  shipPosition = UserInterface.InputShipPosition(deckCount, out shipDirection);
                        isPossibleSetting = playerMapManualInput.BuildOneTypeOfShips(deckCount,
                                                                                     shipPosition, shipDirection);

                        if (!isPossibleSetting)
                        {
                            UserInterface.ClearBottom(0, 45, 7);
                            UserInterface.ShowMessage(Constants.IMPOSSIBLE_SETTING, 0, 0);
                            System.Threading.Thread.Sleep(3000);
                            j--;
                            continue;
                        }

                        UserInterface.PrintManualInputShips(playerMapManualInput);
                    }

                    deckCount--;
                    shipCount++;
                }

                break;

            default:
                break;
            }

            if (_playerMap == null)
            {
                _playerMap = playerMapManualInput;
            }
        }
コード例 #2
0
        public void Run()
        {
            bool shipSearched = true;

            while (_numberUserAction == UserActions.StartGame && shipSearched)
            {
                Console.Clear();

                if (_isNewGame)
                {
                    _enemyMap = new Sea(RandomCoords.MAP_SIZE);
                    _enemyMap.BuildAllTypeOfShips();
                    GetPlayerMap();
                }

                Console.Clear();
                UserInterface.PrintStartPosition(_enemyMap, _playerMap);

                do
                {
                    shipSearched = _enemyMap.SearchShips();
                    if (!shipSearched)
                    {
                        break;
                    }

                    _numberUserAction = ShotPlayer();

                    if (_numberUserAction == UserActions.GameOver)
                    {
                        SaveGameCondition();
                        _isNewGame = false;
                        Console.Clear();
                        Console.WriteLine("GAME SAVED!\nPLease, press any key!");
                        break;
                    }

                    shipSearched = _enemyMap.SearchShips();
                    if (!shipSearched)
                    {
                        _isPlayerWinner = true;
                        break;
                    }

                    _numberUserAction = ShotEnemy();

                    if (_numberUserAction == UserActions.GameOver)
                    {
                        SaveGameCondition();
                        _isNewGame = false;
                        Console.Clear();
                        Console.WriteLine("GAME SAVED!\nPLease, press any key!");
                        break;
                    }
                } while (shipSearched);

                if (_numberUserAction == UserActions.StartGame)
                {
                    UserInterface.PrinPlayerWin(_isPlayerWinner);
                }
            }
        }
コード例 #3
0
ファイル: FormGame.cs プロジェクト: Bohdan24Bondar/Battleship
 public void SetEnemyMap()
 {
     _enemyMap.BuildAllTypeOfShips();
 }
コード例 #4
0
ファイル: FormGame.cs プロジェクト: Bohdan24Bondar/Battleship
 public void SetShipsAuto()
 {
     _playerMap = new Sea(10);
     _playerMap.BuildAllTypeOfShips();
 }