Exemplo n.º 1
0
        public void KeyDown(TetrisCommand command)
        {
            if (_tetris != null && !_tetris.IsPaused)
            {
                //If the current command has a corresponding timer and it is already active, than don't do anything
                if (_timers.ContainsKey(command) && _timers[command].IsEnabled) return;

                #region Check all known commands
                    switch (command)
                    {
                        case TetrisCommand.ROTATE:
                            Settings.Instance.SoundPlayer.PlayResourceFile(new Uri("Tetris;component/Sounds/Effects/rotate.wav", UriKind.Relative));
                            _tetris.Rotate();
                            break;
                        case TetrisCommand.DOWN:
                            _tetris.MoveDown(this);
                            break;
                        case TetrisCommand.LEFT:
                            Settings.Instance.SoundPlayer.PlayResourceFile(new Uri("Tetris;component/Sounds/Effects/move.wav", UriKind.Relative));
                            _tetris.MoveLeft();
                            break;
                        case TetrisCommand.RIGHT:
                            Settings.Instance.SoundPlayer.PlayResourceFile(new Uri("Tetris;component/Sounds/Effects/move.wav", UriKind.Relative));
                            _tetris.MoveRight();
                            break;
                        case TetrisCommand.PAUSE:
                            _tetris.PauseGame();
                            break;
                        default:
                            break;
                    }
                #endregion

                //If the current command has a timer and it was executed, start the timer
                if (_timers.ContainsKey(command)) _timers[command].Start();
            }
        }
Exemplo n.º 2
0
        public void KeyUp(TetrisCommand command)
        {
            if (_timers.ContainsKey(command)) _timers[command].Stop();

            _tetris.ResetSoftDrop();
        }
Exemplo n.º 3
0
        private void EnqueueCommand(TetrisCommand command)
        {
            // добавляем в другом потоке, т.к. при добавлении в основном потоке потом в процессе обработки можем вернуться к нему обратно и зависнуть в ожидании // см. Pack()

            Task.Run(() => Commands.Enqueue(command));
        }
Exemplo n.º 4
0
 public KeySetting(Key key, TetrisCommand command)
 {
     Key = key;
     Command = command;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Only real tetris commands reach this method.
 /// </summary>
 public void Game_KeyUp(TetrisCommand command)
 {
     _controller.KeyUp(command);
 }