nankin.zheng.gatem.controller
Class GameInputEvent

java.lang.Object
  |
  +--nankin.zheng.gatem.controller.GameInputEvent

public class GameInputEvent
extends java.lang.Object

GameInputEvent contains user input (key or mouse) information.

It is created by KeyController or MouseController, and passed to Controller, and then passed to GameInputEventListener objects that cares about user inputs.

NOTE that if it is created by KeyController, it contains keyboard input information only. And if it is created by MouseController, it contains mouse input information only.


Field Summary
static int A_KEY
           
static int B_KEY
           
static int C_KEY
           
static int D_KEY
           
static int DOWN_KEY
           
static int E_KEY
           
static int F_KEY
           
private static int FLAG_NUM
           
private  boolean[] flags
           
private static int KEY_FLAG_NUM
           
private  boolean keyInformation
           
static int LEFT_CLICK
           
static int LEFT_KEY
           
static int MIDDLE_CLICK
           
static int MOUSE_POSITION
           
static int PAUSE_KEY
           
private  Position position
           
static int RIGHT_CLICK
           
static int RIGHT_KEY
           
static int SELECT_KEY
           
static int START_KEY
           
static int UP_KEY
           
 
Constructor Summary
GameInputEvent()
          Constructor.
 
Method Summary
 void copy(GameInputEvent ievt)
          Copy both key information and mouse information of ievt to itself.
 void copyKeyPart(GameInputEvent ievt)
          Copy the key information part of ievt to itself.
 void copyMousePart(GameInputEvent ievt)
          Copy the mouse information part of ievt to itself.
 int getDirection()
          Get the direction, which is indicated by user keyboard input.
 Position getPosition()
          Get the position where mouse is clicking.
 boolean isKeyInformation()
          Which kind of information does this event contain.
 boolean isPressing(int button)
          Query whether a key or a mouse button is pressed.
 void setFlag(int index)
          Set a flag by its index, which means that a corresponding key or mouse button is pressed.
 void setKeyInformation(boolean b)
          Set its information kind.
 void setPosition(Position pos)
          Set the position where mouse is clicking.
 void unsetFlag(int index)
          Unset a flag by its index, which means that a corresponding key or mouse button is released.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT_KEY

public static final int LEFT_KEY
See Also:
Constant Field Values

RIGHT_KEY

public static final int RIGHT_KEY
See Also:
Constant Field Values

UP_KEY

public static final int UP_KEY
See Also:
Constant Field Values

DOWN_KEY

public static final int DOWN_KEY
See Also:
Constant Field Values

A_KEY

public static final int A_KEY
See Also:
Constant Field Values

B_KEY

public static final int B_KEY
See Also:
Constant Field Values

C_KEY

public static final int C_KEY
See Also:
Constant Field Values

D_KEY

public static final int D_KEY
See Also:
Constant Field Values

E_KEY

public static final int E_KEY
See Also:
Constant Field Values

F_KEY

public static final int F_KEY
See Also:
Constant Field Values

SELECT_KEY

public static final int SELECT_KEY
See Also:
Constant Field Values

START_KEY

public static final int START_KEY
See Also:
Constant Field Values

PAUSE_KEY

public static final int PAUSE_KEY
See Also:
Constant Field Values

LEFT_CLICK

public static final int LEFT_CLICK
See Also:
Constant Field Values

RIGHT_CLICK

public static final int RIGHT_CLICK
See Also:
Constant Field Values

MIDDLE_CLICK

public static final int MIDDLE_CLICK
See Also:
Constant Field Values

MOUSE_POSITION

public static final int MOUSE_POSITION
See Also:
Constant Field Values

FLAG_NUM

private static final int FLAG_NUM
See Also:
Constant Field Values

KEY_FLAG_NUM

private static final int KEY_FLAG_NUM
See Also:
Constant Field Values

keyInformation

private boolean keyInformation

flags

private boolean[] flags

position

private Position position
Constructor Detail

GameInputEvent

public GameInputEvent()
Constructor.

Method Detail

isKeyInformation

public boolean isKeyInformation()
Which kind of information does this event contain.

Returns:
true if it contains only key info. false if it contains only mouse info.

setKeyInformation

public void setKeyInformation(boolean b)
Set its information kind.

Parameters:
b - true if it contains only key info. false if it contains only mouse info.

setFlag

public void setFlag(int index)
Set a flag by its index, which means that a corresponding key or mouse button is pressed.

This method is called by Controller.

Parameters:
index - flag index.

unsetFlag

public void unsetFlag(int index)
Unset a flag by its index, which means that a corresponding key or mouse button is released.

This method is called by Controller.

Parameters:
index - flag index.

copy

public void copy(GameInputEvent ievt)
Copy both key information and mouse information of ievt to itself.

Parameters:
ievt - GameInputEvent to be copied.

copyKeyPart

public void copyKeyPart(GameInputEvent ievt)
Copy the key information part of ievt to itself.

Parameters:
ievt - GameInputEvent to be copied.

copyMousePart

public void copyMousePart(GameInputEvent ievt)
Copy the mouse information part of ievt to itself.

Parameters:
ievt - GameInputEvent to be copied.

setPosition

public void setPosition(Position pos)
Set the position where mouse is clicking.

This method is called by MouseController.

Parameters:
pos - position where mouse is clicking.

isPressing

public boolean isPressing(int button)
Query whether a key or a mouse button is pressed.

Parameters:
button - button index
Returns:
true if it is pressed, and false otherwise.

getDirection

public int getDirection()
Get the direction, which is indicated by user keyboard input. (available only if isKeyInformation().)

Returns:
direction

getPosition

public Position getPosition()
Get the position where mouse is clicking. (available only if not isKeyInformation().)

Returns:
position where mouse is clicking.