コード例 #1
0
ファイル: Game.cs プロジェクト: DinaraNuriyeva/PP2
        public void Start()
        {
            Load();

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

            t.IsBackground = true;
            t.Start();


            while (true)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.F3:
                    wall = wall.Load() as Wall;
                    worm = worm.Load() as Worm;
                    worm.LinkToGame(this);
                    t.Abort();

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

                    break;

                case ConsoleKey.F2:
                    this.Save();
                    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;
                }
            }
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: DinaraNuriyeva/PP2
        public void Load()
        {
            worm.LinkToGame(this);

            worm = new Worm(new Point {
                x = 10, y = 10
            },
                            ConsoleColor.Green, '■');
            food = new Food(new Point {
                x = r.Next(0, 34), y = r.Next(0, 34)
            },
                            ConsoleColor.Red, '$');
            wall = new Wall(null, ConsoleColor.White, '#');
            // food.Generate();
            // worm.Generate();
            // wall.Generate();
            worm.Draw();
            wall.Draw();
            food.Draw();
        }