Esempio n. 1
0
        //
        // ..=........................MAIN.........................
        //
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            GameBoard playerOneBoard, playerOneDisplayBoard, playerTwoBoard, playerTwoDisplayBoard;

            Battleships[] pOneShips   = new Battleships[5];
            Battleships[] pTwoShips   = new Battleships[5];
            bool          gameOver    = false;
            int           turnCounter = 0;

            // // // // // // // // // // // // // // //

            InitialiseGame();                                     //Splash screen and grid size initialisation
            InitialiseShips(pOneShips);                           //Initialising ship lists
            InitialiseShips(pTwoShips);
            playerOneBoard        = InitialisePlayerBoard();      //Initialising all gameboard states
            playerOneDisplayBoard = InitialisePlayerBoard();
            playerTwoBoard        = InitialisePlayerBoard();
            playerTwoDisplayBoard = InitialisePlayerBoard();
            PrintPlayerBoards(playerOneDisplayBoard, playerOneBoard);   //Initial board display

            // // // // // // // // // // // // // // //
            Console.WriteLine("Player One, place your ships");
            EnterToContinue();
            PlaceTokens(playerOneBoard, pOneShips);

            Console.WriteLine("Player Two, place your ships");
            EnterToContinue();
            PlaceTokens(playerTwoBoard, pTwoShips);

            // // // // // // // // // // // // // // //

            while (gameOver == false)
            {
                ++turnCounter;
                TurnPreface(turnCounter);
                FireSalvo(playerOneDisplayBoard, playerOneBoard, playerTwoBoard, pOneShips);    //First player's turn, taking player 1's displayboard and playing board to display, and player 2's playing board to check against
                gameOver = WinCondition(pOneShips);
                if (gameOver)
                {
                    break;
                }

                ////////////

                ++turnCounter;
                TurnPreface(turnCounter);
                FireSalvo(playerTwoDisplayBoard, playerTwoBoard, playerOneBoard, pTwoShips);    //Second player's turn, taking player 2's displayboard and playing board to display, and player 1's playing board to check against
                gameOver = WinCondition(pTwoShips);
            }



            Console.WriteLine("GAME WON");
            Console.ReadLine();
        }
Esempio n. 2
0
        static Coordinate GetRightLocationToShot(Panel victimboard)
        {
            List <Coordinate> tmpList = new List <Coordinate> {
            };

            for (int i = 0; i < victimboard.Ships.Length; i++)
            {
                Battleships tmpShip = victimboard.Ships[i];
                for (int j = 0; j < tmpShip.PanelPositions.Length; j++)
                {
                    if (victimboard.CheckCoordinate(tmpShip.PanelPositions[j]) == ShipTargets.Unknown)
                    {
                        tmpList.Add(tmpShip.PanelPositions[j]);
                    }
                }
            }

            return(tmpList[GetRandom.r.Next(0, tmpList.Count - 1)]);
        }
Esempio n. 3
0
        static void InitialiseShips(Battleships[] shipListIN)
        {
            for (int x = 0; x < shipListIN.Length; x++) //Used to instantiate the Battleships objects
            {
                switch (x)                              //Battleship list is always Carrier, Cruiser, Destroyer, Submarine, Patrol. Therefore switch is used to instantiate the different battleship types
                {
                case 0:
                    shipListIN[x] = new Battleships();
                    shipListIN[x]._columnPosition = new int[5];
                    shipListIN[x]._rowPosition    = new int[5];
                    shipListIN[x]._id             = "Carrier";
                    shipListIN[x]._shipLength     = 5;
                    shipListIN[x]._hitsTaken      = 0;
                    shipListIN[x]._shipActive     = true;
                    break;

                case 1:
                    shipListIN[x] = new Battleships();
                    shipListIN[x]._columnPosition = new int[4];
                    shipListIN[x]._rowPosition    = new int[4];
                    shipListIN[x]._id             = "Cruiser";
                    shipListIN[x]._shipLength     = 4;
                    shipListIN[x]._hitsTaken      = 0;
                    shipListIN[x]._shipActive     = true;
                    break;

                case 2:
                    shipListIN[x] = new Battleships();
                    shipListIN[x]._columnPosition = new int[3];
                    shipListIN[x]._rowPosition    = new int[3];
                    shipListIN[x]._id             = "Destroyer";
                    shipListIN[x]._shipLength     = 3;
                    shipListIN[x]._hitsTaken      = 0;
                    shipListIN[x]._shipActive     = true;
                    break;

                case 3:
                    shipListIN[x] = new Battleships();
                    shipListIN[x]._columnPosition = new int[3];
                    shipListIN[x]._rowPosition    = new int[3];
                    shipListIN[x]._id             = "Submarine";
                    shipListIN[x]._shipLength     = 3;
                    shipListIN[x]._hitsTaken      = 0;
                    shipListIN[x]._shipActive     = true;
                    break;

                case 4:
                    shipListIN[x] = new Battleships();
                    shipListIN[x]._columnPosition = new int[2];
                    shipListIN[x]._rowPosition    = new int[2];
                    shipListIN[x]._id             = "Patrol Boat";
                    shipListIN[x]._shipLength     = 2;
                    shipListIN[x]._hitsTaken      = 0;
                    shipListIN[x]._shipActive     = true;
                    break;

                default:
                    break;
                }
            }
        }