Example #1
0
        private void playerFieldArea_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Middle || selectedShip_dockNumber == 0 ||
                !(playerField.PlacementAllowed))
            {
                return;
            }
            else if (e.Button == MouseButtons.Right)
            {
                placeVertically = !placeVertically;
                Cell targetCell = GetTargetCell(playerFieldArea, e.X, e.Y);
                if (targetCell == null)
                {
                    return;
                }
                playerField.HighlightPlacement(selectedShip_dockNumber, targetCell, placeVertically);
                DrawPlayerField();
                return;
            }
            DeselectShipButton();
            switch (selectedShip_dockNumber)
            {
            case 1:
                unplacedTorpedoBoats--;
                if (unplacedTorpedoBoats == 0)
                {
                    btnTorpedoBoat.Enabled = false;
                }
                break;

            case 2:
                unplacedDestroyers--;
                if (unplacedDestroyers == 0)
                {
                    btnDestroyer.Enabled = false;
                }
                break;

            case 3:
                unplacedCruisers--;
                if (unplacedCruisers == 0)
                {
                    btnCruiser.Enabled = false;
                }
                break;

            case 4:
                unplacedBattleships--;
                if (unplacedBattleships == 0)
                {
                    btnBattleship.Enabled = false;
                }
                break;
            }
            selectedShip_dockNumber = 0;
            playerField.PlaceShip();
            playerField.RemoveHighlight();
            DrawPlayerField();
            if ((unplacedBattleships == 0) && (unplacedCruisers == 0) &&
                (unplacedDestroyers == 0) && (unplacedTorpedoBoats == 0))
            {
                playerFieldArea.Enabled = false;
                btnStart.Enabled        = true;
            }
        }