// -------------------------------------------------------------------------------- static void Main() { welcome(); Console.Clear(); Console.BufferHeight = Console.WindowHeight; position[] directions = new position[] { new position(0, 1), //0 -> right > new position(0, -1), //1 -> left < new position(1, 0), //2-> down v new position(-1, 0) //3 -> up ^ }; double speed = new double(); if (level == 1) { Level1 lev_one = new Level1(); speed = 100; play(lev_one, directions, speed); } else { Level2 lev_two = new Level2(); speed = 70; play(lev_two, directions, speed); } }
public static void play(Level1 lev_one, position[] directions, double speed) { lev_one.ap.Display(); DateTime startTime = DateTime.Now; while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo userInput = Console.ReadKey(); lev_one.get_direction(userInput); } position oldHead = new position(); position next = new position(); position newHead = new position(); oldHead = lev_one.Snake.OldHead(); next = directions[lev_one.Direction]; // GAME OVER logic newHead = new position(oldHead.row + next.row, oldHead.col + next.col); set_new_h(ref newHead); if (lev_one.check_snake_dead(newHead)) //<-samoiziajd { if (lev_one.check_snake_dead(newHead)) { lev_one.snake_dead(startTime, 1); } } Console.SetCursorPosition(oldHead.col, oldHead.row); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("*"); //include the new head in the queue lev_one.Snake.Put(newHead); Console.SetCursorPosition(newHead.col, newHead.row); lev_one.show_direction(); if (lev_one.snake_eating(newHead)) { lev_one.apple = new Apple(lev_one.Snake); lev_one.apple.Display(); //speed -= 0.01; // if we want to speed on every success } else { position last = new position(); last = lev_one.Snake.RemoveLast(); lev_one.apple.Display(); Console.SetCursorPosition(last.col, last.row); Console.Write(" "); } speed -= 0.01; Thread.Sleep((int)speed); } }