|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectLectureGame.Core.NetworkManager
public class NetworkManager
Created by IntelliJ IDEA. User: olekrst Date: 26.jan.2007 Time: 13:05:41 The nerver center of the server. This class handles the responses from both StudentClients and the Masterclient. Uses the DataBase LectureGame.DataBase package for database connectivity, and GameMode interface for selecting GameMode.
GameMode
,
StudentClient
,
MasterClient
,
NetworkConnectionKeeper
Field Summary | |
---|---|
private NetworkConnectionKeeper |
connectionKeeper
|
private java.util.Vector<StudentClient> |
connections
|
private Question |
currentQuestion
|
private DataBaseConnection |
db
|
private GameMode |
gameMode
|
private MasterClient |
master
|
private int |
roundIndex
|
private int[] |
roundList
|
private boolean |
serverIsAlive
|
private int |
serverState
|
private java.net.ServerSocket |
socketListener
|
private int |
totalNumberOfQuestions
|
private int |
totalPossibleScore
|
Constructor Summary | |
---|---|
NetworkManager()
Constructor of the NetworkManager class. |
Method Summary | |
---|---|
private void |
action()
This method performs actions on the connected clients and on the GameMode according to the state its in. |
int |
checkAns(java.lang.String answer,
StudentClient c)
Checks the answer using handeling code in the class implementing the GameMode interface |
private boolean |
currentRoundIsLastRound()
Performs check to see if the current round is the last round in a lecture |
java.lang.String |
generateANS(int roundScore,
int totalScore)
Generates a string to be sent to the clients |
int |
getCurrentRound()
Returns which round is the current round |
int |
getTotalNumberOfQuestions()
Method used for controlling how many questions a round contains |
private java.lang.String |
handleEndOfRound()
Handles the end of a round, building the end of round string to be sendt to the MasterClient |
void |
listenForMasterClient()
Starts a new MasterClient thread. |
private void |
makeClientsDie()
|
private boolean |
nextRound()
Sets the next round and loads the questions in it. or if the current round is the final one in the lecture then the serverstate END OF LECTURE is set. |
private void |
resetStatistics()
|
void |
run()
Contains main loop which queries the connections for input data according to the server state. |
private void |
setGameMode(int gamemode)
This is where the GameMode is set according to the GameMode code registered in the database in the round table. |
void |
setLecture(int lectureID)
Sets tje lecture id where the rounds are to be extracted from |
void |
setState(int state)
Sets the server state. |
void |
stop()
Stops the networkmanager and closes all connections. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private NetworkConnectionKeeper connectionKeeper
private int serverState
private Question currentQuestion
private int[] roundList
private DataBaseConnection db
private int roundIndex
private int totalNumberOfQuestions
private int totalPossibleScore
private GameMode gameMode
private java.util.Vector<StudentClient> connections
private MasterClient master
private java.net.ServerSocket socketListener
private boolean serverIsAlive
Constructor Detail |
---|
public NetworkManager()
Method Detail |
---|
public void listenForMasterClient()
MasterClient
public void run()
run
in interface java.lang.Runnable
private void action()
private void resetStatistics()
private void makeClientsDie()
public void setState(int state)
state
- LG
public int checkAns(java.lang.String answer, StudentClient c)
answer
- the answer from the client, a string representing an integerc
- the client which answered
public int getTotalNumberOfQuestions()
public java.lang.String generateANS(int roundScore, int totalScore)
roundScore
- score acheived in this roundtotalScore
- total score accumulated
private void setGameMode(int gamemode) throws IllegalGameModeException
gamemode
-
IllegalGameModeException
public int getCurrentRound()
public void setLecture(int lectureID)
lectureID
- the lectureID to be usedpublic void stop()
private boolean nextRound()
private java.lang.String handleEndOfRound()
private boolean currentRoundIsLastRound()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |