Exemple #1
0
        protected async override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            switch (e.KeyCode)
            {
            case Keys.Up:
                pacman.nextDirection = 1;
                invoker.SetCommand(moveUp);
                invoker.run();
                //pacmans.Single(p => p.Id == _hubConnection.ConnectionId).MovePacman(1);
                //_signalR.SendCoordinates(pacman);
                break;

            case Keys.Right:
                pacman.nextDirection = 2;
                invoker.SetCommand(moveRight);
                invoker.run();
                //pacmans.Single(p => p.Id == _hubConnection.ConnectionId).MovePacman(2);
                //_signalR.SendCoordinates(pacman);
                break;

            case Keys.Down:
                pacman.nextDirection = 3;
                invoker.SetCommand(moveDown);
                invoker.run();
                //pacmans.Single(p => p.Id == _hubConnection.ConnectionId).MovePacman(4);
                //_signalR.SendCoordinates(pacman);
                break;

            case Keys.Left:
                pacman.nextDirection = 4;
                invoker.SetCommand(moveLeft);
                invoker.run();
                //pacmans.Single(p => p.Id == _hubConnection.ConnectionId).MovePacman(4);
                //_signalR.SendCoordinates(pacman);
                break;

            case Keys.Space:
                invoker.undo();
                break;

            case Keys.S:
                if (players.Count < 2)
                {
                    return;
                }
                ghost.EnableTimer();
                pacmans.Single(p => p.Id == _hubConnection.ConnectionId).EnableTImer();
                break;

            case Keys.P:
                if (players.Count < 2)
                {
                    return;
                }
                if (pacmans.Single(p => p.Id == _hubConnection.ConnectionId).IsTimerEnabled() && ghost.IsTimerEnabled())
                {
                    pacmans.Single(p => p.Id == _hubConnection.ConnectionId).StopTimer();
                    ghost.StopTimer();
                }
                else
                {
                    pacmans.Single(p => p.Id == _hubConnection.ConnectionId).StartTimer();
                    ghost.StartTimer();
                }
                break;

            case Keys.F1:
                // Join the game
                if (players.Count < 2)
                {
                    await _signalR.ConnectPlayer();
                }
                break;
            }
        }