Пример #1
0
        //============================================================================================================================
        private void startGame()
        {
            // Set up variables
            int w       = 600 / newBtn.GetLength(0);
            int h       = 600 / newBtn.GetLength(1);
            int yOffSet = 28;
            int xOffSet = 2;

            control_group.Location = new Point(610, 27);
            control_group.Visible  = true;

            // Create grid of buttons
            for (int x = 0; x < newBtn.GetLength(0); x++)
            {
                for (int y = 0; y < newBtn.GetLength(1); y++)
                {
                    // Create each button and initilise for the start of the game
                    btnCoords coords = new btnCoords(x, y);
                    newBtn[x, y] = new Button();
                    newBtn[x, y].SetBounds((x * w) + xOffSet, (y * h) + yOffSet, w, h);
                    newBtn[x, y].BackColor = Color.Honeydew;
                    newBtn[x, y].FlatStyle = FlatStyle.Flat;
                    newBtn[x, y].Tag       = coords;
                    newBtn[x, y].Click    += new EventHandler(buttonClicked);
                    Controls.Add(newBtn[x, y]);
                }
            }

            // Ensure the players points are reset to 0
            p1.setPoints(0);
            p2.setPoints(0);

            black_squares = 0;

            // Update the GUI with the names of the players
            lbl_p1_name.Text = p1.getName();
            lbl_p2_name.Text = p2.getName();

            updateStats();
        }
Пример #2
0
        //============================================================================================================================
        // Event Handlers
        //============================================================================================================================
        private void buttonClicked(object sender, EventArgs e)
        {
            Button    clicked = sender as Button;
            btnCoords coords  = (btnCoords)clicked.Tag;

            bool success = true;

            string weapon_choice = lbl_weapon_choice.Text;

            int x = coords.getX();
            int y = coords.getY();

            if (weapon_choice == "Infected Paint")
            {
                if (weaponCanUse("infected") == true)
                {
                    clicked.Enabled   = false;
                    clicked.BackColor = Color.Black;

                    infectedPaint(x, y);
                    weaponUsed("infected");

                    player_turn   *= -1;
                    black_squares += 25;
                    updateStats();
                    checkWinState();
                    return;
                }
                else
                {
                    MessageBox.Show("Not enough infected paint to use this", "Out of infected paint", MessageBoxButtons.OK);
                }
            }

            if (clicked.BackColor == Color.Honeydew)
            {
                clicked.Enabled   = false;
                clicked.BackColor = Color.Black;

                switch (weapon_choice)
                {
                case "Paint Blob":
                    paintBlob(x, y);
                    break;

                case "Paint Bomb":
                    if (weaponCanUse("bomb") == true)
                    {
                        paintBomb(x, y);
                        weaponUsed("bomb");
                    }
                    else
                    {
                        MessageBox.Show("Not enough bombs to use this", "Out of bombs", MessageBoxButtons.OK);
                        success = false;
                    }
                    break;

                case "Dripping Paint":
                    if (weaponCanUse("dripping") == true)
                    {
                        weaponUsed("dripping");
                    }
                    else
                    {
                        MessageBox.Show("Not enough dripping paint to use this", "Out of dripping paint", MessageBoxButtons.OK);
                        success = false;
                    }
                    break;

                default:
                    Console.WriteLine("Error --> Weapon Switch Statement");
                    break;
                }

                if (success == true)
                {
                    player_turn *= -1;
                    black_squares++;
                    updateStats();
                    checkWinState();
                }
                else
                {
                    clicked.Enabled   = true;
                    clicked.BackColor = Color.Honeydew;
                }
            }
            else
            {
                Console.WriteLine("Error --> Painted Square Clicked");
            }
        }