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);
        }
Beispiel #2
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;
            }
        }