void Draw() { if (snake.body[0].Equals(food.body)) { Sound(); snake.body.Add(food.body); bool ok = false; while (!ok) { bool ok1 = false; Point f = food.Generate(); foreach (Point p1 in snake.body) { if (f.Equals(p1)) { ok1 = false; break; } ok1 = true; foreach (Point p2 in wall.body) { if (f.Equals(p2)) { ok1 = false; break; } ok1 = true; } } ok = ok1; food.body = f; } food.Draw(); score += ShowSpeed; } else { foreach (Point p in wall.body) { if (snake.body[0].Equals(p)) { snake.IsAlive = false; break; } } foreach (Point p in snake.body) { if (p != snake.body[0] && p.Equals(snake.body[0])) { snake.IsAlive = false; break; } } } if (!snake.IsAlive) { return; } if (score >= (currentLevel + 1) * 25) { currentLevel++; wall.Clear(); wall.LoadLevel(currentLevel); snake.Clear2(); snake.body.Clear(); food.Clear(); snake.body.Add(new Point { X = 35, Y = 11, Sign = '█' }); snake.Draw(); bool ok = false; while (!ok) { bool ok1 = false; Point f = food.Generate(); foreach (Point p1 in snake.body) { if (f.Equals(p1)) { ok1 = false; break; } ok1 = true; foreach (Point p2 in wall.body) { if (f.Equals(p2)) { ok1 = false; break; } ok1 = true; } } ok = ok1; food.body = f; } food.Draw(); wall.Draw(); snake.Draw(); snake.ChangeDirection(Console.ReadKey()); } snake.Draw(); StatusBar(); }
public void MoveSnake() { while (isAlive) { snake.Move(); if (snake.IsCollisionWithObject(food)) { snake.body.Add(new Point(1, 22)); DrawScore(); if (snake.body.Count < 9 && snake.body.Count % 4 == 0) { time = time - 70; wall.Clear(); wall.NextLevel(); wall.Draw(); DrawLevel(); snake.InitialPosition(); while (food.IsCollisionWithObject(snake) || food.IsCollisionWithObject(wall)) { food.Generate(); } food.Draw(); } else { while (food.IsCollisionWithObject(snake) || food.IsCollisionWithObject(wall)) { food.Generate(); } food.Draw(); } } if (snake.IsCollisionWithSnake(snake)) { isAlive = false; } if (snake.IsCollisionWithObject(wall)) { isAlive = false; } if (isAlive == false) { if (File.Exists(Nickname + ".xml")) { File.Delete(Nickname + ".xml"); } Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(23, 10); Console.WriteLine("GAME OVER"); Console.SetCursorPosition(22, 12); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("YOUR SCORE:" + ((snake.body.Count * 10) - 10)); Console.ReadKey(); break; } snake.Clear(); snake.Draw(); Thread.Sleep(time); } }