Esempio n. 1
0
        public override void OnKeyPressed(object sender, ConsoleKeyPressedEventArgs e)
        {
            updateStateWaitHandler.WaitOne();

            bool update = false;

            switch (e.ConsoleKey)
            {
            case ConsoleKey.LeftArrow:
                update = _currentFallingObject.TryShift(Direction.Letf);
                break;

            case ConsoleKey.RightArrow:
                update = _currentFallingObject.TryShift(Direction.Right);
                break;

            case ConsoleKey.UpArrow:
                update = _currentFallingObject.TryRotateAroundCenter();
                break;

            case ConsoleKey.DownArrow:
                update = _currentFallingObject.TryShift(Direction.Down);
                break;
            }

            updateStateWaitHandler.Set();

            if (update)
            {
                UpdateConsole();
            }
        }
Esempio n. 2
0
        public override void OnKeyPressed(object sender, ConsoleKeyPressedEventArgs e)
        {
            bool update = false;

            updateStateWaitHandler.WaitOne();
            switch (e.ConsoleKey)
            {
            case ConsoleKey.LeftArrow:
                update = Hero.TryShift(Direction.Letf);
                break;

            case ConsoleKey.RightArrow:
                update = Hero.TryShift(Direction.Right);
                break;

            case ConsoleKey.UpArrow:
                update = Hero.TryShift(Direction.Up);
                break;

            case ConsoleKey.DownArrow:
                update = Hero.TryShift(Direction.Down);
                break;

            case ConsoleKey.Enter:
                update = true;
                Hero.Shoot();
                break;
            }

            updateStateWaitHandler.Set();

            if (update)
            {
                UpdateConsole();
            }
        }