Ejemplo n.º 1
0
        }// Main()

        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();
            }
        } // Loop()
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int   score = 0;
            Walls walls = new Walls(80, 25);

            walls.Draw();

            Point snakeTail = new Point(15, 15, 'X');
            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.HandelKeys(key.Key);
                }

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

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