package lect78_impl.controller; import java.awt.event.KeyEvent; /** * @overview Represents control mappings for a player * * @attributes * moveUp KeyCode Key for upward movement * moveDown KeyCode Key for downward movement * turnCannonLeft KeyCode Key for leftward gun barrel rotatable * turnCannonRight KeyCode Key for rightward gun barrel rotatable * fireKey KeyCode Key for firing */ public class Controls { private int moveUp; private int moveDown; private int rotateLeft; private int rotateRight; private int fireKey; /** * @effects Creates a new Controls object with specified key mappings */ public Controls(int moveUp, int moveDown, int rotateLeft, int rotateRight, int fireKey) { this.moveUp = moveUp; this.moveDown = moveDown; this.rotateLeft = rotateLeft; this.rotateRight = rotateRight; this.fireKey = fireKey; } /** * @effects Creates default controls for Player 1 (WASD + SPACE) */ public static Controls createPlayer1Controls() { return new Controls( KeyEvent.VK_W, // Up KeyEvent.VK_S, // Down KeyEvent.VK_A, // Rotate Left KeyEvent.VK_D, // Rotate Right KeyEvent.VK_SPACE // Fire ); } /** * @effects Creates default controls for Player 2 (Arrow keys + ENTER) */ public static Controls createPlayer2Controls() { return new Controls( KeyEvent.VK_UP, // Up KeyEvent.VK_DOWN, // Down KeyEvent.VK_LEFT, // Rotate Left KeyEvent.VK_RIGHT, // Rotate Right KeyEvent.VK_ENTER // Fire ); } /** * @effects Gets the move up key code */ public int getMoveUp() { return moveUp; } /** * @effects Gets the move down key code */ public int getMoveDown() { return moveDown; } /** * @effects Gets the rotate left key code */ public int getRotateLeft() { return rotateLeft; } /** * @effects Gets the rotate right key code */ public int getRotateRight() { return rotateRight; } /** * @effects Gets the fire key code */ public int getFireKey() { return fireKey; } }