static void Loop(object obj) // якщо змійка зіштовхнулася з стіною або з своїм хвостом, то час зупиняється і поинається заново { if (walls.IsHit(snake.GetHead()) || snake.IsHit(snake.GetHead())) { time.Change(0, Timeout.Infinite); } else if (snake.Eat(foodFactory.food)) // якщо змійка з'їла їжу то створюється новий об'єкт { foodFactory.CreateFood(); } else //якщо нічого не салося то змійка продовжує рухатися { snake.Move(); } }
static void Main(string[] args) { Console.SetWindowSize(80, 30); Walls walls = new Walls(80, 25); walls.Draw(); Point p = new Point(4, 5, '*'); Snakee snake = new Snakee(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(80, 25, '$'); Point food = foodCreator.CreateFood(); food.Draw(); Params settings = new Params(); Sound sound = new Sound(settings.GetResourcesFolder()); sound.Play(); Sound sound1 = new Sound(settings.GetResourcesFolder()); Sound sound2 = new Sound(settings.GetResourcesFolder()); int i = 0; while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { Gameover gameover = new Gameover(); gameover.Game(); sound2.PlayDied(); Console.Write("Ente your name: "); String nimi = (Console.ReadLine()); Console.WriteLine(nimi + " scored " + i + " Points"); string answer = nimi + ": " + i + " Points"; StreamWriter to_file = new StreamWriter(@"C:\Users\Game\source\repos\Snake1\Snake1\resources\results.txt", true); to_file.WriteLine(answer); to_file.Close(); Console.ForegroundColor = ConsoleColor.White; StreamReader from_file = new StreamReader(@"C:\Users\Game\source\repos\Snake1\Snake1\resources\results.txt"); string text = from_file.ReadToEnd(); Console.WriteLine(text); from_file.Close(); break; } Score score = new Score(); score.Scoree(i); if (snake.Eat(food)) { i++; food = foodCreator.CreateFood(); food.Draw(); sound1.PlayEat(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } }