예제 #1
0
        //event for each button clicked
        private void button_click(object sender, EventArgs e)
        {
            Button b = (Button)sender;

            if (turn == true)
            {
                sound.Play();
                b.Text      = "X";
                b.ForeColor = Color.Red;
                proxy.MakeMove(LoginForm.username, b.TabIndex, b.Text);
            }
            else
            {
                sound.Play();
                b.Text      = "O";
                b.ForeColor = Color.Blue;
                proxy.MakeMove(LoginForm.username, b.TabIndex, b.Text);
            }

            int checkwinner = this.CheckWinner(button1.Text, button2.Text, button3.Text, button4.Text, button5.Text, button6.Text, button7.Text, button8.Text, button9.Text);

            if (checkwinner == 1)
            {
                wins++;
                win.Play();
                button1.BackColor = Color.Green;
                button2.BackColor = Color.Green;
                button3.BackColor = Color.Green;

                MessageBox.Show("You have a winner");
                //label3.Text = LoginForm.username+" has "+ wins + " wins";
                //label4.Text = proxy.GetName(LoginForm.username) + " has " + wins + " wins";
                //label3.Text = "You have " + wins + " wins";
                //label3.Text = proxy.CountWins(proxy.GetName(LoginForm.username), wins);
                //this.WinsCallBack(LoginForm.username, wins);
                //label4.Text = proxy.GetName(LoginForm.username) + " has " + wins + " wins";

                this.ResetBoard();
            }
            else if (checkwinner == 2)
            {
                win.Play();
                button4.BackColor = Color.Green;
                button5.BackColor = Color.Green;
                button6.BackColor = Color.Green;

                MessageBox.Show("You have a winner");
                this.ResetBoard();
            }
            else if (checkwinner == 3)
            {
                win.Play();
                button7.BackColor = Color.Green;
                button8.BackColor = Color.Green;
                button9.BackColor = Color.Green;

                MessageBox.Show("You have a winner");
                this.ResetBoard();
            }
            else if (checkwinner == 4)
            {
                win.Play();
                button1.BackColor = Color.Green;
                button4.BackColor = Color.Green;
                button7.BackColor = Color.Green;

                MessageBox.Show("You have a winner");
                this.ResetBoard();
            }
            else if (checkwinner == 5)
            {
                win.Play();
                button2.BackColor = Color.Green;
                button5.BackColor = Color.Green;
                button8.BackColor = Color.Green;

                MessageBox.Show("You have a winner");
                this.ResetBoard();
            }
            else if (checkwinner == 6)
            {
                win.Play();
                button3.BackColor = Color.Green;
                button6.BackColor = Color.Green;
                button9.BackColor = Color.Green;

                MessageBox.Show("You have a winner");
                this.ResetBoard();
            }
            else if (checkwinner == 7)
            {
                win.Play();
                button1.BackColor = Color.Green;
                button5.BackColor = Color.Green;
                button9.BackColor = Color.Green;

                MessageBox.Show("You have a winner");
                this.ResetBoard();
            }
            else if (checkwinner == 8)
            {
                win.Play();
                button3.BackColor = Color.Green;
                button5.BackColor = Color.Green;
                button7.BackColor = Color.Green;

                MessageBox.Show("You have a winner");
                this.ResetBoard();
            }
            else if (checkwinner == 9)
            {
                foreach (Button bttn in buttonArray)
                {
                    bttn.BackColor = Color.LightBlue;
                }

                MessageBox.Show("Draw!");
                this.ResetBoard();
            }
            turn      = !turn;
            b.Enabled = false;
            foreach (Button btn in buttonArray)
            {
                btn.Enabled = false;
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: SYKC/Tic-Tac-Toe
        //event for each button clicked
        private void button_click(object sender, EventArgs e)
        {
            Button b = (Button)sender;

            if (turn == true)
            {
                move.Play();
                b.Text      = "X";
                b.ForeColor = Color.Red;
                proxy.MakeMove(LoginForm.username, b.TabIndex, b.Text);
            }
            else
            {
                move.Play();
                b.Text      = "O";
                b.ForeColor = Color.Blue;
                proxy.MakeMove(LoginForm.username, b.TabIndex, b.Text);
            }

            int checkwinner = this.CheckWinner(button1.Text, button2.Text, button3.Text, button4.Text, button5.Text, button6.Text, button7.Text, button8.Text, button9.Text);

            if (checkwinner == 1)
            {
                wins++;
                win.Play();
                button1.BackColor = Color.Green;
                button2.BackColor = Color.Green;
                button3.BackColor = Color.Green;


                //label3.Text = LoginForm.username+" has "+ wins + " wins";
                //label4.Text = proxy.GetName(LoginForm.username) + " has " + wins + " wins";
                //label3.Text = "You have " + wins + " wins";
                int score = Convert.ToInt32(label3.Text);
                score++;
                label3.Text = score.ToString();
                MessageBox.Show("You win! Your score is now " + score);


                this.ResetBoard();
            }
            else if (checkwinner == 2)
            {
                win.Play();
                button4.BackColor = Color.Green;
                button5.BackColor = Color.Green;
                button6.BackColor = Color.Green;


                int score = Convert.ToInt32(label3.Text);
                score++;
                label3.Text = score.ToString();
                MessageBox.Show("You win! Your score is now " + score);
                this.ResetBoard();
            }
            else if (checkwinner == 3)
            {
                win.Play();
                button7.BackColor = Color.Green;
                button8.BackColor = Color.Green;
                button9.BackColor = Color.Green;


                int score = Convert.ToInt32(label3.Text);
                score++;
                label3.Text = score.ToString();
                MessageBox.Show("You win! Your score is now " + score);
                this.ResetBoard();
            }
            else if (checkwinner == 4)
            {
                win.Play();
                button1.BackColor = Color.Green;
                button4.BackColor = Color.Green;
                button7.BackColor = Color.Green;


                int score = Convert.ToInt32(label3.Text);
                score++;
                label3.Text = score.ToString();
                MessageBox.Show("You win! Your score is now " + score);
                this.ResetBoard();
            }
            else if (checkwinner == 5)
            {
                win.Play();
                button2.BackColor = Color.Green;
                button5.BackColor = Color.Green;
                button8.BackColor = Color.Green;


                int score = Convert.ToInt32(label3.Text);
                score++;
                label3.Text = score.ToString();
                MessageBox.Show("You win! Your score is now " + score);
                this.ResetBoard();
            }
            else if (checkwinner == 6)
            {
                win.Play();
                button3.BackColor = Color.Green;
                button6.BackColor = Color.Green;
                button9.BackColor = Color.Green;


                int score = Convert.ToInt32(label3.Text);
                score++;
                label3.Text = score.ToString();
                MessageBox.Show("You win! Your score is now " + score);
                this.ResetBoard();
            }
            else if (checkwinner == 7)
            {
                win.Play();
                button1.BackColor = Color.Green;
                button5.BackColor = Color.Green;
                button9.BackColor = Color.Green;


                int score = Convert.ToInt32(label3.Text);
                score++;
                label3.Text = score.ToString();
                MessageBox.Show("You win! Your score is now " + score);
                this.ResetBoard();
            }
            else if (checkwinner == 8)
            {
                win.Play();
                button3.BackColor = Color.Green;
                button5.BackColor = Color.Green;
                button7.BackColor = Color.Green;


                int score = Convert.ToInt32(label3.Text);
                score++;
                label3.Text = score.ToString();
                MessageBox.Show("You win! Your score is now " + score);
                this.ResetBoard();
            }
            else if (checkwinner == 9)
            {
                foreach (Button bttn in buttonArray)
                {
                    bttn.BackColor = Color.LightBlue;
                }

                MessageBox.Show("Draw!");
                int score = Convert.ToInt32(label8.Text);
                score++;
                label8.Text = score.ToString();

                this.ResetBoard();
            }
            turn      = !turn;
            b.Enabled = false;
            foreach (Button btn in buttonArray)
            {
                btn.Enabled = false;
            }
        }