Class GameServer

java.lang.Object
  extended by java.lang.Thread
      extended by GameServer
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
OthelloServer

public abstract class GameServer
extends java.lang.Thread

This static side of this class is the Server side Application for a client/server Othello Game. Objects of this class are also used to communicate to individual threads via multithreading.

Author:
Adam Hauer Stony Brook University

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
 
Constructor Summary
GameServer(java.net.Socket initConnection, int initPlayerNumber)
          This constructor initializes the server by setting up all Object I/O to be used to communicate back and forth with this client.
 
Method Summary
 void assignColors()
          Assigns colors to the two opponents.
 boolean createProfile()
          Creates a user profile so the user can now have access to the server and play 2player games
 boolean findOpponent()
          Finds an opponent for this player and sets this player as the opponent of another player
 int getBoardReference()
           
 GameServer getOpponent()
           
 int getPlayerNumber()
           
 boolean login()
          Allows users who connect to log in to the server.
abstract  void modifyScore()
          Compares the winner of the game with the player's playerNumber, then modifies the stats of the player.
 void resetStats()
          Resets the stats of the player in the current game(Wins, Losses, Ties)
abstract  void restartGame()
          This method restarts a game either after a draw or after a player has won.
 boolean saveProfile()
          Method used to save the current profile in a file on the server.
 void selectGame()
          User selects a game.
 void sendNetworkObject(GameNetworkObject tttno)
          This method is used to send a message to the client handled by this thread.
 void setBoardReference(int newRef)
           
 void setColor(int color)
          Manually assigns a color to the player
 void setOpponent(GameServer newOpponent)
          Sets an opponent for this player
 void setPlayerNumber(int pn)
          Changes the players number
 
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, run, 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
 

Constructor Detail

GameServer

public GameServer(java.net.Socket initConnection,
                  int initPlayerNumber)
This constructor initializes the server by setting up all Object I/O to be used to communicate back and forth with this client.

Parameters:
initConnection - - socket that is connected to a client
initPlayerNumber - - represents the player number for the client that will be communicated with by this thread.
Method Detail

restartGame

public abstract void restartGame()
This method restarts a game either after a draw or after a player has won.


setPlayerNumber

public void setPlayerNumber(int pn)
Changes the players number

Parameters:
pn - - integer containing the player's new number

getPlayerNumber

public int getPlayerNumber()
Returns:
- The player number

assignColors

public void assignColors()
Assigns colors to the two opponents. Uses the setColor method for the other opponent


setColor

public void setColor(int color)
Manually assigns a color to the player

Parameters:
color -

modifyScore

public abstract void modifyScore()
Compares the winner of the game with the player's playerNumber, then modifies the stats of the player.

Parameters:
winner - - the player that won the game

getOpponent

public GameServer getOpponent()
Returns:
- the opponent(OthelloServer)

setOpponent

public void setOpponent(GameServer newOpponent)
Sets an opponent for this player


findOpponent

public boolean findOpponent()
Finds an opponent for this player and sets this player as the opponent of another player

Returns:
- True or False depending on whether an opponent has been found

resetStats

public void resetStats()
Resets the stats of the player in the current game(Wins, Losses, Ties)


sendNetworkObject

public void sendNetworkObject(GameNetworkObject tttno)
This method is used to send a message to the client handled by this thread.

Parameters:
tttno - - the network packet to be sent to the client handled by this thread.

saveProfile

public boolean saveProfile()
Method used to save the current profile in a file on the server. The file contains a list of all the user profiles.

Returns:
- returns true if successful, false if not

login

public boolean login()
Allows users who connect to log in to the server. Users must login with corrent user name and password. If they do not have, they should be asked to create a profile.

Returns:
- returns true if user entered correct info, false if not

selectGame

public void selectGame()
User selects a game. This game is represented by a number stored in gameType. These numbers should be specifically defined for each game.


createProfile

public boolean createProfile()
Creates a user profile so the user can now have access to the server and play 2player games

Returns:
- returns true if successful in creating a profile, false if unsuccessful

getBoardReference

public int getBoardReference()
Returns:
- The integer for the board number reference in the ArrayList

setBoardReference

public void setBoardReference(int newRef)