示例#1
0
文件: Game.cs 项目: zhengissov/PT2017
        public void Load()
        {
            worm = new Worm();
            worm.AttachGameLink(this);

            wall = new Wall();
            food = new Food();
            food.Generate(wall, worm);
            worm.Generate(wall);
            wall.Generate(level);
            worm.Draw();
            wall.Draw();
            food.Draw();
        }
示例#2
0
文件: Game.cs 项目: zhengissov/PT2017
        public void Start()
        {
            Load();


            Thread t = new Thread(new ThreadStart(worm.Move));

            t.Start();

            while (true)
            {
                wall.Save();
                if (score == 500 && nextLevel == true)
                {
                    level = level + 1;
                    wall.Clear();
                    wall.Generate(level);
                    wall.Draw();
                    nextLevel = false;
                    score     = 0;

                    worm.Clear();
                    Point p = new Point();
                    p = worm.points[0];
                    worm.points.Clear();
                    worm.points.Add(p);
                }

                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.F2:
                    this.Save();
                    break;

                case ConsoleKey.F3:
                    wall = wall.Load() as Wall;
                    wall.Draw();
                    worm.Clear();
                    worm = worm.Load() as Worm;
                    worm.AttachGameLink(this);
                    t.Abort();

                    t = new Thread(new ThreadStart(worm.Move));
                    t.Start();
                    break;

                case ConsoleKey.UpArrow:
                    worm.dx = 0;
                    worm.dy = -1;
                    break;

                case ConsoleKey.DownArrow:
                    worm.dx = 0;
                    worm.dy = 1;
                    break;

                case ConsoleKey.LeftArrow:
                    worm.dx = -1;
                    worm.dy = 0;
                    break;

                case ConsoleKey.RightArrow:
                    worm.dx = 1;
                    worm.dy = 0;
                    break;

                case ConsoleKey.Escape:
                    break;
                }
            }
        }