Exemplo n.º 1
0
        static void Game()
        {
            snake.body.Add(new Point(20, 20));
            while (!gameOver)
            {
                if (cnt == 3)
                {
                    level++;
                    cnt  = 0;
                    wall = new Wall(level);
                }
                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 (direction1 == 1)
                {
                    snake1.Move(0, -1);
                }
                if (direction1 == 2)
                {
                    snake1.Move(0, 1);
                }
                if (direction1 == 3)
                {
                    snake1.Move(1, 0);
                }
                if (direction1 == 4)
                {
                    snake1.Move(-1, 0);
                }
                while (snake.Inthesnake(fruit.coordinates.x, fruit.coordinates.y) || snake.Inthewall(fruit.coordinates.x, fruit.coordinates.y, wall))
                {
                    fruit.FoodMaker();
                }
                if (snake.Bump() || snake.Collide(wall))
                {
                    Console.Clear();
                    Console.SetCursorPosition(50, 50);
                    Console.WriteLine("GAME OVER");
                    Console.ReadKey();
                    snake = new Snake();
                    snake.body.Add(new Point(20, 20));
                    level = 1;
                    score = 0;
                    cnt   = 0;
                    speed = 120;
                }

                if (snake.Eaten(fruit) == true)
                {
                    cnt++;
                    score++;
                }
                Console.Clear();
                snake.Draw();
                fruit.DrawFood();
                wall.Draw();
                Console.SetCursorPosition(150, 200);
                Console.Write("Score:" + score.ToString());
                Console.Write("Level:" + level);

                if (cnt % 3 == 0 && cnt != 0)
                {
                    speed = Math.Max(speed - 1, 1);
                }

                Thread.Sleep(speed);
            }
        }