lecturequiz.server.gamemodes
Class AbstractGameMode

java.lang.Object
  extended by lecturequiz.server.gamemodes.AbstractGameMode
Direct Known Subclasses:
PlainGame

public abstract class AbstractGameMode
extends java.lang.Object


Field Summary
protected  boolean canJoinStarted
           
protected  Question currentQuestion
           
protected  int currentQuestionIndex
           
protected  java.lang.String id
           
protected  java.lang.String name
           
protected  User owner
           
protected  java.util.ArrayList<User> players
           
protected  java.util.Date questionStartTime
           
protected  Quiz quiz
           
protected  java.lang.String quizCode
           
protected  boolean quizHasEnded
           
protected  boolean started
           
 
Constructor Summary
AbstractGameMode(Quiz quiz, java.lang.String quizCode)
          Constructor.
 
Method Summary
 boolean canJoinStarted()
          Tells if a client can join this game mode if the first question has already started.
 Question getCurrentQuestion()
          Returns the current question in the quiz.
 GameStatus getGameStatus()
          Get the current status of this game, such as players in game, number of teams, what question we are on etc.
 java.lang.String getId()
          Returns the game mode ID of the game mode that runs on this game.
 java.lang.String getName()
          Returns the game mode name of the game mode that runs on this game
 int getNumberOfPlayers()
          Returns the number of current players that have joined this game.
abstract  java.util.ArrayList<StatisticsEntry> getOverallStatistics()
          Returns the overall statistics for the entire game for all users.
abstract  java.util.ArrayList<StatisticsEntry> getOverallStatistics(User user)
          Returns the overall statistics for the entire game for a specified user.
 User getOwner()
          Return the owner of this game
 java.util.ArrayList<User> getPlayers()
          Returns the list of players in this game
abstract  java.util.ArrayList<StatisticsEntry> getQuestionStatistics()
          Returns the combined statistics for all users of this game
abstract  java.util.ArrayList<StatisticsEntry> getQuestionStatistics(User user)
          Returns the statistics for the last question for the requested user.
 java.lang.String getQuizCode()
          Returns the quiz code for this game.
 int getTimeLeft()
          Returns the time left before the question should change.
 boolean hasQuestionTimedOut()
          Checks if the current question running has reached the time limit set by the question.
 boolean hasQuizEnded()
          Tells if the quiz has ended and the last question has been answered
 boolean isStarted()
          Check if the game is started.
 int joinGame(User player, java.util.List<ParameterEntry> parameters)
          Tries add a player to the game.
abstract  int receiveAnswer(int answerID, User player)
          Receives an answer from a player and registers it.
 void removeUser(User user)
          Remove a user from the game
 void setOwner(User user)
          Set the owner of this game
 boolean setParameters(java.util.List<ParameterEntry> parameters)
          Sets the custom parameters for this game mode.
abstract  boolean startNextQuestion()
          Starts the next question in the quiz
 void startQuiz()
          Starts the quiz.
protected  boolean timeoutReached()
          Simple function to determine if the time limit of a question has been reached
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected java.lang.String id

name

protected java.lang.String name

quizCode

protected java.lang.String quizCode

owner

protected User owner

players

protected java.util.ArrayList<User> players

quiz

protected Quiz quiz

canJoinStarted

protected boolean canJoinStarted

currentQuestion

protected Question currentQuestion

currentQuestionIndex

protected int currentQuestionIndex

questionStartTime

protected java.util.Date questionStartTime

quizHasEnded

protected boolean quizHasEnded

started

protected boolean started
Constructor Detail

AbstractGameMode

public AbstractGameMode(Quiz quiz,
                        java.lang.String quizCode)
Constructor. Sets the quiz and quiz code members and initializes the players array. Also sets the quizHasEnded member to false.

Parameters:
quiz - Quiz the game will use.
quizCode - Quiz code of the game.
Method Detail

getId

public java.lang.String getId()
Returns the game mode ID of the game mode that runs on this game.

Returns:
ID of the game mode

getName

public java.lang.String getName()
Returns the game mode name of the game mode that runs on this game

Returns:
Name of the game mode

getQuizCode

public java.lang.String getQuizCode()
Returns the quiz code for this game.

Returns:
The quiz code for this game.

joinGame

public int joinGame(User player,
                    java.util.List<ParameterEntry> parameters)
Tries add a player to the game.

Parameters:
player - The player to add.
parameters - Custom parameters from the client
Returns:
Error codes:
0 - Success
1 - User already in the game
2 - Join denied

isStarted

public boolean isStarted()
Check if the game is started.

Returns:
True if the game is started, false otherwise.

getPlayers

public java.util.ArrayList<User> getPlayers()
Returns the list of players in this game

Returns:
List of all players in the game

getNumberOfPlayers

public int getNumberOfPlayers()
Returns the number of current players that have joined this game.

Returns:
Number of players in the game.

startQuiz

public void startQuiz()
Starts the quiz. Also starts the first question. This will mark the quiz as started.


getCurrentQuestion

public Question getCurrentQuestion()
Returns the current question in the quiz. Should only return a question that is actually running.

Returns:
The current question or null if there are no current question.

startNextQuestion

public abstract boolean startNextQuestion()
Starts the next question in the quiz

Returns:
True for success, false if no more questions are vailable

getQuestionStatistics

public abstract java.util.ArrayList<StatisticsEntry> getQuestionStatistics()
Returns the combined statistics for all users of this game

Returns:
A list of statistics entries, or null if statistics cannot be returned a this point

getQuestionStatistics

public abstract java.util.ArrayList<StatisticsEntry> getQuestionStatistics(User user)
Returns the statistics for the last question for the requested user.

Parameters:
user - User to get statistics for, pass null for general statistics.
Returns:
A list of statistics entries, or null if statistics cannot be returned a this point

getOverallStatistics

public abstract java.util.ArrayList<StatisticsEntry> getOverallStatistics()
Returns the overall statistics for the entire game for all users.

Returns:
A list of statistics entries or null if the game is not over.

getOverallStatistics

public abstract java.util.ArrayList<StatisticsEntry> getOverallStatistics(User user)
Returns the overall statistics for the entire game for a specified user.

Parameters:
user - The user to get statistics for
Returns:
A list of statistics entries or null if the game is not over.

hasQuestionTimedOut

public boolean hasQuestionTimedOut()
Checks if the current question running has reached the time limit set by the question.

Returns:
True if the timelimit has been reached, false otherwise. If the first \ question has not been started, it also returns true.

canJoinStarted

public boolean canJoinStarted()
Tells if a client can join this game mode if the first question has already started.

Returns:
True if a client can join, false if otherwise.

receiveAnswer

public abstract int receiveAnswer(int answerID,
                                  User player)
Receives an answer from a player and registers it. Does not check if the answer is correct

Parameters:
answerID -
player -
Returns:
Error codes:
0 - Success
1 - Invalid answer
2 - Player has already answered
3 - Question timeout is reached

setOwner

public void setOwner(User user)
Set the owner of this game

Parameters:
user - the user to set as owner

getOwner

public User getOwner()
Return the owner of this game

Returns:
the game owner

removeUser

public void removeUser(User user)
Remove a user from the game

Parameters:
user - user to remove

hasQuizEnded

public boolean hasQuizEnded()
Tells if the quiz has ended and the last question has been answered

Returns:
True if the quiz has ended, false if not

getGameStatus

public GameStatus getGameStatus()
Get the current status of this game, such as players in game, number of teams, what question we are on etc.

Returns:
A GameStatus object with the status of this game

setParameters

public boolean setParameters(java.util.List<ParameterEntry> parameters)
Sets the custom parameters for this game mode. Is usually called on game creation. The default implenetation ignores these parameters.

Parameters:
parameters - The custom parameters from the teacher client who created the game.
Returns:
True if the parameters are valid and accepted, false otherwise.

getTimeLeft

public int getTimeLeft()
Returns the time left before the question should change. Will return 0 if there is no current question

Returns:
the time left in seconds

timeoutReached

protected boolean timeoutReached()
Simple function to determine if the time limit of a question has been reached

Returns:
True if the time limit has been reached, false otherwise. Will return true if there is no current question.