示例#1
0
 public void TimerTick(object sender, EventArgs e)
 {
     if (activeShape != null)
     {
         List <Rectangle> children = activeShape.getChildren();
         if (hitCheckDown() != false)
         {
             if (activeShape.getMaxY() < 600)
             {
                 for (int x = 0; x < children.Count; x++)
                 {
                     Rectangle rect = children.ElementAt(x);
                     rect.Y += 5;
                     lock (locker)
                     {
                         children.Remove(children.ElementAt(x));
                         children.Insert(x, rect);
                     }
                 }
                 sm.increaseScore();
             }
             else
             {
                 startNewShape();
             }
         }
         else
         {
             startNewShape();
         }
     }
     panel.Refresh();
 }
示例#2
0
 private void panel3_Paint(object sender, PaintEventArgs e)
 {
     if (gm.getNextShape() != null)
     {
         System.Drawing.Graphics formGraphics = e.Graphics;
         nextShape = gm.getNextShape();
         Color      color   = nextShape.getColor();
         SolidBrush brush   = new SolidBrush(color);
         Composite  c       = gm.getActiveShape();
         int        xOffset = 0;
         int        yOffset = 0;
         if (color == Color.Cyan)
         {
             yOffset = -25;
             xOffset = -2;
         }
         else if (color == Color.Blue || color == Color.Magenta)
         {
             yOffset = -10;
             xOffset = 15;
         }
         else if (color == Color.Orange || color == Color.Red || color == Color.Green)
         {
             yOffset = 5;
         }
         else if (color == Color.Yellow)
         {
             yOffset = -10;
         }
         foreach (Rectangle rect in nextShape.getChildren())
         {
             Rectangle rect1 = new Rectangle(rect.X - 145 + xOffset, rect.Y + 70 + yOffset, 30, 30);
             formGraphics.FillRectangle(brush, rect1);
             if (outline == true)
             {
                 formGraphics.DrawRectangle(new Pen(Color.Black), rect1);
             }
         }
         brush.Dispose();
         formGraphics.Dispose();
     }
 }
示例#3
0
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            System.Drawing.Graphics formGraphics = e.Graphics;
            SolidBrush brush = new SolidBrush(Color.Black);

            if (gm.getActiveShape() != null)
            {
                Composite c = gm.getActiveShape();
                brush = new SolidBrush(c.getColor());

                Font         drawFont  = null;
                SolidBrush   drawBrush = null;
                string       drawString;
                StringFormat drawFormat = null;
                float        x, y;
                if (labels == true)
                {
                    drawString = "";
                    drawFont   = new Font("Arial", 9);
                    if (c.getColor() != Color.Yellow && c.getColor() != Color.Cyan)
                    {
                        drawBrush = new SolidBrush(Color.White);
                    }
                    else
                    {
                        drawBrush = new SolidBrush(Color.Black);
                    }
                    x          = 0;
                    y          = 0;
                    drawFormat = new StringFormat();
                }

                foreach (Rectangle rect in c.getChildren())
                {
                    formGraphics.FillRectangle(brush, rect);
                    if (outline == true)
                    {
                        formGraphics.DrawRectangle(new Pen(Color.Black), rect);
                    }
                    if (labels == true)
                    {
                        int column = (rect.X / 30) + 1;
                        drawString = "" + column;
                        x          = rect.X + 10;
                        y          = rect.Y + 10;
                        if (column >= 10)
                        {
                            x -= 3;
                        }
                        formGraphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
                    }
                }
            }
            foreach (Composite comp in gm.getShapes())
            {
                Font         drawFont  = null;
                SolidBrush   drawBrush = null;
                string       drawString;
                StringFormat drawFormat = null;
                float        x, y;
                if (labels == true)
                {
                    drawString = "";
                    drawFont   = new Font("Arial", 9);
                    if (comp.getColor() != Color.Yellow && comp.getColor() != Color.Cyan)
                    {
                        drawBrush = new SolidBrush(Color.White);
                    }
                    else
                    {
                        drawBrush = new SolidBrush(Color.Black);
                    }
                    x          = 0;
                    y          = 0;
                    drawFormat = new StringFormat();
                }
                brush = new SolidBrush(comp.getColor());
                foreach (Rectangle rect in comp.getChildren())
                {
                    formGraphics.FillRectangle(brush, rect);
                    if (outline == true)
                    {
                        formGraphics.DrawRectangle(new Pen(Color.Black), rect);
                    }
                    if (labels == true)
                    {
                        int column = (rect.X / 30) + 1;
                        drawString = "" + column;
                        x          = rect.X + 10;
                        y          = rect.Y + 10;
                        if (column >= 10)
                        {
                            x -= 3;
                        }
                        formGraphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
                    }
                }
            }

            if (gm.isPaused() == true)
            {
                string drawString = "P A U S E D";
                System.Drawing.Font       drawFont  = new System.Drawing.Font("Arial", 24);
                System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
                float x = 120;
                float y = 200;
                System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
                formGraphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
                drawFont.Dispose();
                drawBrush.Dispose();
            }
            if (gm.getGameEnd() == true)
            {
                string drawString = "G A M E  O V E R";
                System.Drawing.Font       drawFont  = new System.Drawing.Font("Arial", 24);
                System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
                float x = 80;
                float y = 200;
                System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
                formGraphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
                drawFont.Dispose();
                drawBrush.Dispose();
            }
            panel2.Refresh();
            if (nextShape != gm.getNextShape())
            {
                panel3.Refresh();
            }
            brush.Dispose();
            //formGraphics.Dispose();
        }