示例#1
0
        public void Process(ConsoleKeyInfo pressedButton)
        {
            switch (pressedButton.Key)
            {
            case ConsoleKey.LeftArrow:
                worm.DY = 0;
                worm.DX = -1;
                break;

            case ConsoleKey.RightArrow:
                worm.DY = 0;
                worm.DX = 1;
                break;

            case ConsoleKey.UpArrow:
                worm.DY = -1;
                worm.DX = 0;
                break;

            case ConsoleKey.DownArrow:
                worm.DY = 1;
                worm.DX = 0;
                break;

            case ConsoleKey.Spacebar:
                if (isPaused)
                {
                    isPaused = false;
                    Start();
                }
                else
                {
                    isPaused = true;
                    Stop();
                }
                break;

            case ConsoleKey.F1:
                if (isPaused)
                {
                    pts = points;
                    l   = lev;
                    worm.Save();
                    food.Save();
                    wall.Save();
                }
                break;

            case ConsoleKey.F2:
                if (isPaused)
                {
                    Console.Clear();
                    DrawField();
                    points = pts;
                    lev    = l;
                    worm   = worm.Load() as Worm;
                    food   = food.Load() as Food;
                    wall   = wall.Load() as Wall;
                    Draw();
                }
                break;

            case ConsoleKey.Escape:
                alive = false;
                Stop();
                DrawGameOver();
                break;

            default:
                break;
            }
        }
示例#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;
                }
            }
        }