Example #1
0
 private void gamePBox_Paint(object sender, PaintEventArgs e)
 {
     if (currentGame != null)
     {
         byte[,] currentGlass = currentGame.GetGlassSnapshot();
         int w = gamePBox.Width / currentGlass.GetLength(1);
         int h = gamePBox.Height / currentGlass.GetLength(0);
         for (int i = currentGlass.GetLowerBound(0); i <= currentGlass.GetUpperBound(0); i++)
         {
             for (int j = currentGlass.GetLowerBound(1); j <= currentGlass.GetUpperBound(1); j++)
             {
                 byte type = currentGlass[i, j];
                 if (type != 0)
                 {
                     Pen        p  = new Pen(Color.Black);
                     SolidBrush br = new SolidBrush(colors[type]);
                     int        x  = j * w;
                     int        y  = (currentGlass.GetUpperBound(0) - i) * h;
                     e.Graphics.DrawRectangle(p, x, y, w, h);
                     e.Graphics.FillRectangle(br, x + 3, y + 3, w - 6, h - 6);
                     p.Dispose();
                     br.Dispose();
                 }
             }
         }
         if (currentGame.GameOver)
         {
             Font         strFont  = new Font("Arial", 24);
             SolidBrush   strBrush = new SolidBrush(Color.IndianRed);
             StringFormat strForm  = new StringFormat();
             strForm.Alignment = StringAlignment.Center;
             e.Graphics.DrawString("GAME OVER", strFont, strBrush, gamePBox.DisplayRectangle, strForm);
             strFont.Dispose();
             strBrush.Dispose();
         }
         if (currentGame.Paused)
         {
             Font         strFont  = new Font("Arial", 24);
             SolidBrush   strBrush = new SolidBrush(Color.DeepSkyBlue);
             StringFormat strForm  = new StringFormat();
             strForm.Alignment = StringAlignment.Center;
             e.Graphics.DrawString("GAME PAUSED", strFont, strBrush, gamePBox.DisplayRectangle, strForm);
             strFont.Dispose();
             strBrush.Dispose();
         }
     }
 }