示例#1
0
 public void Level(Wall wall, snake snake)
 {
     if (snake.body.Count == 4)
     {
         Console.Clear();
         wall.cnt++;
         wall.ReadLevel();
         int a = 1;
         for (int i = 0; i < snake.body.Count; i++)
         {
             snake.body[i].x = a;
             snake.body[i].y = 10;
             a++;
         }
     }
     if (snake.body.Count == 8)
     {
         Console.Clear();
         wall.cnt++;
         wall.ReadLevel();
         int b = 1;
         for (int i = 0; i < snake.body.Count; i++)
         {
             snake.body[i].x = b;
             snake.body[i].y = 10;
             b++;
         }
     }
 }
示例#2
0
 public static void Func()
 {
     while (k == 0)
     {
         if ((food.loc.x == snake.body[0].x && food.loc.y == snake.body[0].y))
         {
             wall.Level(wall, snake);
             if (snake.body.Count > 1)
             {
                 snake.body.Add(new Point(snake.body[snake.body.Count - 1].x, snake.body[snake.body.Count - 1].y));
             }
             else
             {
                 snake.body.Add(new Point(5, 5));
             }
             food.SetRandomPosition(wall, snake);
             food.Draw();
         }
         if (direction == 1)
         {
             snake.Move(0, 1);
         }
         if (direction == 2)
         {
             snake.Move(0, -1);
         }
         if (direction == 3)
         {
             snake.Move(1, 0);
         }
         if (direction == 4)
         {
             snake.Move(-1, 0);
         }
         if (snake.CollisionWithWall(snake, wall))
         {
             snake.Save(name, snake.body.Count);
             k = 1;
         }
         food.Draw();
         snake.Draw();
         wall.ReadLevel();
         wall.Draw();
         Thread.Sleep(100);
     }
 }