Beispiel #1
0
        public FieldParams CreateFieldParams()
        {
            int height;
            int width;
            int ships;

            Console.WriteLine("Enter Height of Field");
            bool result = int.TryParse(Console.ReadLine(), out height);

            if (!result)
            {
                return(DumbHuman());
            }
            Console.WriteLine("Enter Width of Field");
            bool result1 = int.TryParse(Console.ReadLine(), out width);

            if (!result1)
            {
                return(DumbHuman());
            }
            Console.WriteLine("Enter a number of Ships");
            bool result2 = int.TryParse(Console.ReadLine(), out ships);

            if (!result2)
            {
                return(DumbHuman());
            }
            FieldParams newParams = new FieldParams();

            newParams.width  = width + 1;
            newParams.height = height + 1;
            newParams.ships  = ships;

            return(newParams);
        }
Beispiel #2
0
        public Field CreateField(FieldParams fieldParams)
        {
            char[,] field = new char[fieldParams.height, fieldParams.width];
            int height = fieldParams.height;
            int width  = fieldParams.width;
            int ships  = fieldParams.ships;

            Random rand = new Random();

            int gridNumber = 49;
            int gridLetter = 65;

            for (int i = 0; i < height; i++) //почему-то поле может быть только квадратным
            {
                for (int j = 0; j < width; j++)
                {
                    field[i, j] = Constants.EmptyCell;

                    if (i == 0 && j == 0)
                    {
                        field[i, j] = Constants.EmptyCell;
                    }

                    if (i == 0 && j != 0)
                    {
                        field[i, j] = (char)gridLetter;
                        gridLetter++;
                    }

                    if (i != 0 && j == 0)
                    {
                        field[i, j] = (char)gridNumber;
                        gridNumber++;
                    }
                }
            }

            int setedShips = 0;

            while (setedShips < ships)
            {
                int ShipPosY = rand.Next(1, height);
                int ShipPosX = rand.Next(1, height);
                if (CanSetShip(field, ShipPosY, ShipPosX))
                {
                    field[ShipPosY, ShipPosX] = Constants.ShipSymbol;
                    setedShips++;
                }
            }

            Field warField = new Field(fieldParams, field);

            return(warField);
        }
Beispiel #3
0
        public void DrawOpenField(GamePlayer botGamePlayer)
        {
            char[,] fieldSymbols = botGamePlayer.gameField.fieldSymbols;
            FieldParams myfieldParams = botGamePlayer.gameField.myfieldParams;

            for (int i = 0; i < myfieldParams.height; i++)
            {
                for (int j = 0; j < myfieldParams.width; j++)
                {
                    Console.Write(fieldSymbols[i, j]);
                }
                Console.WriteLine();
            }
        }
Beispiel #4
0
        public void DrawHiddenField(GamePlayer botGamePlayer)
        {
            char[,] fieldSymbols = botGamePlayer.gameField.fieldSymbols;
            FieldParams myfieldParams = botGamePlayer.gameField.myfieldParams;

            for (int i = 0; i < myfieldParams.height; i++)
            {
                for (int j = 0; j < myfieldParams.width; j++)
                {
                    if (fieldSymbols[i, j] == Constants.ShipSymbol)
                    {
                        Console.Write(Constants.EmptyCell);
                    }
                    else
                    {
                        Console.Write(fieldSymbols[i, j]);
                    }
                }
                Console.WriteLine();
            }
        }
Beispiel #5
0
 public Field(FieldParams fieldParams, char[,] newFielSymbols)
 {
     myfieldParams = fieldParams;
     fieldSymbols  = newFielSymbols;
 }