예제 #1
0
        private void s_ShipSunk(object sender, EventArgs e)
        {
            //what to do when a ship is sunk
            bool   allShipsSunk;
            var    ship       = sender as Ship;
            string messageLb  = "The following hit has sunk " + ship.Player + "'s " + ship.ShipType + ".";
            string messageBox = ship.Player + "'s " + ship.ShipType + " has been sunk.";

            MessageBox.Show(messageBox);
            lbMoves.Items.Add(messageLb);

            //if a ship is sunk checks to see if all ships are sunk
            //if all ships are sunk determines winner
            if (ship.Player == Player1Name)
            {
                allShipsSunk = GameMechanics.CheckAllShipsSunk(playerShips);
                if (allShipsSunk == true)
                {
                    MessageBox.Show("Game Over. The computer has won.");
                    tableLayoutPanel1.Enabled = false;
                    isWinner = true;
                }
            }
            else if (ship.Player == Player2Name)
            {
                allShipsSunk = GameMechanics.CheckAllShipsSunk(computerShips);
                if (allShipsSunk == true)
                {
                    MessageBox.Show("Congratulations, you won!");
                    tableLayoutPanel1.Enabled = false;
                    isWinner = true;
                }
            }
        }