Beispiel #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);
        }
Beispiel #2
0
        private void Btn_1_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            button.BackColor = Color.Green;
            button.Enabled   = false;
            int x = Playing_Field.GetPositionFromControl((Button)sender).Column;
            int y = Playing_Field.GetPositionFromControl((Button)sender).Row;

            SetButton(x, y, mark);
            bool won = Won();

            client.SendMessage(new
            {
                id   = "opponentSet",
                data = new
                {
                    x    = x,
                    y    = y,
                    mark = mark,
                    won  = won.ToString(),
                    full = full
                }
            });
            if (!won)
            {
                AddMessageToConsole("Opponents turn...");
            }
        }
Beispiel #3
0
 /********************************************************************************
  *
  * Method: DrawYAxis
  *
  * Arguments: PictureBox p, bool need_it_for_line, bool need_it_for_quadratic,
  *            bool need_it_for_cubic, bool need_it_for_circle
  *
  * Return Type: void
  *
  * Purpose: Draws X Axis conditionally, depending on the coordinates.
  *
  * *******************************************************************************/
 private void DrawYAxis(PictureBox p, bool need_it_for_line, bool need_it_for_quadratic, bool need_it_for_cubic, bool need_it_for_circle)
 {
     if (need_it_for_line == true)
     {
         p = Playing_Field;
         Graphics lg = Playing_Field.CreateGraphics();
         lg.DrawLine(myWhitePen, (Playing_Field.Width / 2), 0,
                     (Playing_Field.Width / 2), Playing_Field.Height);
     }
     else
     {
         p = Playing_Field;
         Graphics lg = Playing_Field.CreateGraphics();
         lg.DrawLine(myWhitePen, (Playing_Field.Width / 2) - 150, 0,
                     (Playing_Field.Width / 2) - 150, Playing_Field.Height);
     }
     if (need_it_for_quadratic == true)
     {
         p = QuadraticPlayingField;
         Graphics qg = QuadraticPlayingField.CreateGraphics();
         qg.DrawLine(myWhitePen, (QuadraticPlayingField.Width / 2), 0,
                     (QuadraticPlayingField.Width / 2), QuadraticPlayingField.Height);
     }
     else
     {
         p = QuadraticPlayingField;
         Graphics qg = QuadraticPlayingField.CreateGraphics();
         qg.DrawLine(myWhitePen, (QuadraticPlayingField.Width / 2) - 150, 0,
                     (QuadraticPlayingField.Width / 2) - 150, QuadraticPlayingField.Height);
     }
     if (need_it_for_cubic == true)
     {
         p = CubicPlayingField;
         Graphics cubic_g = CubicPlayingField.CreateGraphics();
         cubic_g.DrawLine(myWhitePen, (CubicPlayingField.Width / 2), 0,
                          (CubicPlayingField.Width / 2), CubicPlayingField.Height);
     }
     else
     {
         p = CubicPlayingField;
         Graphics cubic_g = CubicPlayingField.CreateGraphics();
         cubic_g.DrawLine(myWhitePen, (CubicPlayingField.Width / 2) - 150, 0,
                          (CubicPlayingField.Width / 2) - 150, CubicPlayingField.Height);
     }
     if (need_it_for_circle == true)
     {
         p = CirclePlayingField;
         Graphics cg = CirclePlayingField.CreateGraphics();
         cg.DrawLine(myWhitePen, (CirclePlayingField.Width / 2), 0,
                     (CirclePlayingField.Width / 2), CirclePlayingField.Height);
     }
     else
     {
         p = CirclePlayingField;
         Graphics cg = CirclePlayingField.CreateGraphics();
         cg.DrawLine(myWhitePen, (CirclePlayingField.Width / 2) - 150, 0,
                     (CirclePlayingField.Width / 2) - 150, CirclePlayingField.Height);
     }
 }
Beispiel #4
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;
            }
        }
Beispiel #5
0
        private void Btn_2_Click(object sender, EventArgs e)
        {
            int x = Playing_Field.GetPositionFromControl((Button)sender).Column;
            int y = Playing_Field.GetPositionFromControl((Button)sender).Row;


            SetButton(x, y, mark);
            client.SendMessage(new
            {
                id   = "opponentSet",
                data = new
                {
                    x    = x,
                    y    = y,
                    mark = mark,
                    won  = Won().ToString()
                }
            });
            AddMessageToConsole("Opponents turn...");
        }
Beispiel #6
0
        /********************************************************************************
         *
         * Method: DrawLine
         *
         * Arguments: float m, float b, bool need_X_axis, bool need_Y_axis
         *
         * Return Type: void
         *
         * Purpose: Draws a line with specific coordinates through the plane.
         *
         * *******************************************************************************/
        void DrawLine(float m, float b, bool need_X_axis, bool need_Y_axis)
        {
            Graphics g        = Playing_Field.CreateGraphics();
            Pen      line_pen = new Pen(Color.Green);

            float start_X = 0;
            float start_Y = 150 + (150 * m);
            float end_X   = 300;
            float end_Y   = 150 - (150 * m);

            start_Y -= b;
            end_Y   -= b;

            if (need_X_axis && !need_Y_axis)
            {
                start_X -= 150;
                end_X   -= 150;
            }

            g.DrawLine(line_pen, start_X, start_Y, end_X, end_Y);
            Console.WriteLine("startX: " + start_X + " startY: " + start_Y + " end_X: " + end_X + " end_Y: " + end_Y);
        }
Beispiel #7
0
        /********************************************************************************
         *
         * Method: CalculateEquationsBtn_Click
         *
         * Arguments: object sender, EventArgs e
         *
         * Return Type: void
         *
         * Purpose: Handles button click events and display a graph or an error.
         *
         * *******************************************************************************/
        private void CalculateEquationsBtn_Click(object sender, EventArgs e)
        {
            Graphics   lg           = Playing_Field.CreateGraphics();
            Graphics   qg           = QuadraticPlayingField.CreateGraphics();
            Graphics   cubic_g      = CubicPlayingField.CreateGraphics();
            Graphics   cg           = CirclePlayingField.CreateGraphics();
            SolidBrush paintItBlack = new SolidBrush(Color.Black);

            if ((LineMTextBox.Text != "" &&
                 (Regex.IsMatch(LineMTextBox.Text, @"^\d+$") || Regex.IsMatch(LineMTextBox.Text, @"^[-+]?\d+\.?\d*$"))) &&
                (LineBTextBox.Text != "" &&
                 (Regex.IsMatch(LineBTextBox.Text, @"^\d+$") || Regex.IsMatch(LineBTextBox.Text, @"^[-+]?\d+\.?\d*$"))))
            {
                lg.FillRectangle(paintItBlack, 0, 0, Playing_Field.Width, Playing_Field.Height);
                float m_for_Line = (float)Convert.ToDouble(LineMTextBox.Text);
                float b_for_Line = (float)Convert.ToDouble(LineBTextBox.Text);

                bool need_Y_for_line = b_for_Line != 0;
                bool need_X_for_line = b_for_Line < 0 || m_for_Line < 0;

                DrawXAxis(Playing_Field, need_X_for_line, false, false, false);
                DrawYAxis(Playing_Field, need_Y_for_line, false, false, false);
                DrawTicks(Playing_Field, need_X_for_line, need_Y_for_line);
                DrawLine(m_for_Line, b_for_Line, need_X_for_line, need_Y_for_line);
            }
            if ((QuadraticATextBox.Text != "" && (Regex.IsMatch(QuadraticATextBox.Text, @"^\d+$") || Regex.IsMatch(QuadraticATextBox.Text, @"^[-+]?\d+\.?\d*$"))) &&
                (QuadraticBTextBox.Text != "" && (Regex.IsMatch(QuadraticBTextBox.Text, @"^\d+$") || Regex.IsMatch(QuadraticBTextBox.Text, @"^[-+]?\d+\.?\d*$"))) &&
                (QuadraticCTextBox.Text != "" && (Regex.IsMatch(QuadraticCTextBox.Text, @"^\d+$") || Regex.IsMatch(QuadraticCTextBox.Text, @"^[-+]?\d+\.?\d*$"))))
            {
                qg.FillRectangle(paintItBlack, 0, 0, QuadraticPlayingField.Width, QuadraticPlayingField.Height);

                float a = (float)Convert.ToDouble(QuadraticATextBox.Text.ToString());
                float b = (float)Convert.ToDouble(QuadraticBTextBox.Text.ToString());
                float c = (float)Convert.ToDouble(QuadraticCTextBox.Text.ToString());

                bool need_Y_for_quad = true;
                bool need_X_for_quad = a < 0 || b < 0 || c < 0;

                // y = ax2 + bx + c
                // Create pens.
                Pen redPen = new Pen(Color.Red);
                DrawXAxis(QuadraticPlayingField, false, need_X_for_quad, false, false);
                DrawYAxis(QuadraticPlayingField, false, need_Y_for_quad, false, false);
                DrawTicks(QuadraticPlayingField, need_X_for_quad, need_Y_for_quad);
                // Draw curve to screen.
                DrawQuadratic(a, b, c);
            }
            if ((CubicATextBox.Text != "" && (Regex.IsMatch(CubicATextBox.Text, @"^\d+$") || Regex.IsMatch(CubicATextBox.Text, @"^[-+]?\d+\.?\d*$"))) &&
                (CubicBTextBox.Text != "" && (Regex.IsMatch(CubicBTextBox.Text, @"^\d+$") || Regex.IsMatch(CubicBTextBox.Text, @"^[-+]?\d+\.?\d*$"))) &&
                (CubicCTextBox.Text != "" && (Regex.IsMatch(CubicCTextBox.Text, @"^\d+$") || Regex.IsMatch(CubicCTextBox.Text, @"^[-+]?\d+\.?\d*$"))) &&
                (CubicDTextBox.Text != "" && (Regex.IsMatch(CubicDTextBox.Text, @"^\d+$") || Regex.IsMatch(CubicDTextBox.Text, @"^[-+]?\d+\.?\d*$"))))
            {
                cubic_g.FillRectangle(paintItBlack, 0, 0, CubicPlayingField.Width, CubicPlayingField.Height);

                float cubicA = (float)Convert.ToDouble(CubicATextBox.Text);
                float cubicB = (float)Convert.ToDouble(CubicBTextBox.Text);
                float cubicC = (float)Convert.ToDouble(CubicCTextBox.Text);
                float cubicD = (float)Convert.ToDouble(CubicDTextBox.Text);

                bool need_Y_for_Cubic = true;
                bool need_X_for_Cubic = true;

                DrawXAxis(CubicPlayingField, false, false, need_X_for_Cubic, false);
                DrawYAxis(CubicPlayingField, false, false, need_Y_for_Cubic, false);
                DrawTicks(CubicPlayingField, need_X_for_Cubic, need_Y_for_Cubic);
                // Draw curve to screen.
                DrawCubic(cubicA, cubicB, cubicC, cubicD);
            }
            if ((HCircleTextBox.Text != "" && (Regex.IsMatch(HCircleTextBox.Text, @"^\d+$") || Regex.IsMatch(HCircleTextBox.Text, @"^[-+]?\d+\.?\d*$"))) &&
                (KCircleTextBox.Text != "" && (Regex.IsMatch(KCircleTextBox.Text, @"^\d+$") || Regex.IsMatch(KCircleTextBox.Text, @"^[-+]?\d+\.?\d*$"))) &&
                RCircleTextBox.Text != "" && (Regex.IsMatch(RCircleTextBox.Text, @"^\d+$") || Regex.IsMatch(RCircleTextBox.Text, @"^[-+]?\d+\.?\d*$")))
            {
                cg.FillRectangle(paintItBlack, 0, 0, CirclePlayingField.Width, CirclePlayingField.Height);

                float h = (float)Convert.ToDouble(HCircleTextBox.Text);
                float k = (float)Convert.ToDouble(KCircleTextBox.Text);
                float r = (float)Convert.ToDouble(RCircleTextBox.Text);

                bool need_Y_for_circle = k < 0;
                bool need_X_for_circle = h < 0;

                DrawXAxis(CirclePlayingField, false, false, false, need_X_for_circle);
                DrawYAxis(CirclePlayingField, false, false, false, need_Y_for_circle);
                DrawTicks(CirclePlayingField, need_X_for_circle, need_Y_for_circle);
                DrawCircle(h, k, r, need_X_for_circle, need_Y_for_circle);
            }
            //else
            //{
            //    DisplayError("other");
            //}
        }
Beispiel #8
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);
        }