Exemplo n.º 1
0
 static bool playlevel(int level)
 {
     Console.SetWindowSize(szx, szy);
     Console.Clear();
     Console.WriteLine("Welcome to level {0}", level);
     Console.ReadKey();
     Console.SetCursorPosition(1, 1);
     snake dragon = new snake(1, 1);
     Wall = new wall();
     Food = new food();
     for(int i = 0; i < level+1; ++i)
     {
         pair t = new pair((getrand() % szx + szx) % szx, (getrand() % szy + szy) % szy);
         Food.add(t.x, t.y);
     }
     for (int i = 0; i < 4 * level; ++i)
     {
         pair t = new pair((getrand() % szx + szx) % szx, (getrand() % szy + szy) % szy);
         while(t.x == 1 && t.y == 1)
             t = new pair((getrand() % szx + szx) % szx, (getrand() % szy + szy) % szy);
         Wall.add(t.x, t.y);
     }
     Draw risovanie = new Draw(dragon, Wall, Food);
     while (!risovanie.dragon.lose)
     {
         ConsoleKeyInfo button = Console.ReadKey();
         if(button.Key == ConsoleKey.UpArrow)
         {
             dragon.makemove(0, -1, szx, szy, Food);
         }
         else if(button.Key == ConsoleKey.DownArrow)
         {
             dragon.makemove(0, +1, szx, szy, Food);
         }
         else if (button.Key == ConsoleKey.RightArrow)
         {
             dragon.makemove(1, 0, szx, szy, Food);
         }
         else if (button.Key == ConsoleKey.LeftArrow)
         {
             dragon.makemove(-1, 0, szx, szy, Food);
         }
         if (dragon.body.Count % (level + 5) == 0)
             return true;
         risovanie.Print();
     }
     if(dragon.lose)
     {
         Console.Clear();
         Console.WriteLine("You Lost");
         Console.ReadKey();
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 public Draw(snake a, wall b, food c)
 {
     dragon = a; Wall = b; Food = c;
 }
Exemplo n.º 3
0
 public Draw()
 {
     dragon = new snake();
     Wall = new wall();
     Food = new food();
 }