Example #1
0
        private bool Won()
        {
            int check = 0;

            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    Button button = (Button)Playing_Field.GetControlFromPosition(x, y);
                    if (button.Text.Equals(mark))
                    {
                        check++;
                        if (check == 3)
                        {
                            client.SetWon();
                            return(true);
                        }
                    }
                    else
                    {
                        check = 0;
                    }
                }
                check = 0;
            }

            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    Button button = (Button)Playing_Field.GetControlFromPosition(x, y);
                    if (button.Text.Equals(mark))
                    {
                        check++;
                        if (check == 3)
                        {
                            client.SetWon();
                            return(true);
                        }
                    }
                    else
                    {
                        check = 0;
                    }
                }
                check = 0;
            }

            if (((Button)Playing_Field.GetControlFromPosition(0, 0)).Text.Equals(mark) && ((Button)Playing_Field.GetControlFromPosition(1, 1)).Text.Equals(mark) && ((Button)Playing_Field.GetControlFromPosition(2, 2)).Text.Equals(mark))
            {
                client.SetWon();
                return(true);
            }
            if (((Button)Playing_Field.GetControlFromPosition(0, 2)).Text.Equals(mark) && ((Button)Playing_Field.GetControlFromPosition(1, 1)).Text.Equals(mark) && ((Button)Playing_Field.GetControlFromPosition(2, 0)).Text.Equals(mark))
            {
                client.SetWon();
                return(true);
            }
            return(false);
        }
Example #2
0
        internal void SetButton(int x, int y, string mark)
        {
            if (InvokeRequired)
            {
                this.BeginInvoke(new Action <int, int, string>(SetButton), new object[] { x, y, mark });
                return;
            }
            Button button = (Button)Playing_Field.GetControlFromPosition(x, y);

            if (button.Text.Equals(""))
            {
                button.Text = mark;
            }
        }
Example #3
0
        private bool Won()
        {
            int check = 0;

            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    Button button = (Button)Playing_Field.GetControlFromPosition(x, y);
                    if (button.Text.Equals(mark))
                    {
                        check++;
                        if (check == 3)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        check = 0;
                    }
                }
                check = 0;
            }

            for (int y = 0; y < 3; y++)
            {
                for (int x = 0; x < 3; x++)
                {
                    Button button = (Button)Playing_Field.GetControlFromPosition(x, y);
                    if (button.Text.Equals(mark))
                    {
                        check++;
                        if (check == 3)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        check = 0;
                    }
                }
                check = 0;
            }

            if (((Button)Playing_Field.GetControlFromPosition(0, 0)).Text.Equals(mark) && ((Button)Playing_Field.GetControlFromPosition(1, 1)).Text.Equals(mark) && ((Button)Playing_Field.GetControlFromPosition(2, 2)).Text.Equals(mark))
            {
                return(true);
            }
            if (((Button)Playing_Field.GetControlFromPosition(0, 2)).Text.Equals(mark) && ((Button)Playing_Field.GetControlFromPosition(1, 1)).Text.Equals(mark) && ((Button)Playing_Field.GetControlFromPosition(2, 0)).Text.Equals(mark))
            {
                return(true);
            }

            int TotalControls = 0;

            foreach (Button button in Playing_Field.Controls)
            {
                if (button.Text != "")
                {
                    TotalControls++;
                }
            }

            if (TotalControls == 9)
            {
                full = true;
                foreach (Button button in Playing_Field.Controls)
                {
                    button.Text      = "";
                    button.BackColor = Color.White;
                }
                return(true);
            }

            return(false);
        }