Example #1
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);
        }
Example #2
0
        public static void SearchRandomCoords(Sea playerMap)
        {
            bool wasShot;

            do
            {
                GetRandomCoords(playerMap);

                wasShot = playerMap.WasShot();
            } while (wasShot);
        }
Example #3
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);
            }
        }
Example #4
0
        public void GetTargetCoords(Sea playerMap)
        {
            bool wasShot = true;

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

            do
            {
                if (_targetDirection > Direction.Left)
                {
                    _targetDirection = Direction.Up;
                }

                switch (_targetDirection)
                {
                case Direction.Up:
                    playerMap.TargetCoordY -= _counterSuccessfulShot;
                    break;

                case Direction.Right:
                    playerMap.TargetCoordX += _counterSuccessfulShot;
                    break;

                case Direction.Down:
                    playerMap.TargetCoordY += _counterSuccessfulShot;
                    break;

                case Direction.Left:
                    playerMap.TargetCoordX -= _counterSuccessfulShot;
                    break;

                default:
                    break;
                }

                if ((playerMap.TargetCoordX < 0) || (playerMap.TargetCoordX >= RandomCoords.MAP_SIZE) ||
                    (playerMap.TargetCoordY < 0) ||
                    (playerMap.TargetCoordY >= RandomCoords.MAP_SIZE))
                {
                    if (_counterSuccessfulShot >= RandomCoords.COUNT_OF_COORDS)
                    {
                        playerMap.TargetCoordY = _cleanShotPosition.OY;
                        playerMap.TargetCoordX = _cleanShotPosition.OX;
                        _targetDirection      += RandomCoords.COUNT_OF_COORDS;
                        continue;
                    }
                    else
                    {
                        playerMap.TargetCoordY = _cleanShotPosition.OY;
                        playerMap.TargetCoordX = _cleanShotPosition.OX;
                        _counterSuccessfulShot = 1;
                        _targetDirection++;
                        continue;
                    }
                }

                wasShot = playerMap.WasShot();

                if ((_counterSuccessfulShot < RandomCoords.SECCESSFUL_SHOT) && wasShot)
                {
                    _targetDirection++;
                    _counterSuccessfulShot = 1;
                    playerMap.TargetCoordY = _cleanShotPosition.OY;
                    playerMap.TargetCoordX = _cleanShotPosition.OX;
                }
                else
                {
                    if (wasShot && _counterSuccessfulShot >= RandomCoords.SECCESSFUL_SHOT)
                    {
                        int counter = (int)_targetDirection + RandomCoords.SECCESSFUL_SHOT;
                        _targetDirection       = (Direction)counter;
                        _counterSuccessfulShot = 1;
                        playerMap.TargetCoordY = _cleanShotPosition.OY;
                        playerMap.TargetCoordX = _cleanShotPosition.OX;
                    }
                }
            } while (wasShot);
        }