예제 #1
0
        /// <summary>
        /// Changing type of cells around the ship that was killed and cells in which the ship located
        /// </summary>
        /// <param name="ship">Killed ship</param>
        private void SetKilledShipAndCellsAround(Ship ship)
        {
            int minRow = ship[0].Row > 1 ? ship[0].Row - 1 : ship[0].Row,
                minCol = ship[0].Col > 1 ? ship[0].Col - 1 : ship[0].Col;

            int maxRow = ship[ship.Length - 1].Row < Settings.boardSize ? ship[ship.Length - 1].Row + 1 : ship[ship.Length - 1].Row,
                maxCol = ship[ship.Length - 1].Col < Settings.boardSize ? ship[ship.Length - 1].Col + 1 : ship[ship.Length - 1].Col;

            for (int r = minRow; r <= maxRow; r++)
            {
                for (int c = minCol; c <= maxCol; c++)
                {
                    if (_cells[r, c].Type != TypeCell.MuffShot)
                    {
                        _cells[r, c].Type = TypeCell.AreaAroundShip;
                    }
                }
            }

            for (int i = 0; i < ship.Length; i++)
            {
                _cells[ship[i].Row, ship[i].Col].Type = TypeCell.KilledShip;
            }

            Ships.Find(s => s[0].Equals(ship[0])).IsKilled = true;
        }
예제 #2
0
        /// <summary>
        /// Add ships to list Ships
        /// </summary>
        private void AddShips()
        {
            int i;

            for (i = 0; i < Settings.fourDeckersCount; i++)
            {
                Ships.Add(new Ship(4));
            }
            for (i = 0; i < Settings.threeDeckersCount; i++)
            {
                Ships.Add(new Ship(3));
            }
            for (i = 0; i < Settings.twoDeckersCount; i++)
            {
                Ships.Add(new Ship(2));
            }
            for (i = 0; i < Settings.oneDeckersCount; i++)
            {
                Ships.Add(new Ship(1));
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: az4z3l/SeaBattle
        static void Main(string[] args)
        {
            Point[,] playerpoints    = new Point[10, 10];
            Point[,] AIpoints        = new Point[10, 10];
            Point[,] AIpointsForView = new Point[10, 10];
            Ships[] playersships = new Ships[10];
            Ships[] AIships      = new Ships[10];

            PointsInPoints(playerpoints, AIpoints, AIpointsForView);

            playersships[0] = new Ships(1); // Ships in playerships[].
            playersships[1] = new Ships(1);
            playersships[2] = new Ships(1);
            playersships[3] = new Ships(1);
            playersships[4] = new Ships(2);
            playersships[5] = new Ships(2);
            playersships[6] = new Ships(2);
            playersships[7] = new Ships(3);
            playersships[8] = new Ships(3);
            playersships[9] = new Ships(4);

            AIships[0] = new Ships(1); // Ships in AIships[].
            AIships[1] = new Ships(1);
            AIships[2] = new Ships(1);
            AIships[3] = new Ships(1);
            AIships[4] = new Ships(2);
            AIships[5] = new Ships(2);
            AIships[6] = new Ships(2);
            AIships[7] = new Ships(3);
            AIships[8] = new Ships(3);
            AIships[9] = new Ships(4);

            PlayerInput playerinput1 = new PlayerInput();         // Adding PlayerInput-module.
            AI          ai1          = new AI();                  // Adding AI-module.
            WinChecker  winchecker1  = new WinChecker();          // Adding WinChecker-module.

            playerinput1.Preparation(playerpoints, playersships); // Creating ships for player.
            ai1.AIPreparation(AIpoints, AIships);                 // Creating ships for AI.

            Point.SetStringsForPoints(AIpointsForView);
            Point.SetStringsForPoints(playerpoints);

            Renderer.Render(playerpoints);
            Renderer.Render(AIpointsForView);

            while (winchecker1.IsWin == 0)
            {
                playerinput1.GetPlayerInput(AIpoints, AIpointsForView, playerpoints); // Player's step.
                winchecker1.PlayerStep = 1;
                winchecker1.CheckWin(AIships);

                if (winchecker1.IsWin != 0)
                {
                    break;
                }

                ai1.AIShot(playerpoints, AIpointsForView); // AI's step.
                winchecker1.PlayerStep = 2;
                winchecker1.CheckWin(playersships);
            }

            winchecker1.Win();

            Console.ReadKey();
        }