示例#1
0
        private void ShotWithEnemyIntellegence(ref UserActions chosenAction)
        {
            do
            {
                UserInterface.ShowMessage(_enemyTurn);
                System.Threading.Thread.Sleep(1000);

                if (CheckExit())
                {
                    chosenAction = UserActions.GameOver;
                    break;
                }

                _enemysMind.MakeTheShot(ref _isAlivePlayerAfterRigthShoot, _playerMap);
                _isTargetPlayer = _enemysMind.IsTargetPlayer;

                _playerMap.CheckShipCondition(_isTargetPlayer, _isAlivePlayerAfterRigthShoot, _enemysMind);

                int cursorLeft = UserInterface.DISTANCE_BETWEEN_MAP;
                int cursorTop  = UserInterface.START_TOP_CURSOR;
                UserInterface.PrintShipPlayer(_playerMap, cursorLeft, cursorTop);
                UserInterface.ShowResultOfShot(_isAlivePlayerAfterRigthShoot, _isTargetPlayer);
                UserInterface.PrintExitSymbol();/////////////////

                System.Threading.Thread.Sleep(1500);
                bool shipSearched = _playerMap.SearchShips();

                if (!shipSearched)
                {
                    break;
                }
            } while (_isTargetPlayer);
        }
示例#2
0
        public void IsEnemyTurn(out string message, out bool isEnemyWin)
        {
            isEnemyWin = false;

            if (_isEasyLevel)
            {
                RandomCoords.SearchRandomCoords(_playerMap);
                _isTargetPlayer = _playerMap.HitTarget(ref _isAlivePlayerAfterRigthShoot);
            }
            else
            {
                _enemysMind.MakeTheShot(ref _isAlivePlayerAfterRigthShoot, _playerMap);
                _isTargetPlayer = _enemysMind.IsTargetPlayer;
                _playerMap.CheckShipCondition(_isTargetPlayer, _isAlivePlayerAfterRigthShoot, _enemysMind);
            }


            if (_isTargetPlayer)
            {
                message = (_playerMap.TargetCoordY + 1)
                          + ((Letters)_playerMap.TargetCoordX).ToString()
                          + "\nHit the target!"
                          + "\n Enemy's turn!";
            }
            else
            {
                message = (_playerMap.TargetCoordY + 1)
                          + ((Letters)_playerMap.TargetCoordX).ToString()
                          + "\nPast!!"
                          + "\nYour turn!";
            }

            if (!_playerMap.SearchShips())
            {
                isEnemyWin = true;
                message    = "ENEMY WON!!!";
            }
        }
示例#3
0
        public void IsPlayerTurn(out string message, out bool isEnemyTurn, out bool isPlayerWin)
        {
            isPlayerWin = false;
            isEnemyTurn = false;

            if (_enemyMap.SearchShips())
            {
                _isTargetEnemy = _enemyMap.HitTarget(ref _isAliveEnemyAfterRigthShot);

                if (_isTargetEnemy && !_isAliveEnemyAfterRigthShot)
                {
                    _enemyMap.MarkImpossibleTargets();
                }

                if (_isTargetEnemy)
                {
                    message = (_enemyMap.TargetCoordY + 1)
                              + ((Letters)_enemyMap.TargetCoordX).ToString()
                              + "\nHit the target!"
                              + "\n Your turn!";
                }
                else
                {
                    message = (_enemyMap.TargetCoordY + 1)
                              + ((Letters)_enemyMap.TargetCoordX).ToString()
                              + "\nPast!"
                              + "\nEnemy's turn!";
                    isEnemyTurn = true;
                }
            }
            else
            {
                message     = "YOU WON!!!";
                isPlayerWin = true;
            }
        }
示例#4
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);
                }
            }
        }