Пример #1
0
        private void ShotWithoutIntellegence(ref UserActions chosenAction)
        {
            do
            {
                UserInterface.ShowMessage(_enemyTurn);
                System.Threading.Thread.Sleep(1000);

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

                RandomCoords.SearchRandomCoords(_playerMap);
                _isTargetPlayer = _playerMap.HitTarget(ref _isAlivePlayerAfterRigthShoot);

                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
        private UserActions ShotPlayer()
        {
            UserActions chosenAction = UserActions.StartGame;

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

                bool shipSearched = _enemyMap.SearchShips();

                if (!shipSearched)
                {
                    break;
                }

                UserInterface.ShowMessage(_yourTurn);
                bool wasShot;

                do
                {
                    Position coords = UserInterface.AreRigthCoords();

                    if ((coords.OX == -1) || (coords.OY == -1))
                    {
                        _numberUserAction = UserActions.GameOver;
                        break;
                    }

                    _enemyMap.TargetCoordY = coords.OY;
                    _enemyMap.TargetCoordX = coords.OX;
                    wasShot = _enemyMap.WasShot();
                    UserInterface.AreSimilarCoords(wasShot);
                } while (wasShot);

                bool isFinishedOfShipEnemy = false;
                _isTargetEnemy = _enemyMap.HitTarget(ref isFinishedOfShipEnemy);

                int cursorLeft = UserInterface.START_LEFT_CURSOR;
                int cursorTop  = UserInterface.START_TOP_CURSOR;

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

                UserInterface.PrintShipEnemy(_enemyMap, cursorLeft, cursorTop);
                UserInterface.ShowResultOfShot(isFinishedOfShipEnemy, _isTargetEnemy);
                UserInterface.PrintExitSymbol();/////////////////

                System.Threading.Thread.Sleep(1500);
            } while (_isTargetEnemy);

            return(chosenAction);
        }
Пример #3
0
        public virtual void MakeTheShot(ref bool isAlivePlayerAfterShoot, Sea playerMap)
        {
            if (!isAlivePlayerAfterShoot)
            {
                RandomCoords.SearchRandomCoords(playerMap);
                _isTargetPlayer = playerMap.HitTarget(ref isAlivePlayerAfterShoot);

                if (_isTargetPlayer)
                {
                    SaveCoordsSuccessfulTarget(playerMap);
                }
            }
            else
            {
                GetTargetCoords(playerMap);
                _isTargetPlayer = playerMap.HitTarget(ref isAlivePlayerAfterShoot);
            }
        }
Пример #4
0
        public override void MakeTheShot(ref bool isAlivePlayerAfterShoot, Sea playerMap)
        {
            bool wasShot = false;

            if (!isAlivePlayerAfterShoot)
            {
                do
                {
                    if (_plentyShots.Count <= 0)
                    {
                        RandomCoords.SearchRandomCoords(playerMap);
                        //break;//
                    }
                    else
                    {
                        Position currentPos = _plentyShots.Dequeue();

                        playerMap.TargetCoordX = currentPos.OX;
                        playerMap.TargetCoordY = currentPos.OY;

                        wasShot = playerMap.WasShot();
                    }
                } while (wasShot);


                _isTargetPlayer = playerMap.HitTarget(ref isAlivePlayerAfterShoot);

                if (_isTargetPlayer)
                {
                    SaveCoordsSuccessfulTarget(playerMap);
                }
            }
            else
            {
                GetTargetCoords(playerMap);

                _isTargetPlayer = playerMap.HitTarget(ref isAlivePlayerAfterShoot);
            }
        }
Пример #5
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!!!";
            }
        }
Пример #6
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;
            }
        }