示例#1
0
 protected override void OnMouseUp(MouseEventArgs e)        //33
 {
     PegPicking = false;
     if (myBoard.Status == GameStatus.Active)
     {
         for (int j = 0; j < 4; j++)
         {
             if (DrawingUtility.isPointinRectangle(new Point(e.X, e.Y), Boxes[myBoard.ActiveRowNo, j]) == true)
             {
                 myBoard.Rowss[myBoard.ActiveRowNo][j] = (byte)(myBoard.SelectedPeg + 1);
                 break;
             }
         }
     }
     if (DrawingUtility.isPointinRectangle(new Point(e.X, e.Y), Ok) == true)
     {
         myBoard.test(mychois);
     }
     if (myBoard.Status == GameStatus.Active)
     {
         if (myBoard.ActiveRowIsComplite)
         {
             statusBar.Text = "Нажмите ОК чтоб подтвердить результат";
         }
         else
         {
             statusBar.Text = "Заполнить строку";
         }
     }
     else if (myBoard.Status == GameStatus.Won)
     {
         statusBar.Text = "Поздравляем!Вы угадали комбинацию!";
     }
     else if (myBoard.Status == GameStatus.Lost)
     {
         statusBar.Text = "Ничего страшного, попробуй еще раз!";
     }
     Invalidate();
 }
示例#2
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // This Code will give a start for Draging Peg from Tray
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


            // -------------------------------------------------------
            // loop through all Pegs to find Where Mouse was down
            // -------------------------------------------------------
            for (int i = 0; i < ColorPellete.Length; i++)
            {
                if (DrawingUtility.isPointinRectangle(new Point(e.X, e.Y), ColorPellete[i]) == true)
                {
                    // Make that peg selected peg
                    myBoard.SelectedPeg = (byte)i;
                    // make flag PegPicking true
                    this.PegPicking = true;
                    break;
                }
            }
        }
示例#3
0
        private Image CreateResultPeg(Color c)         //изображение получившейся комбинации
        {
            Image img;
            int   RbWidth = this.ResultBoxes[0, 0].Width;

            img = new Bitmap(RbWidth - 2, RbWidth - 2);
            Graphics g = Graphics.FromImage(img);

            g.Clear(this.BackColor);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            if (c.B == 0)
            {
                DrawingUtility.DrawPeg(ref g, new Rectangle(1, 1, RbWidth - 4, RbWidth - 4), Color.Black);       //если угадали позицию и цвет
            }
            else
            {
                DrawingUtility.DrawPeg(ref g, new Rectangle(1, 1, RbWidth - 4, RbWidth - 4), Color.FromArgb(102, 102, 102));     //если угадали лишь цвет
            }
            g.Dispose();

            return(img);
        }
示例#4
0
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Creates Result Peg White and Black
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        private Image CreateResultPeg(Color c)
        {
            Image img;
            int   RbWidth = this.ResultBoxes[0, 0].Width;

            img = new Bitmap(RbWidth - 2, RbWidth - 2);
            Graphics g = Graphics.FromImage(img);

            g.Clear(this.BackColor);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            if (c.B == 0)
            {
                DrawingUtility.DrawPeg(ref g, new Rectangle(1, 1, RbWidth - 4, RbWidth - 4), Color.Black);
            }
            else
            {
                DrawingUtility.DrawPeg(ref g, new Rectangle(1, 1, RbWidth - 4, RbWidth - 4), Color.FromArgb(102, 102, 102));
            }
            g.Dispose();

            return(img);
        }
示例#5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            // ------------------------------------------------
            // Get Graphics Object from EventArgs
            // ------------------------------------------------
            Graphics g = e.Graphics;

            // ------------------------------------------------
            // if User is Draging peg no need to reDraw Image
            // ------------------------------------------------
            if (PegPicking == false)
            {
                CreateOffScreenImage();
            }

            // ------------------------------------------------
            // Draw OffScreen Image to Screen
            // ------------------------------------------------
            g.DrawImage(this.OffScreenBitmap, 0, 0, new Rectangle(0, 0, this.Width, this.Height), GraphicsUnit.Pixel);

            // ------------------------------------------------
            // If Player is Currently Draging Peg Draw Peg at
            // tip of Mouse to Show Effect of Draging
            // ------------------------------------------------
            if (this.PegPicking == true)
            {
                // I am using Direct drawing instead of using Imageof peg
                // because I can not find suitable method to make background
                // of Image transperent

                // set AntiAlias on
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                DrawingUtility.DrawPeg(ref g, new Rectangle(this.mPosition.X - 7, this.mPosition.Y - 7, this.boxWidth - 6, this.boxWidth - 6), this.PelleteColors[myBoard.SelectedPeg]);
                // Set AntiAlias off
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
            }
        }
示例#6
0
        private void CreateOffScreenImage()        //формирвоание игрового поля
        {
            gOffScreen.Clear(this.BackColor);
            gOffScreen.DrawRectangle(DarkPen, Rb);
            gOffScreen.DrawLine(DarkPen, StartPoint.X + 4 * boxWidth + border, StartPoint.Y, StartPoint.X + 4 * boxWidth + border, StartPoint.Y + mychois * boxWidth);

            if (mychois > 10)
            {
                for (int k = 10; k < mychois; k++)
                {
                    myBoard.Resultss.Add(new List <byte>()
                    {
                        0, 0, 0, 0
                    });
                    myBoard.Rowss.Add(new List <byte>()
                    {
                        0, 0, 0, 0
                    });
                }
            }

            for (int i = 0; i < mychois; i++)//!!!
            {
                gOffScreen.DrawLine(DarkPen, Boxes[1, 0].X, Boxes[i, 0].Y, Boxes[1, 0].X + Boxes[1, 0].Width * 5, Boxes[i, 0].Y);

                for (int j = 0; j < 4; j++)
                {
                    if (myBoard.ActiveRowNo != i && myBoard.Resultss[i][j] == 0)
                    {
                        gOffScreen.DrawImage(ResultPegHole, ResultBoxes[i, j].X, ResultBoxes[i, j].Y);
                    }
                    else if (myBoard.ActiveRowIsComplite == false || myBoard.Status != GameStatus.Active)
                    {
                        gOffScreen.DrawImage(ResultPegHole, ResultBoxes[i, j].X, ResultBoxes[i, j].Y);
                    }
                    if (myBoard.Rowss[i][j] != 0)
                    {
                        gOffScreen.DrawImage(this.PegImages[myBoard.Rowss[i][j] - 1], Boxes[i, j].X + 3, Boxes[i, j].Y + 3);
                    }
                    else
                    {
                        gOffScreen.DrawImage(this.PegHole, Boxes[i, j].X + 3, Boxes[i, j].Y + 3);
                    }
                }
            }
            gOffScreen.DrawRectangle(DarkPen, ColorPelleteTray);
            for (int i = 0; i < ColorPellete.Length; i++)
            {
                gOffScreen.DrawImage(this.PegImages[i], ColorPellete[i].X + 3, ColorPellete[i].Y + 3);
            }
            Rectangle rm = new Rectangle(MasterBoxes[0].X + 2, MasterBoxes[0].Y + 2, MasterBoxes[0].Width * 4 - 4, MasterBoxes[0].Height - 4);

            if (myBoard.Status == GameStatus.Active)
            {
                gOffScreen.DrawString("Мастер майнд", this.MyFont, this.DarkBrush, MasterBoxes[0].X + 5, MasterBoxes[0].Y + 3);
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    gOffScreen.DrawImage(this.PegImages[myBoard.master.Rows[i] - 1], MasterBoxes[i].X + 3, MasterBoxes[i].Y + 3);
                }
            }
            for (int i = 0; i <= myBoard.ActiveRowNo; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    Rectangle ResultCircle = new Rectangle(ResultBoxes[i, j].X + 2, ResultBoxes[i, j].Y + 2, ResultBoxes[i, j].Width - 4, ResultBoxes[i, j].Height - 4);
                    if (myBoard.Resultss[i][j] != 0)
                    {
                        if (myBoard.Resultss[i][j] == 1)
                        {
                            gOffScreen.DrawImage(this.ResultBlackPeg, ResultBoxes[i, j].X + 1, ResultBoxes[i, j].Y + 1);
                        }
                        else
                        {
                            gOffScreen.DrawImage(this.ResultWhitePeg, ResultBoxes[i, j].X + 1, ResultBoxes[i, j].Y + 1);
                        }
                    }
                }
            }
            if (myBoard.Status == GameStatus.Active)
            {
                if (myBoard.ActiveRowIsComplite)
                {
                    Ok.Y = StartPoint.Y + myBoard.ActiveRowNo * boxWidth;
                    DrawingUtility.DrawRaisedString(ref gOffScreen, "Ok", Ok, this.BackColor, MyFont);
                }
            }
        }
示例#7
0
        private void CreateOffScreenImage()
        {
            gOffScreen.Clear(this.BackColor);
            // Outer rectangle of game Board
            gOffScreen.DrawRectangle(DarkPen, Rb);
            // Vertical line dividing Rows and Result Space
            gOffScreen.DrawLine(DarkPen, StartPoint.X + 4 * boxWidth + border, StartPoint.Y, StartPoint.X + 4 * boxWidth + border, StartPoint.Y + 10 * boxWidth);

            for (int i = 0; i < 10; i++)
            {
                // Draw Horizontal lines through rows
                gOffScreen.DrawLine(DarkPen, Boxes[1, 0].X, Boxes[i, 0].Y, Boxes[1, 0].X + Boxes[1, 0].Width * 5, Boxes[i, 0].Y);

                for (int j = 0; j < 4; j++)
                {
                    //  -------------------------------------
                    // Draw Result Peg Holes
                    //  -------------------------------------
                    if (myBoard.ActiveRowNo != i && myBoard.Results[i][j] == 0)
                    {
                        gOffScreen.DrawImage(ResultPegHole, ResultBoxes[i, j].X, ResultBoxes[i, j].Y);
                    }
                    else if (myBoard.ActiveRowIsComplite == false || myBoard.Status != GameStatus.Active)
                    {
                        gOffScreen.DrawImage(ResultPegHole, ResultBoxes[i, j].X, ResultBoxes[i, j].Y);
                    }

                    //  -------------------------------------
                    // Draw Pegs if Filled or show Peg Hole
                    //  -------------------------------------
                    if (myBoard.Rows[i][j] != 0)
                    {
                        gOffScreen.DrawImage(this.PegImages[myBoard.Rows[i][j] - 1], Boxes[i, j].X + 3, Boxes[i, j].Y + 3);
                    }
                    else
                    {
                        gOffScreen.DrawImage(this.PegHole, Boxes[i, j].X + 3, Boxes[i, j].Y + 3);
                    }
                }
            }


            //  --------------------------------------------------------
            // pegs drawing on Peg Tray
            //  --------------------------------------------------------
            gOffScreen.DrawRectangle(DarkPen, ColorPelleteTray);
            for (int i = 0; i < ColorPellete.Length; i++)
            {
                gOffScreen.DrawImage(this.PegImages[i], ColorPellete[i].X + 3, ColorPellete[i].Y + 3);
            }
            //  -------------------------------------------------------
            //  draw master Which is Hiding Colors
            //  --------------------------------------------------------
            Rectangle rm = new Rectangle(MasterBoxes[0].X + 2, MasterBoxes[0].Y + 2, MasterBoxes[0].Width * 4 - 4, MasterBoxes[0].Height - 4);

            if (myBoard.Status == GameStatus.Active)
            {
                gOffScreen.DrawString("MasterMind", this.MyFont, this.DarkBrush, MasterBoxes[0].X + 5, MasterBoxes[0].Y + 3);
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    gOffScreen.DrawImage(this.PegImages[myBoard.master.Row[i] - 1], MasterBoxes[i].X + 3, MasterBoxes[i].Y + 3);
                }
            }
            //  -------------------------------------------------------
            //  draw results  with White and Black Pegs
            //  -------------------------------------------------------
            for (int i = 0; i <= myBoard.ActiveRowNo; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    Rectangle ResultCircle = new Rectangle(ResultBoxes[i, j].X + 2, ResultBoxes[i, j].Y + 2, ResultBoxes[i, j].Width - 4, ResultBoxes[i, j].Height - 4);
                    if (myBoard.Results[i][j] != 0)
                    {
                        if (myBoard.Results[i][j] == 1)
                        {
                            gOffScreen.DrawImage(this.ResultBlackPeg, ResultBoxes[i, j].X + 1, ResultBoxes[i, j].Y + 1);
                        }
                        else
                        {
                            gOffScreen.DrawImage(this.ResultWhitePeg, ResultBoxes[i, j].X + 1, ResultBoxes[i, j].Y + 1);
                        }
                    }
                }
            }

            //  -------------------------------------------------------
            // Drawing Of Ok Button
            //  -------------------------------------------------------
            if (myBoard.Status == GameStatus.Active)
            {
                if (myBoard.ActiveRowIsComplite)
                {
                    Ok.Y = StartPoint.Y + myBoard.ActiveRowNo * boxWidth;
                    DrawingUtility.DrawRaisedString(ref gOffScreen, "Ok", Ok, this.BackColor, MyFont);
                }
            }
        }
示例#8
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // this code will handle droping peg on board  if Player was
            // draging peg from tray and Click on Ok While current Row is
            // filled
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


            // ------------------------------------------------------------
            // Stop Draging if its on
            // ------------------------------------------------------------
            PegPicking = false;

            // ------------------------------------------------------------
            //  Inserting Pegs but only is Game is Active
            // ------------------------------------------------------------
            if (myBoard.Status == GameStatus.Active)
            {
                for (int j = 0; j < 4; j++)
                {
                    // Allow insert only in Active Row.
                    if (DrawingUtility.isPointinRectangle(new Point(e.X, e.Y), Boxes[myBoard.ActiveRowNo, j]) == true)
                    {
                        myBoard.Rows[myBoard.ActiveRowNo][j] = (byte)(myBoard.SelectedPeg + 1);
                        break;
                    }
                }
            }

            // ------------------------------------------------------------
            // Check For Ok button Click
            // ------------------------------------------------------------
            if (DrawingUtility.isPointinRectangle(new Point(e.X, e.Y), Ok) == true)
            {
                myBoard.test();
            }



            // ---------------------------------------------------------
            // Insert messages in to status bar as required
            // ---------------------------------------------------------
            if (myBoard.Status == GameStatus.Active)
            {
                if (myBoard.ActiveRowIsComplite)
                {
                    statusBar.Text = "Press Ok to validate result";
                }
                else
                {
                    statusBar.Text = "Fill active row";
                }
            }
            else if (myBoard.Status == GameStatus.Won)
            {
                statusBar.Text = "You Won, play new!";
            }
            else if (myBoard.Status == GameStatus.Lost)
            {
                statusBar.Text = "You lost, play new!";
            }

            // ---------------------------------------------------
            // Repaint Screen to show changes in game
            // ---------------------------------------------------
            Invalidate();
        }