|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
Tracksail
Class Tracksail implements the client program of Tracksail.
When the program is started, the user is asked for the player name and host
machine. A connection to the host is attempted an if the attempt is
successful, we get a server object that implements the
ServerInterface. Any calls to the server are done via this
interface.
If the connection and permission are received, the client program is
initialised and a Swing-based GUI is constructed with a JFrame
frame as it's root.
After the program has been started, there are two main states: lobby and race. Depending on the current state, the frame shows either a lobby room or a race room.
- In lobby room we have a largish chat-box in the middle. At the bottom, we have a text field where a message can be written. The message can be sent either by pressing return or by clicking on the 'Say'-button. On the right-hand side there is a race panel, which has a list of the current races, buttons to join an existing race or create a new race and a text field where a name for the race to create is written.
- In race room we have a large sea-view (render_view),
where all the race graphics are drawn. At the bottom, there are '<-' and
'->' buttons, with which the player can turn his/her boat, and a slider
that controls the sail. Under these we have a text field and a 'Say'
button, which work as they do in the lobby. In the race room, chat messages
are shown in the render_view area, instead of a separate chat
area, and only a few of the latest messages are shown at a time.
Tracksail implements the ClientInterface, which is
an interface for making method calls from the server to the clients. This
client interface object is sent to the server during the intialisation of the
connection as one parameter in the server call (see login()).
ClientInterface,
Player,
Game,
Server,
Track,
Serialized Form| Nested Class Summary | |
(package private) class |
Tracksail.ChangeTrackItemListener
Handles the changes of the choice in the track list. |
(package private) class |
Tracksail.CreateGameActionListener
Handles clicking the 'create game' button. |
(package private) class |
Tracksail.ExitActionListener
Handles clicking the 'Exit' button. |
(package private) class |
Tracksail.JoinGameActionListener
Handles clicking the 'join game' button. |
(package private) class |
Tracksail.JRenderView
Custom GUI component, a drawing area on which all graphics of the game are drawn. |
(package private) class |
Tracksail.SailChangeListener
Handles changes in the slider controlling the sail. |
(package private) class |
Tracksail.SayItActionListener
Handles events that are generated when the player clicks the 'say' button or hits enter with focus in the chat input text area. |
(package private) class |
Tracksail.StartGameActionListener
Handles clicking the 'start game' in a race. |
(package private) class |
Tracksail.TurnLeftAction
Handles clicking the '<' button. |
(package private) class |
Tracksail.TurnRightAction
Handles clicking the '>' button. |
class |
Tracksail.WindowCloser
Handles events that are generated when the player closes the window. |
| Field Summary | |
(package private) boolean |
active
Tells if we're still executing the program. |
(package private) javax.swing.JTextArea |
chat_messages
Multiline text area where chat messages are output to |
(package private) javax.swing.JScrollPane |
chat_scroll
This makes the text area to scroll up so only the latest messages are seen at the bottom |
private java.util.ArrayList |
chat_text
The latest chat messages. |
(package private) javax.swing.JButton |
create_game_button
Button to create a new race |
(package private) javax.swing.JButton |
exit_button
Button to leave the program if we're at the lobby room. |
protected javax.swing.JFrame |
frame
Main window |
(package private) Game |
game
Current state of the race (if we are in one) |
private int |
game_id
Unique id of the race the player is in (if we are in one) |
(package private) javax.swing.JList |
game_list
List of the races available |
(package private) GameListModel |
game_list_model
Model for the race list |
(package private) javax.swing.JTextField |
game_name_text
Text field for the name of a new race |
private java.lang.String |
host_name
Name of the host |
(package private) javax.swing.JTextField |
info_text
Uneditable text field for the program to write information to |
(package private) boolean |
is_lobby
Are we in a lobby room or in a race room? True means we're in a lobby, false means we're in a race |
private boolean |
is_master
Is this player the master of the current race? |
(package private) javax.swing.JButton |
join_button
Button to join a race |
(package private) javax.swing.JPanel |
lobby_panel
Panel that's visible when in lobby room |
(package private) javax.swing.JPanel |
main_panel
Main panel where all other content is placed |
private int |
player_id
Player's unique id |
private java.lang.String |
player_name
Player name |
(package private) javax.swing.JPanel |
race_panel
This is the panel that's visible when we're racing |
(package private) Tracksail.JRenderView |
render_view
Racing view. |
(package private) javax.swing.JSlider |
sail_slider
Slider to set the sail control rope tightness |
(package private) javax.swing.JButton |
say_it
Button that sends a chat message from this player |
(package private) javax.swing.JTextField |
say_text
Text field for the player to write chat messages to |
(package private) javax.swing.JButton |
start_button
Button to start the race |
(package private) javax.swing.JComboBox |
track_list
List to change the track |
(package private) TrackListModel |
track_list_model
Model for the track list |
(package private) ServerInterface |
ts_server
An interface used to call the remote methods of the server |
(package private) javax.swing.JButton |
turn_left_button
Button to turn the boat portboard |
(package private) javax.swing.JButton |
turn_right_button
Button to turn the boat starboard |
static java.lang.String |
version
|
| Fields inherited from class java.rmi.server.UnicastRemoteObject |
|
| Fields inherited from class java.rmi.server.RemoteServer |
|
| Fields inherited from class java.rmi.server.RemoteObject |
ref |
| Constructor Summary | |
Tracksail()
Constructor. |
|
| Method Summary | |
void |
connect()
Establishes a RMI connection to the server. |
void |
createGUI()
This method constructs the client GUI. |
java.awt.image.BufferedImage[] |
createRotatedImages(java.lang.String filename,
int num_images)
Creates a rotated image series. |
void |
error(java.lang.String str)
Common error handler. |
void |
game_loop()
Game loop. |
void |
gameStateChange(boolean racing)
The server tells the player the state of the race when it changes (racing/paused). |
java.awt.image.BufferedImage |
getBufferedImage(java.lang.String filename)
Loads an image from a file. |
void |
init()
Initialize program. |
void |
kick(java.lang.String message)
Kicks out a player. |
static void |
main(java.lang.String[] args)
This is where the execution begins. |
void |
sendText(java.lang.String str)
Sends a message to the client. |
void |
switchToGame()
Changes from lobby state to racing state. |
void |
switchToLobby()
Changes from racing state to lobby state. |
void |
uninit()
Logs a player out from the server. |
void |
updateGameList(GameInfo[] ri)
Send an updated race list from the server to the client. |
void |
updateTrackList(java.lang.String[] tracks)
Send an updated track list from the server to the client. |
| Methods inherited from class java.rmi.server.UnicastRemoteObject |
clone, exportObject, exportObject, exportObject, unexportObject |
| Methods inherited from class java.rmi.server.RemoteServer |
getClientHost, getLog, setLog |
| Methods inherited from class java.rmi.server.RemoteObject |
equals, getRef, hashCode, toString, toStub |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final java.lang.String version
private java.lang.String host_name
private java.lang.String player_name
private int player_id
private int game_id
Game game
private boolean is_master
protected javax.swing.JFrame frame
boolean is_lobby
boolean active
private java.util.ArrayList chat_text
ServerInterface ts_server
javax.swing.JPanel lobby_panel
javax.swing.JTextField info_text
javax.swing.JTextArea chat_messages
javax.swing.JTextField say_text
javax.swing.JButton say_it
javax.swing.JList game_list
javax.swing.JButton join_button
javax.swing.JButton create_game_button
javax.swing.JTextField game_name_text
GameListModel game_list_model
javax.swing.JButton exit_button
javax.swing.JScrollPane chat_scroll
javax.swing.JPanel race_panel
Tracksail.JRenderView render_view
javax.swing.JButton start_button
javax.swing.JComboBox track_list
TrackListModel track_list_model
javax.swing.JButton turn_left_button
javax.swing.JButton turn_right_button
javax.swing.JSlider sail_slider
javax.swing.JPanel main_panel
| Constructor Detail |
public Tracksail()
throws java.rmi.RemoteException
| Method Detail |
public static void main(java.lang.String[] args)
args - command line parameters
public void init()
throws java.lang.Exception
Show startup dialog, construct the GUI and connect to a server.
java.lang.Exception
public void connect()
throws java.lang.Exception
java.lang.Exceptionpublic void uninit()
public void error(java.lang.String str)
Prints out the error message and exits the program (force exit).
str - error messagepublic void createGUI()
public void switchToGame()
public void switchToLobby()
public void game_loop()
public java.awt.image.BufferedImage getBufferedImage(java.lang.String filename)
Waits until the image is fully loaded before returning it as an image object.
filename - name of the image file to load
public java.awt.image.BufferedImage[] createRotatedImages(java.lang.String filename,
int num_images)
E.g. if an image series contains 36 images, we create 36 images out of the original image, of which the first one is rotated by 0 degrees, next by 10, then by 20 and so on. When done, the series has images to rotate the original by full 360 degrees.
filename - name of the image file to generate the series fromnum_images - how many images the series is to contain
public void sendText(java.lang.String str)
throws java.rmi.RemoteException
sendText in interface ClientInterfacestr - message
java.rmi.RemoteException
public void kick(java.lang.String message)
throws java.rmi.RemoteException
kick in interface ClientInterfacemessage - informational message printed to the console
java.rmi.RemoteException
public void updateGameList(GameInfo[] ri)
throws java.rmi.RemoteException
This is called for all players if a new race is created or an existing race is closed. This is also always called for a player when (s)he signs in to the server.
updateGameList in interface ClientInterfaceri - the race list to give
java.rmi.RemoteException
public void updateTrackList(java.lang.String[] tracks)
throws java.rmi.RemoteException
This is called for all players always when the track list changes. This is also always called for a player when (s)he signs in to the server.
updateTrackList in interface ClientInterfacetracks - the track list to give
java.rmi.RemoteException
public void gameStateChange(boolean racing)
throws java.rmi.RemoteException
So the server calls this e.g. when a race begins or ends.
gameStateChange in interface ClientInterfaceracing - true if the race begun, false if it ended.
java.rmi.RemoteException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||