|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfourwin.BrickConnection
public class BrickConnection
Establishes a connection with a remote computer using bluetooth or USB. The connection is used to send messages to the computer including moves and status data and to receive commands from the computer.
To connect a pc the waitForConnection() method has to be called. The robot waits then for the remote computer to initiate the connection. Waiting blocks the application until the connection is established.
Remark that bluetooth has to be turned on and the brick has to be visible for other bluetooth devices.
Integer values are used to transmit data. So a code is introduced to allocate an integer to its meaning. See contants defined in that class.
Field Summary | |
---|---|
private int |
CodeOffset
|
(package private) NXTConnector |
connection
Connection handle |
private int |
DUMMY
|
private int |
GAME_START
|
(package private) DataInputStream |
inStream
Stream for receiving data |
private boolean |
isConnected
Saves if a connection is already established |
private int |
KIlevel
|
private int |
MOVE_PLAYER_ONE
|
private int |
MOVE_PLAYER_TWO
|
private int |
NEW_BEGINNER
|
private int |
NEW_DIFFICULTY
|
(package private) DataOutputStream |
outStream
Stream for outputting data |
private int |
PCS_TURN
|
private FourPlayer |
player
|
private int |
RESET
|
private boolean |
useBluetooth
Determeines whether to use bluetooth. |
Constructor Summary | |
---|---|
BrickConnection(boolean useBluetooth)
Returns an object which represents one connection to a remote PC. |
Method Summary | |
---|---|
boolean |
Connect()
Waits for the remote PC to initiate the connection. |
void |
Disconnect()
Uses the leJOS close() methods to disconnect from 4RowBot. |
boolean |
isConnected()
|
void |
processInput(PlayingField board,
FourGUI gui)
This method is used to receive messages from the brick. |
void |
SendDummy()
Can be used to send a dummy message which is always ignored. |
void |
SendGameReset(FourGUI gui)
Sends the game reset message to the brick. |
void |
SendGameStart()
Is used to send the game-start message to the brick. |
void |
SendMove(byte column)
Sends a move command to the Brick. |
void |
SendNewBeginner(int beginnerCode)
Is used to notify the brick about a new beginner. |
void |
SendNewDifficulty(int newDifficulty)
Is used to notify the brick about a new difficulty. |
void |
setAIlevel(int level)
Is used to set the new AI level if the difficulty changes. |
void |
useBluetooth(boolean useBluetooth)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private boolean useBluetooth
private boolean isConnected
NXTConnector connection
DataOutputStream outStream
DataInputStream inStream
private final int CodeOffset
private final int RESET
private final int MOVE_PLAYER_ONE
private final int MOVE_PLAYER_TWO
private final int GAME_START
private final int NEW_DIFFICULTY
private final int NEW_BEGINNER
private final int PCS_TURN
private final int DUMMY
private int KIlevel
private FourPlayer player
Constructor Detail |
---|
public BrickConnection(boolean useBluetooth)
useBluetooth
- Determines whether to use bluetooth (true) or USB (false)Method Detail |
---|
public boolean isConnected()
public void useBluetooth(boolean useBluetooth)
useBluetooth
- Determines whether to use bluetooth (true) or USB (false)public boolean Connect()
public void Disconnect()
public void SendMove(byte column)
column
- column in which 4RowBot should insert its chip.public void SendGameReset(FourGUI gui)
gui
- GUI-object. Is used to call the repaint method after the playing field has been emptied.public void SendDummy()
public void SendGameStart()
public void SendNewDifficulty(int newDifficulty)
newDifficulty
- Numerical value for the new Difficultypublic void SendNewBeginner(int beginnerCode)
beginnerCode
- Code of the new beginner.public void processInput(PlayingField board, FourGUI gui)
board
- To the gui attached playing field objectgui
- GUI-object, needed to change settingspublic void setAIlevel(int level)
level
- new level for the artificial intelligence
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |