Exemplo n.º 1
0
        public static Position InputShipPosition(TypeOfShips deckCount, out Direction shipDirection,
                                                 ConsoleColor color = ConsoleColor.Yellow)
        {
            int  direction;
            bool isRigthDirection;

            Console.ForegroundColor = color;

            do
            {
                ClearBottom(0, 47, 7);

                Console.SetCursorPosition(0, 0);

                Console.WriteLine("DIRECTION:");

                for (Direction i = Direction.Up; i <= Direction.Left; i++)
                {
                    Console.WriteLine("{0} - {1}", i, ((int)i));
                }

                Console.Write("Please, input direction for {0} ship:", deckCount);

                isRigthDirection = int.TryParse(Console.ReadLine(), out direction);

                shipDirection = (Direction)direction;
            } while (!isRigthDirection || shipDirection < Direction.Up ||
                     shipDirection > Direction.Left);

            return(AreRigthCoords(SHIP_POSITION_MESSAGE, 6));
        }
Exemplo n.º 2
0
        public void SetOneShip(Direction currentDirection)
        {
            TypeOfShips deckCount = 0;

            if (_playerMapManualInput.CountAliveShips == 0)
            {
                deckCount = TypeOfShips.FourDecker;
            }
            else
            {
                if (_playerMapManualInput.CountAliveShips == 1 || _playerMapManualInput.CountAliveShips == COUNT_THREE_DECK_SHIP)
                {
                    deckCount = TypeOfShips.ThreeDecker;
                }
                else
                {
                    if (_playerMapManualInput.CountAliveShips >= COUNT_TWO_DECK_SHIP &&
                        _playerMapManualInput.CountAliveShips < (COUNT_ALL_SHIPS - COUNT_ONE_DECK_SHIP))
                    {
                        deckCount = TypeOfShips.TwoDecker;
                    }
                    else
                    {
                        if (_playerMapManualInput.CountAliveShips >= (COUNT_ALL_SHIPS - COUNT_ONE_DECK_SHIP) &&
                            _playerMapManualInput.CountAliveShips < COUNT_ALL_SHIPS)
                        {
                            deckCount = TypeOfShips.OneDecker;
                        }
                    }
                }
            }

            _playerMapManualInput.BuildOneTypeOfShips(deckCount, _startShipPosition, currentDirection);
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
        public bool BuildOneTypeOfShips(TypeOfShips deckCount, Position startShipPosition, Direction shipDirection)
        {
            bool isPossibleSetteing = true;

            _targetCoordY = startShipPosition.OY;
            _targetCoordX = startShipPosition.OX;

            for (TypeOfShips i = TypeOfShips.OneDecker; i <= deckCount; i++)
            {
                isPossibleSetteing = HasCollide();

                if (!isPossibleSetteing)
                {
                    break;
                }

                switch (shipDirection)
                {
                case Direction.Up:
                    _targetCoordY--;
                    break;

                case Direction.Right:
                    _targetCoordX++;
                    break;

                case Direction.Down:
                    _targetCoordY++;
                    break;

                case Direction.Left:
                    _targetCoordX--;
                    break;

                default:
                    break;
                }
            }

            if (isPossibleSetteing)
            {
                _targetCoordY = startShipPosition.OY;
                _targetCoordX = startShipPosition.OX;

                SetShips(deckCount, shipDirection);
            }

            return(isPossibleSetteing);///если false - возвращаем переменную и выводим пользователю сообщение что нужна новая позиция корабля
        }