예제 #1
0
 private void Clear_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < 64; i++)
     {
         space drawSpace = ((space)coordinates[i]);
         drawSpace.setOccupied(false);
         totalQueens = 0;
     }
     Invalidate();
 }
예제 #2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             int y = (50 * i + 100);
             int x = (50 * j + 100);
             space boardSpace = new space(x, y, i, j);
             coordinates.Add(boardSpace);
         }
     }
 }
예제 #3
0
 private void Form1_Load(object sender, EventArgs e)
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             int   y          = (50 * i + 100);
             int   x          = (50 * j + 100);
             space boardSpace = new space(x, y, i, j);
             coordinates.Add(boardSpace);
         }
     }
 }
예제 #4
0
 private void Form1_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         for (int i = 0; i < 64; i++)
         {
             space drawSpace = ((space)coordinates[i]);
             if (drawSpace.isClicked(e.X, e.Y))
             {
                 if (drawSpace.isValid(coordinates))
                 {
                     drawSpace.setOccupied(true);
                     totalQueens++;
                 }
                 else
                 {
                     System.Media.SystemSounds.Beep.Play();
                 }
             }
         }
     }
     if (e.Button == MouseButtons.Right)
     {
         for (int i = 0; i < 64; i++)
         {
             space drawSpace = ((space)coordinates[i]);
             if (drawSpace.isClicked(e.X, e.Y))
             {
                 if (drawSpace.isOccupied())
                 {
                     drawSpace.setOccupied(false);
                     totalQueens--;
                 }
             }
         }
     }
     Invalidate();
 }
예제 #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;

            g.DrawString("Queen Count: " + totalQueens, Font, Brushes.Black, 140, 17);
            for (int i = 0; i < 64; i++)
            {
                space     drawSpace = ((space)coordinates[i]);
                Rectangle rect      = drawSpace.getRect();
                int       X         = drawSpace.getX();
                int       Y         = drawSpace.getY();
                if ((i / 8) % 2 == 0)
                {
                    if (i % 2 == 0)
                    {
                        if (!hints)
                        {
                            g.FillRectangle(Brushes.Black, rect);
                            g.DrawRectangle(Pens.Black, rect);
                            if (drawSpace.isOccupied())
                            {
                                Font useThis = new Font("Arial", 32);
                                g.DrawString("Q", useThis, Brushes.White, X, Y);
                            }
                        }
                        else
                        {
                            if (!drawSpace.isValid(coordinates))
                            {
                                g.FillRectangle(Brushes.Red, rect);
                                g.DrawRectangle(Pens.Black, rect);
                                if (drawSpace.isOccupied())
                                {
                                    Font useThis = new Font("Arial", 32);
                                    g.DrawString("Q", useThis, Brushes.White, X, Y);
                                }
                            }
                            else
                            {
                                g.FillRectangle(Brushes.Black, rect);
                                g.DrawRectangle(Pens.Black, rect);
                                if (drawSpace.isOccupied())
                                {
                                    Font useThis = new Font("Arial", 32);
                                    g.DrawString("Q", useThis, Brushes.White, X, Y);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!hints)
                        {
                            g.FillRectangle(Brushes.White, rect);
                            g.DrawRectangle(Pens.Black, rect);
                            if (drawSpace.isOccupied())
                            {
                                Font useThis = new Font("Arial", 32);
                                g.DrawString("Q", useThis, Brushes.Black, X, Y);
                            }
                        }
                        else
                        {
                            if (!drawSpace.isValid(coordinates))
                            {
                                g.FillRectangle(Brushes.Red, rect);
                                g.DrawRectangle(Pens.Black, rect);
                                if (drawSpace.isOccupied())
                                {
                                    Font useThis = new Font("Arial", 32);
                                    g.DrawString("Q", useThis, Brushes.White, X, Y);
                                }
                            }
                            else
                            {
                                g.FillRectangle(Brushes.White, rect);
                                g.DrawRectangle(Pens.Black, rect);
                                if (drawSpace.isOccupied())
                                {
                                    Font useThis = new Font("Arial", 32);
                                    g.DrawString("Q", useThis, Brushes.Black, X, Y);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (i % 2 == 1)
                    {
                        if (!hints)
                        {
                            g.FillRectangle(Brushes.Black, rect);
                            g.DrawRectangle(Pens.Black, rect);
                            if (drawSpace.isOccupied())
                            {
                                Font useThis = new Font("Arial", 32);
                                g.DrawString("Q", useThis, Brushes.White, X, Y);
                            }
                        }
                        else
                        {
                            if (!drawSpace.isValid(coordinates))
                            {
                                g.FillRectangle(Brushes.Red, rect);
                                g.DrawRectangle(Pens.Black, rect);
                                if (drawSpace.isOccupied())
                                {
                                    Font useThis = new Font("Arial", 32);
                                    g.DrawString("Q", useThis, Brushes.White, X, Y);
                                }
                            }
                            else
                            {
                                g.FillRectangle(Brushes.Black, rect);
                                g.DrawRectangle(Pens.Black, rect);
                                if (drawSpace.isOccupied())
                                {
                                    Font useThis = new Font("Arial", 32);
                                    g.DrawString("Q", useThis, Brushes.White, X, Y);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!hints)
                        {
                            g.FillRectangle(Brushes.White, rect);
                            g.DrawRectangle(Pens.Black, rect);
                            if (drawSpace.isOccupied())
                            {
                                Font useThis = new Font("Arial", 32);
                                g.DrawString("Q", useThis, Brushes.Black, X, Y);
                            }
                        }
                        else
                        {
                            if (!drawSpace.isValid(coordinates))
                            {
                                g.FillRectangle(Brushes.Red, rect);
                                g.DrawRectangle(Pens.Black, rect);
                                if (drawSpace.isOccupied())
                                {
                                    Font useThis = new Font("Arial", 32);
                                    g.DrawString("Q", useThis, Brushes.White, X, Y);
                                }
                            }
                            else
                            {
                                g.FillRectangle(Brushes.White, rect);
                                g.DrawRectangle(Pens.Black, rect);
                                if (drawSpace.isOccupied())
                                {
                                    Font useThis = new Font("Arial", 32);
                                    g.DrawString("Q", useThis, Brushes.Black, X, Y);
                                }
                            }
                        }
                    }
                }
            }
            if (totalQueens == 8)
            {
                for (int i = 0; i < 64; i++)
                {
                    space drawSpace = ((space)coordinates[i]);
                    drawSpace.setOccupied(false);
                    totalQueens = 0;
                }
                MessageBox.Show("You win!");
            }
        }