Ejemplo n.º 1
0
        private void SanDau_Load(object sender, EventArgs e)
        {
            int i, j;

            // Tạo ma trận button cho player1
            Panel1 = new List <List <myButton> >();    // panel1
            for (i = 0; i < 9; i++)
            {
                Panel1.Add(new List <myButton>());   // panel1
                for (j = 0; j < 9; j++)
                {
                    myButton btn = new myButton()
                    {
                        Width    = squareSize,
                        Height   = squareSize,
                        Location = new Point(squareSize * i, squareSize * j),
                        X        = i,
                        Y        = j,
                        //UseVisualStyleBackColor = true,
                        FlatStyle = FlatStyle.Flat,
                        BackColor = Color.Transparent,
                    };

                    btn.Click += Btn_Click_pnl1;

                    pnlPlayer1.Controls.Add(btn);
                    Panel1[i].Add(btn);     // Panel
                }
            }

            // Tạo ma trận button cho player1
            Panel2 = new List <List <myButton> >();    // panel2
            for (i = 0; i < 9; i++)
            {
                Panel2.Add(new List <myButton>());   // panel2
                for (j = 0; j < 9; j++)
                {
                    myButton btn = new myButton()
                    {
                        Width    = squareSize,
                        Height   = squareSize,
                        Location = new Point(squareSize * i, squareSize * j),
                        X        = i,
                        Y        = j,
                        //UseVisualStyleBackColor = true,
                        FlatStyle = FlatStyle.Flat,
                        BackColor = Color.Transparent,
                    };

                    btn.Click += Btn_Click_pnl2;
                    pnlPlayer2.Controls.Add(btn);
                    Panel2[i].Add(btn);     // Pane2
                }
            }
        }
Ejemplo n.º 2
0
        private void Btn_Click_pnl2(object sender, EventArgs e)
        {
            myButton btn = sender as myButton;

            if (playerTurn == turn.player1)
            {
                timer.Stop();
                MessageBox.Show("This is player1's turn");
                timer.Start();
                return;
            }

            //if (btn.UseVisualStyleBackColor == false)
            if (btn.BackColor == Color.Yellow || btn.BackColor == Color.Wheat ||
                btn.BackColor == Color.White)
            {
                timer.Stop();
                MessageBox.Show("This position has been shot");
                timer.Start();
                return;
            }
            // ban trung dau
            if (player2.Matrix[btn.X][btn.Y].isHead)
            {
                btn.BackColor = Color.Yellow;
                player2.NumOfPlane--;
                lbThongBao2.Text = "You shot down " + (3 - player2.NumOfPlane).ToString() + " enemy aircraft";
                if (player2.NumOfPlane > 0)
                {
                }
                else
                {
                    // MessageBox.Show("Ban da ban 3 may bay cua doi phuong\nBan THANG roi");
                    timer.Stop();
                    DialogResult dialogResult = MessageBox.Show("YOU WIN",
                                                                "Do you want to start a new game?", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        // Game reset
                        System.Diagnostics.Process.Start(Application.ExecutablePath);
                        Application.Exit();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        Close();
                    }
                }
            }

            else if (player2.Matrix[btn.X][btn.Y].isPart)
            {
                btn.BackColor = Color.Wheat;
            }

            else
            {
                btn.BackColor = Color.White;
            }

            // đổi lượt
            timer.Stop();
            playerTurn = turn.player1;
            // mũi tên sangs player1
            arrow.Image = BanMayBay.Properties.Resources.leftArrow;

            // reset timer
            count        = countDown;
            lbTimer.Text = count.ToString();
            timer.Start();
        }
Ejemplo n.º 3
0
        private void Btn_Click_pnl1(object sender, EventArgs e)
        {
            myButton btn = sender as myButton;

            if (playerTurn == turn.player2)     // lượt của player2
            {
                timer.Stop();
                MessageBox.Show("This is player2's turn");
                timer.Start();
                return;
            }

            //if (btn.UseVisualStyleBackColor == false)
            if (btn.BackColor == Color.Yellow || btn.BackColor == Color.Wheat ||
                btn.BackColor == Color.White)
            {
                timer.Stop();
                MessageBox.Show("This position has been shot");
                timer.Start();
                return;
            }
            // ban trung dau
            if (player1.Matrix[btn.X][btn.Y].isHead)
            {
                btn.BackColor = Color.Yellow;
                player1.NumOfPlane--;
                lbThongBao1.Text = "You shot down " + (3 - player1.NumOfPlane).ToString() + " enemy aircraft";
                if (player1.NumOfPlane > 0)
                {
                }
                else
                {
                    timer.Stop();

                    DialogResult dialogResult = MessageBox.Show("YOU WIN",
                                                                "Do you want to start a new game?", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        //Choi tiep
                        //FormMenu newGame = new FormMenu();
                        //newGame.Show();
                        //Close();
                        System.Diagnostics.Process.Start(Application.ExecutablePath);
                        Application.Exit();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        Close();
                    }
                }
            }

            else if (player1.Matrix[btn.X][btn.Y].isPart)
            {
                btn.BackColor = Color.Wheat;
            }
            else
            {
                btn.BackColor = Color.White;
            }

            // đổi lượt
            timer.Stop();
            playerTurn = turn.player2;

            // đổi hướng mũi tên sang player2
            arrow.Image = BanMayBay.Properties.Resources.rightArrow;

            // reset timer
            count        = countDown;
            lbTimer.Text = count.ToString();
            timer.Start();
        }