Пример #1
0
        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            for (int r = 0; r < NumCells; r++)
            {
                for (int c = 0; c < NumCells; c++)
                {
                    Brush brush;
                    Pen   pen;

                    if (lightsOut.GetGridValue(r, c))
                    {
                        pen   = Pens.Black;
                        brush = Brushes.White;
                    }
                    else
                    {
                        pen   = Pens.White;
                        brush = Brushes.Black;
                    }

                    int x = c * CellLength + GridOffset;
                    int y = r * CellLength + GridOffset;

                    g.DrawRectangle(pen, x, y, CellLength, CellLength);
                    g.FillRectangle(brush, x + 1, y + 1, CellLength - 1, CellLength - 1);
                }
            }
        }
Пример #2
0
        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            int cellLength = gridLength / game.GridSize;

            for (int r = 0; r < game.GridSize; r++)
            {
                for (int c = 0; c < game.GridSize; c++)
                {
                    // Get proper pen and brush for on/off grid section
                    Brush brush;
                    Pen   pen;

                    if (game.GetGridValue(r, c))
                    {
                        pen   = Pens.Black;
                        brush = Brushes.White;  // On
                    }
                    else
                    {
                        pen   = Pens.White;
                        brush = Brushes.Black;  // Off
                    }

                    // Determine (x,y) coord of row and col to draw rectangle
                    int x = c * cellLength + GridOffset;
                    int y = r * cellLength + GridOffset;

                    // Draw outline and inner rectangle
                    g.DrawRectangle(pen, x, y, cellLength, cellLength);
                    g.FillRectangle(brush, x + 1, y + 1, cellLength - 1, cellLength - 1);
                }
            }
        }
Пример #3
0
        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            int CellLength = GridLength / game.GridSize;

            for (int r = 0; r < game.GridSize; r++)
            {
                for (int c = 0; c < game.GridSize; c++)
                {
                    // Get proper pen and brush for on/off grid section
                    Brush brush;
                    Pen   pen;

                    if (game.GetGridValue(r, c))
                    {
                        pen   = Pens.Black;
                        brush = Brushes.White;
                    }
                    else
                    {
                        pen   = Pens.White;
                        brush = Brushes.Black;
                    }

                    int x = c * CellLength + GridOffset;
                    int y = r * CellLength + GridOffset;

                    g.DrawRectangle(pen, x, y, CellLength, CellLength);
                    g.FillRectangle(brush, x + 1, y + 1, CellLength - 1, CellLength - 1);
                }
            }
        }
Пример #4
0
        private void DrawGrid()
        {
            int index = 0;

            // Set the colors of the rectangles
            for (int r = 0; r < game.GridSize; r++)
            {
                for (int c = 0; c < game.GridSize; c++)
                {
                    Rectangle rect = boardCanvas.Children[index] as Rectangle;
                    index++;

                    if (game.GetGridValue(r, c))
                    {
                        // On
                        rect.Fill   = Brushes.White;
                        rect.Stroke = Brushes.Black;
                    }
                    else
                    {
                        // Off
                        rect.Fill   = Brushes.Black;
                        rect.Stroke = Brushes.White;
                    }
                }
            }
        }
Пример #5
0
 private void newGameButton_Click(object sender, EventArgs e)
 {
     lightsOutGame.NewGame();
     // Fill grid with either white or black
     for (int r = 0; r < NumCells; r++)
     {
         for (int c = 0; c < NumCells; c++)
         {
             grid[r, c] = lightsOutGame.GetGridValue(r, c);
         }
     }
     // Redraw grid
     this.Invalidate();
 }
Пример #6
0
        private Random rand;                // Used to generate random numbers
        public MainForm()
        {
            lightsOutGame = new LightsOutGame();

            InitializeComponent();
            rand = new Random();             // Initializes random number generator
            grid = new bool[NumCells, NumCells];

            for (int r = 0; r < NumCells; r++)
            {
                for (int c = 0; c < NumCells; c++)
                {
                    grid[r, c] = lightsOutGame.GetGridValue(r, c);
                }
            }
        }