Beispiel #1
0
        static void Main(string[] args)
        {
            int   score = 0;
            Walls walls = new Walls(119, 29);

            walls.Draw();
            Point snakeTail = new Point(5, 5, 's');
            Snake snake     = new Snake(snakeTail, 10, Direction.RIGHT);

            snake.Draw();
            FoodGenerator foodGenerator = new FoodGenerator(119, 29, '$');
            Point         food          = foodGenerator.GenerateFood();

            food.Draw();


            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodGenerator.GenerateFood();
                    food.Draw();


                    Random rnd = new Random();
                    int    num = rnd.Next(1, 3);
                    if (num == 1)
                    {
                        score = score + 2;
                    }
                    else
                    {
                        score--;
                    }
                }
                else
                {
                    snake.Move();
                }


                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKeys(key.Key);
                }

                Thread.Sleep(300);
            }

            string str_score = Convert.ToString(score);

            WriteGameOver(str_score);
            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            int   score = 0;
            Walls walls = new Walls(80, 25);

            walls.Draw();

            Point snakeTail = new Point(15, 15, 's');
            Snake snake     = new Snake(snakeTail, 5, Direction.RIGHT);

            snake.Draw();

            FoodGenerator foodGenerator = new FoodGenerator(80, 25, '$');
            Point         food          = foodGenerator.GenerateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodGenerator.GenerateFood();
                    food.Draw();
                    score++;
                }
                else
                {
                    snake.Move();
                }

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKays(key.Key);
                }

                Thread.Sleep(300);
            }
            string str_score = Convert.ToString(score);

            WriteGameOver(str_score);
            Console.ReadLine();
        }