示例#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();
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WindowWidth   = GlobalConstants.ConsoleWidth;
            Console.WindowHeight  = GlobalConstants.ConsoleHeigth;
            Console.BufferHeight  = GlobalConstants.ConsoleHeigth;
            Console.BufferWidth   = GlobalConstants.ConsoleWidth;
            Console.CursorVisible = false;

            IPositionalRenderer renderer   = new ConsoleRenderer();
            IReader             reader     = new ConsoleReader();
            IFoodGenerator      generator  = new FoodGenerator();
            IGameEngine         gameEngine = new SnakeEngine(renderer, reader, generator);

            gameEngine.Start();
        }
示例#3
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();
        }