示例#1
0
文件: Program.cs 项目: aimlee/PPII
        static void MoveSnakeThread(object state)
        {
            while (!Game.GameOver(Game.Wall))
            {
                if (Game.snake.body[0].x < 13)
                {
                    Game.snake.body[0].x = 96;
                }
                if (Game.snake.body[0].x > 95)
                {
                    Game.snake.body[0].x = 12;
                }
                if (Game.snake.body[0].y < 8)
                {
                    Game.snake.body[0].y = 21;
                }
                if (Game.snake.body[0].y > 21)
                {
                    Game.snake.body[0].y = 7;
                }
                switch (direction)
                {
                case 1:
                    Game.snake.Move(1, 0);
                    break;

                case 2:
                    Game.snake.Move(0, 1);
                    break;

                case 3:
                    Game.snake.Move(-1, 0);
                    break;

                case 4:
                    Game.snake.Move(0, -1);
                    break;
                }
                if (Game.GameOver(Game.Wall))
                {
                    Game.snake.a = 0;

                    Console.Clear();

                    Game.snake.body = new List <Point>();
                    Game.snake.body.Add(new Point(16, 7));
                    Game.snake.body.Add(new Point(15, 7));
                    Game.snake.body.Add(new Point(14, 7));
                }

                if (Game.snake.CanEat(Game.food))
                {
                    Game.food.setRandomPosition();
                    Game.a++;
                }

                Game.Draw();
                Thread.Sleep(speed);
            }
        }
示例#2
0
 static void Main(string[] args)
 {
     Inizialize();
     Game.StartGame();
     Game.Update();
     Game.GameOver();
 }
示例#3
0
文件: Program.cs 项目: aimlee/PPII
        static void Main(string[] args)
        {
            Console.WriteLine(" ");
            Console.WriteLine(" ");

            Console.WriteLine("     Score: ");
            Console.WriteLine("     " + Game.a);

            Game.Gamesize();

            if (Game.GameOver(Game.Wall))
            {
                Console.Clear();
                Game.snake.body = new List <Point>();

                Game.snake.body.Add(new Point(16, 7));
                Game.snake.body.Add(new Point(15, 7));
                Game.snake.body.Add(new Point(14, 7));
            }

            Thread t = new Thread(MoveSnakeThread);

            t.Start();


            while (!Game.GameOver(Game.Wall))
            {
                ConsoleKeyInfo btn = Console.ReadKey();
                switch (btn.Key)
                {
                case ConsoleKey.UpArrow:
                    direction = 4;
                    break;

                case ConsoleKey.DownArrow:
                    direction = 2;
                    break;

                case ConsoleKey.LeftArrow:
                    direction = 3;
                    break;

                case ConsoleKey.RightArrow:
                    direction = 1;
                    break;
                }
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80 + 1, 30 + 1);
            Console.SetBufferSize(80 + 1, 30 + 1);
            Console.CursorVisible = false;

            game = new Game(80, 30);
            game.Snake.IsAlive = true;
            game.FoodFactory.Create();

            timer = new Timer(game.Loop, null, 0, 125);

            while (game.Snake.IsAlive)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                game.Snake.Rotate(key.Key);
            }

            game.GameOver();
        }