public void keyPressed(KeyEvent e) {
        int x = e.getKeyCode();

        // Exit if the user hit <ESC>
        if (x == KeyEvent.VK_ESCAPE) {
            System.exit(0);
        }
        
        int prevDir = game.pacman.getDirection();

        // Movement controls
        if (x == KeyEvent.VK_LEFT) {
            game.pacman.setDirection(Directions.LEFT);
        } else if (x == KeyEvent.VK_RIGHT) {
            game.pacman.setDirection(Directions.RIGHT);
        } else if (x == KeyEvent.VK_UP) {
            game.pacman.setDirection(Directions.UP);
        } else if (x == KeyEvent.VK_DOWN) {
            game.pacman.setDirection(Directions.DOWN);
        }    
        
        //However, if Pacman is now colliding with something, revert it.
        if (game.isCollision(game.pacman)) {
            game.pacman.setDirection(prevDir);
        }
    }