Example #1
0
        private void DeckPictureBoxClick(object sender, EventArgs e)
        {
            if (currentShip != -1 && mouseCellX != -1 && mouseCellY != -1)
            {
                if (Game.CanThereBeShip(currentShip, mouseCellX, mouseCellY, shipRotation, player.ShipSet))
                {
                    shipRotateButton.Enabled  = false;
                    shipDeployed[currentShip] = true;

                    switch (currentShip)
                    {
                    case 0:
                    {
                        deployShip0Button.Enabled = false;
                        deleteShip0Button.Enabled = true;
                        break;
                    }

                    case 1:
                    {
                        deployShip1Button.Enabled = false;
                        deleteShip1Button.Enabled = true;
                        break;
                    }

                    case 2:
                    {
                        deployShip2Button.Enabled = false;
                        deleteShip2Button.Enabled = true;
                        break;
                    }

                    case 3:
                    {
                        deployShip3Button.Enabled = false;
                        deleteShip3Button.Enabled = true;
                        break;
                    }

                    case 4:
                    {
                        deployShip4Button.Enabled = false;
                        deleteShip4Button.Enabled = true;
                        break;
                    }
                    }


                    Game.DeployShip(currentShip, mouseCellX, mouseCellY, shipRotation, player.ShipSet);
                    deckPictureBox.Refresh();
                    currentShip = -1;


                    bool areAllShipsDeployed = true;
                    foreach (bool isDeployed in shipDeployed)
                    {
                        if (!isDeployed)
                        {
                            areAllShipsDeployed = false;
                        }
                    }

                    if (areAllShipsDeployed)
                    {
                        doneButton.Enabled = true;
                    }
                }
            }
        }
        private void DeckPictureBoxClick(object sender, EventArgs e)
        {
            if (currentShip != -1 && mouseCellX != -1 && mouseCellY != -1)
            {
                if (Game.CanThereBeShip(currentShip, mouseCellX, mouseCellY, shipRotation, player.ShipSet))
                {
                    // Allow rotation via the button.
                    shipRotateButton.Enabled = false;
                    // The current ship is being deployed.
                    shipDeployed[currentShip] = true;

                    // Changing buttons' aspects.
                    switch (currentShip)
                    {
                    case 0:
                    {
                        deployShip0Button.Enabled = false;
                        deleteShip0Button.Enabled = true;
                        break;
                    }

                    case 1:
                    {
                        deployShip1Button.Enabled = false;
                        deleteShip1Button.Enabled = true;
                        break;
                    }

                    case 2:
                    {
                        deployShip2Button.Enabled = false;
                        deleteShip2Button.Enabled = true;
                        break;
                    }

                    case 3:
                    {
                        deployShip3Button.Enabled = false;
                        deleteShip3Button.Enabled = true;
                        break;
                    }

                    case 4:
                    {
                        deployShip4Button.Enabled = false;
                        deleteShip4Button.Enabled = true;
                        break;
                    }
                    }

                    // Deploy the current ship into the ship set.
                    Game.DeployShip(currentShip, mouseCellX, mouseCellY, shipRotation, player.ShipSet);

                    // Redraw the deck.
                    deckPictureBox.Refresh();

                    // Unselect the ship.
                    currentShip = -1;

                    // Are all the ships already deployed?
                    bool areAllShipsDeployed = true;
                    foreach (bool isDeployed in shipDeployed)
                    {
                        if (!isDeployed)
                        {
                            // At least one ship is not deployed.
                            areAllShipsDeployed = false;
                        }
                    }

                    // If all the ships are deployed, enable the done button.
                    if (areAllShipsDeployed)
                    {
                        doneButton.Enabled = true;
                    }
                }
            }
        }