Exemple #1
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (canFall(fallFigur))
     {
         fallFigur.stepFigure();
     }
     else 
     {
         liyPoints.AddRange(fallFigur.FillPoints);
         foreach (Point pn in fallFigur.FillPoints)
         {
             tetr[pn.X / width, pn.Y / width] = true;
         }
         checkLine();
         cehckFail();
         fallFigur = randomFigure();
     }
     pictureBox1.Invalidate();
 }
Exemple #2
0
 private void timer2_Tick(object sender, EventArgs e)
 {
     switch (lastKey)
     {
         /*case KeyPressed.Space:
             fallFigur.rotate();
             break;*/
         case KeyPressed.A:
             if (canLeft(fallFigur))
             {
                 fallFigur.LeftPoint = new Point(fallFigur.LeftPoint.X - width, fallFigur.LeftPoint.Y);
                 pictureBox1.Invalidate();
             }
             break;
         case KeyPressed.D:
             if (canRight(fallFigur))
             {
                 fallFigur.LeftPoint = new Point(fallFigur.LeftPoint.X + width, fallFigur.LeftPoint.Y);
                 pictureBox1.Invalidate();
             }
             break;
         case KeyPressed.S:
             timer1.Enabled=timer2.Enabled=false;
             while (canFall(fallFigur))
             {
                 fallFigur.stepFigure();
             }
             liyPoints.AddRange(fallFigur.FillPoints);
             foreach (Point pn in fallFigur.FillPoints)
             {
                 tetr[pn.X / width, pn.Y / width] = true;
             }
             checkLine();
             cehckFail();
             fallFigur = randomFigure();
             pictureBox1.Invalidate();
             timer1.Enabled = timer2.Enabled = true;
             lastKey = KeyPressed.None;
             break;
     }
 }
Exemple #3
0
        private bool canRight(Figure fg)
        {
            bool result = fg.RightPoint.X + width < pictureBox1.Width - 1;
            foreach (Point point in liyPoints)
            {
                foreach (Point point2 in fg.FillPoints)
                {
                    if (point.Equals(new Point(point2.X + width, point2.Y)))
                        return false;
                }
            }

            return result;
        }
Exemple #4
0
 private bool canLeft(Figure fg)
 {
     bool result = fg.LeftPoint.X - width >= 0;
     foreach (Point point in liyPoints)
     {
         foreach (Point point2 in fg.FillPoints)
         {
             if (point.Equals(new Point(point2.X - width, point2.Y)))
                 return false;
         }
     }
     return result;
 }
Exemple #5
0
        private bool canFall(Figure fg)
            {
            bool result = fg.BottomPoint.Y + width < pictureBox1.Height - 1;
            foreach (Point point in liyPoints)
            {
                foreach (Point point2 in fg.FillPoints)
                {
                    if (point.Equals(new Point(point2.X, point2.Y + width)))
                        return false;
                }
            }
            return result;

        }
Exemple #6
0
 public static void AddFigure(Figure figure)
 {
     figureList.Add(figure);
 }
Exemple #7
0
 private void многоугольникToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var o = new Figure(comboBox1.SelectedIndex+5);
     FigureList.Add(o);
     Invalidate();
 }