예제 #1
0
        public GameBoard(int tableSize, bool automaticYes)

        {
            GameBoard.tableSize = tableSize;
            this.automaticYes   = automaticYes;

            //init player 1 own ships table with emptiness

            for (int i = 0; i < GameBoard.tableSize; i++)
            {
                Player1Board1.Add(new List <BoardSquareState>());
                for (int j = 0; j < GameBoard.tableSize; j++)
                {
                    Player1Board1[i].Add(BoardSquareState.Empty);
                }
            }

            //init player 2 own ships table with emptiness

            for (int i = 0; i < GameBoard.tableSize; i++)
            {
                Player2Board1.Add(new List <BoardSquareState>());
                for (int j = 0; j < GameBoard.tableSize; j++)
                {
                    Player2Board1[i].Add(BoardSquareState.Empty);
                }
            }
        }
예제 #2
0
        //Player1Board1

        public GameBoard(int tableDimension, bool isAutomatic)

        {
            ShipTypes.Add(Ships.Carrier);
            ShipTypes.Add(Ships.Battleship);
            ShipTypes.Add(Ships.Submarine);
            ShipTypes.Add(Ships.Cruiser);
            ShipTypes.Add(Ships.Patrol);

            ShipLengths.Add(4);
            ShipLengths.Add(3);
            ShipLengths.Add(2);
            ShipLengths.Add(1);
            ShipLengths.Add(0);



            TableDimension   = tableDimension;
            this.isAutomatic = isAutomatic;

            //player 1 own ships table

            for (int i = 0; i < TableDimension; i++)
            {
                Player1Board1.Add(new List <BoardSquareState>());
                for (int j = 0; j < TableDimension; j++)
                {
                    Player1Board1[i].Add(BoardSquareState.Empty);
                }
            }



            //player 2 own ships table

            for (int i = 0; i < TableDimension; i++)
            {
                Player2Board1.Add(new List <BoardSquareState>());
                for (int j = 0; j < TableDimension; j++)
                {
                    Player2Board1[i].Add(BoardSquareState.Empty);
                }
            }
        }
예제 #3
0
        //Player1Board1

        public GameBoard(int tableDimension, bool isAutomatic)

        {
            ShipTypes.Add(Ships.Carrier);
            ShipTypes.Add(Ships.Battleship);
            ShipTypes.Add(Ships.Submarine);
            ShipTypes.Add(Ships.Cruiser);
            ShipTypes.Add(Ships.Patrol);

            ShipLengths.Add(4);
            ShipLengths.Add(3);
            ShipLengths.Add(2);
            ShipLengths.Add(1);
            ShipLengths.Add(0);

            /*Player1ShipCoordinates.Add("11");
             * Player1ShipCoordinates.Add("22");
             * Player1ShipCoordinates.Add("47");
             * Player1ShipCoordinates.Add("33");
             * Player1ShipCoordinates.Add("64");
             * Player1ShipDirections.Add(Directions.E);
             * Player1ShipDirections.Add(Directions.S);
             * Player1ShipDirections.Add(Directions.W);
             * Player1ShipDirections.Add(Directions.E);
             * Player1ShipDirections.Add(Directions.E);
             *
             * Player2ShipCoordinates.Add("11");
             * Player2ShipCoordinates.Add("22");
             * Player2ShipCoordinates.Add("47");
             * Player2ShipCoordinates.Add("33");
             * Player2ShipCoordinates.Add("64");
             * Player2ShipDirections.Add(Directions.E);
             * Player2ShipDirections.Add(Directions.S);
             * Player2ShipDirections.Add(Directions.W);
             * Player2ShipDirections.Add(Directions.E);
             * Player2ShipDirections.Add(Directions.E);*/


            TableDimension   = tableDimension;
            this.isAutomatic = isAutomatic;

            //player 1 own ships table
            Console.WriteLine("PLAYER 1");
            for (int i = 0; i < TableDimension; i++)
            {
                Player1Board1.Add(new List <BoardSquareState>());
                for (int j = 0; j < TableDimension; j++)
                {
                    Player1Board1[i].Add(BoardSquareState.Empty);
                }
            }

            if (this.isAutomatic)
            {
                AutomaticShipCoordinates1();
            }
            else
            {
                ManualShipCoordinates1();
            }

            //place player 1 ships on table
            foreach (var coordinate in Player1ShipCoordinates)
            {
                x_coord = Int32.Parse(coordinate.Substring(0, 1));
                y_coord = Int32.Parse(coordinate.Substring(1, 1));
                Player1Board1[x_coord - 1][y_coord] =
                    BoardSquareState.Ship;

                counter1 = ShipLengths[counter];
                if (Player1ShipDirections[counter] == Directions.W)
                {
                    for (int i = counter1; i >= 0; i--)
                    {
                        Player1Board1[x_coord - 1][y_coord - i] = BoardSquareState.Ship;
                    }
                }
                else if (Player1ShipDirections[counter] == Directions.N)
                {
                    for (int i = counter1; i >= 0; i--)
                    {
                        Player1Board1[x_coord - 1 - i][y_coord] = BoardSquareState.Ship;
                    }
                }
                else if (Player1ShipDirections[counter] == Directions.E)
                {
                    for (int i = counter1; i >= 0; i--)
                    {
                        Player1Board1[x_coord - 1][y_coord + i] = BoardSquareState.Ship;
                    }
                }
                else if (Player1ShipDirections[counter] == Directions.S)
                {
                    for (int i = counter1; i >= 0; i--)
                    {
                        Player1Board1[x_coord - 1 + i][y_coord] = BoardSquareState.Ship;
                    }
                }

                counter1 = 0;
                counter++;
            }

            //player 1 enemy ships table

            for (int i = 0; i < TableDimension; i++)
            {
                Player1Board2.Add(new List <BoardSquareState>());
                for (int j = 0; j < TableDimension; j++)
                {
                    Player1Board2[i].Add(BoardSquareState.Unknown);
                }
            }

            counter = 0;

            //player 2 own ships table
            Console.WriteLine("PLAYER 2");
            for (int i = 0; i < TableDimension; i++)
            {
                Player2Board1.Add(new List <BoardSquareState>());
                for (int j = 0; j < TableDimension; j++)
                {
                    Player2Board1[i].Add(BoardSquareState.Empty);
                }
            }

            if (this.isAutomatic)
            {
                AutomaticShipCoordinates2();
            }
            else
            {
                ManualShipCoordinates2();
            }

            //place player 2 ships on table
            foreach (var coordinate in Player1ShipCoordinates)
            {
                x_coord = Int32.Parse(coordinate.Substring(0, 1));
                y_coord = Int32.Parse(coordinate.Substring(1, 1));
                Player2Board1[x_coord][y_coord] =
                    BoardSquareState.Ship;

                counter1 = ShipLengths[counter];
                if (Player2ShipDirections[counter] == Directions.W)
                {
                    for (int i = counter1; i >= 0; i--)
                    {
                        Player2Board1[x_coord - 1][y_coord - i] = BoardSquareState.Ship;
                    }
                }
                else if (Player2ShipDirections[counter] == Directions.N)
                {
                    for (int i = counter1; i >= 0; i--)
                    {
                        Player2Board1[x_coord - 1 - i][y_coord] = BoardSquareState.Ship;
                    }
                }
                else if (Player2ShipDirections[counter] == Directions.E)
                {
                    for (int i = counter1; i >= 0; i--)
                    {
                        Player2Board1[x_coord - 1][y_coord + i] = BoardSquareState.Ship;
                    }
                }
                else if (Player2ShipDirections[counter] == Directions.S)
                {
                    for (int i = counter1; i >= 0; i--)
                    {
                        Player2Board1[x_coord - 1 + i][y_coord] = BoardSquareState.Ship;
                    }
                }

                counter1 = 0;
                counter++;
            }

            counter = 0;

            //player 2 enemy ships table

            for (int i = 0; i < TableDimension; i++)
            {
                Player2Board2.Add(new List <BoardSquareState>());
                for (int j = 0; j < TableDimension; j++)
                {
                    Player2Board2[i].Add(BoardSquareState.Unknown);
                }
            }
        }