All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pacman.controllers.HumanController Maven / Gradle / Ivy

There is a newer version: 2.0.1.0
Show newest version
package pacman.controllers;

import pacman.game.Constants.MOVE;
import pacman.game.Game;

import java.awt.event.KeyEvent;

/*
 * Allows a human player to play the game using the arrow key of the keyboard.
 */
public class HumanController extends PacmanController {
    public KeyBoardInput input;

    public HumanController(KeyBoardInput input) {
        this.input = input;
    }

    public KeyBoardInput getKeyboardInput() {
        return input;
    }

    @Override
    public MOVE getMove(Game game, long dueTime) {
        //        System.out.println("Returned: " + input.getKey());
        switch (input.getKey()) {
            case KeyEvent.VK_UP:
                return MOVE.UP;
            case KeyEvent.VK_RIGHT:
                return MOVE.RIGHT;
            case KeyEvent.VK_DOWN:
                return MOVE.DOWN;
            case KeyEvent.VK_LEFT:
                return MOVE.LEFT;
            default:
                return MOVE.NEUTRAL;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy