Пример #1
0
 // Method for clicking next ship button
 private void btnNextShip_Click(object sender, EventArgs e)
 {
     if (shipNumber == 5)
     // placed all ships, time to load next player placement form or game play form
     {
         if (playerNum == 2)
         {
             // Both players have placed ships, move onto game form
             frmGameBoard gameBoard = new frmGameBoard(playerOne, playerTwo);
             Hide();
             gameBoard.Show();
         }
         else
         {
             // First player has placed ships, load ship placement form for player 2 this time
             frmShipPlacement secondPlayerPlacement = new frmShipPlacement(playerOne, playerTwo, 2);
             Hide();
             secondPlayerPlacement.Show();
         }
     }
     else
     {
         // Current player not placed all ships yet, keep placing
         pnlShipPlacementBoard.Enabled = true;
         currentShip             = currentPlayer.getShips()[shipNumber];
         lblCurrentShipName.Text = currentShip.getShipType() + " it has a lenght of " + currentShip.getShipSize().ToString();
         btnNextShip.Enabled     = false;
     }
 }
Пример #2
0
        // Play game click handler
        // Checks that names are both entered, then loads placement board for P1 if valid
        private void btnPlayGame_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtPlayerOne.Text) || string.IsNullOrWhiteSpace(txtPlayerTwo.Text))
            {
                MessageBox.Show("Enter both player names", "Invalid Name");
            }
            else
            {
                Player playerOne = new Player(txtPlayerOne.Text);
                Player playerTwo = new Player(txtPlayerTwo.Text);

                Hide();
                frmShipPlacement placementBoard = new frmShipPlacement(playerOne, playerTwo, 1);
                placementBoard.Show();
            }
        }