Title: GamePlayer
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

Package | Class | Use | Tree | Deprecated | Index | Help |
PREV CLASS   NEXT CLASS | FRAMES    NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

gameNet_cloneable
Class GamePlayer


java.lang.Object
  java.lang.Thread
      gameNet_cloneable.GamePlayer


All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable

public class GamePlayer
extends java.lang.Thread
implements java.io.Serializable




The GamePlayer class manages the socket connection with the GameControl.

When the GUI wants to send a message to the GameControl, the sendMessage routine is called to write the message object to an ObjectOutputStream.

When the GameControl wants to send a message to the GUI, the GamePlayer Thread will read the object from the ObjectInputStream. The GamePlayer class passes it along to the GUI by calling the receivedMessage method.

See Also:
Serialized Form

Nested Class Summary

Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler

Field Summary

Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY

Method Summary
void | doneWithGame()
boolean | GameIsAlive() GameIsAlive can be called to find out if the GamePlayer socket is still connected.
java.lang.String | getPlayerName() getPlayerName returns the name of the player associated with this connection.
void | run() The Thread that is underneath the GamePlayer class is responsible for reading the ObjectOutputStream from the GameControl.
void | sendMessage(java.lang.Object objectToSend) sendMessage provides a way to send an object to the GameControl.
void | setGameConnectionBroken(GameNet_ConnectionBrokenInterface gcb) If you want your GUI to find out when a GameControl connection is broken, your GUI must implement the Interface_ConnectionBroken interface.

Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Method Detail

getPlayerName


public java.lang.String getPlayerName()

getPlayerName returns the name of the player associated with this connection.

setGameConnectionBroken


public void setGameConnectionBroken(GameNet_ConnectionBrokenInterface gcb)

If you want your GUI to find out when a GameControl connection is broken, your GUI must implement the Interface_ConnectionBroken interface. Use setGameConnectionBroken to let GamePlayer know about this interface.

Parameters:
gcb - - an instance of the Interface_ConnectionBroken interface to be called when the Socket disconnects.

run


public void run()

The Thread that is underneath the GamePlayer class is responsible for reading the ObjectOutputStream from the GameControl. Every MyGameOutput read from the ObjectOutputStream is passed on by calling the receivedMessage routine. Your Networked Game should not be accessing the run routine directly. It has to be public to properly run as a thread.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

GameIsAlive


public boolean GameIsAlive()

GameIsAlive can be called to find out if the GamePlayer socket is still connected.

Returns:
true if socket is still alive

doneWithGame


public void doneWithGame()

sendMessage


public void sendMessage(java.lang.Object objectToSend)

sendMessage provides a way to send an object to the GameControl.

Parameters:
objectToSend - to pass to the GameControl.

Package | Class | Use | Tree | Deprecated | Index | Help |
PREV CLASS   NEXT CLASS | FRAMES    NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD