Exemple #1
0
        public void Process(ConsoleKeyInfo pressedButton)
        {
            switch (pressedButton.Key)
            {
            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:
                Console.Clear();
                Menu menu = new Menu();
                menu.Process();
                Console.ReadKey();
                break;

            case ConsoleKey.F2:
                worm.Save();
                food.Save();
                break;

            case ConsoleKey.F1:
                worm = worm.Load() as Worm;
                food = food.Load() as Food;
                break;
            }
        }
Exemple #2
0
        public Game()
        {
            gameLevel = GameLevel.First;
            worm      = new Worm(new Point {
                X = 10, Y = 10
            },
                                 ConsoleColor.White, '*');
            food = new Food(new Point {
                X = 20, Y = 10
            },
                            ConsoleColor.White, '+');
            wall = new Wall(null, ConsoleColor.White, '#');



            g_objects.Add(worm);
            g_objects.Add(food);
            g_objects.Add(wall);
            LoadLvl(k);
            // Lvl();
        }
Exemple #3
0
        public void Process(ConsoleKeyInfo pressedButton)
        {
            switch (pressedButton.Key)
            {
            case ConsoleKey.UpArrow:
            case ConsoleKey.DownArrow:
            case ConsoleKey.LeftArrow:
            case ConsoleKey.RightArrow:
                worm.ChangeDir(pressedButton);
                break;

            case ConsoleKey.Escape:
                Console.Clear();
                t.Abort();
                isAlive = false;
                break;

            case ConsoleKey.F2:
                worm.Save();
                food.Save();
                break;

            case ConsoleKey.F1:
                t.Abort();
                ThreadStart ts = new ThreadStart(Draw);
                t = new Thread(ts);
                t.Start();
                worm = worm.Load() as Worm;
                food = food.Load() as Food;
                g_objects.Clear();
                g_objects.Add(worm);
                g_objects.Add(food);
                g_objects.Add(wall);
                Console.Clear();
                break;
            }
        }