lecturequiz.server.gamemodes
Class PlainGame

java.lang.Object
  extended by lecturequiz.server.gamemodes.AbstractGameMode
      extended by lecturequiz.server.gamemodes.PlainGame

public class PlainGame
extends AbstractGameMode


Field Summary
protected  java.util.HashMap<User,java.lang.Integer> currentAnswers
           
protected  java.util.ArrayList<java.util.HashMap<User,java.lang.Integer>> statistics
           
 
Fields inherited from class lecturequiz.server.gamemodes.AbstractGameMode
canJoinStarted, currentQuestion, currentQuestionIndex, id, name, owner, players, questionStartTime, quiz, quizCode, quizHasEnded, started
 
Constructor Summary
PlainGame(Quiz quiz, java.lang.String quizCode)
          Constructor.
 
Method Summary
 java.util.ArrayList<StatisticsEntry> getOverallStatistics()
          Returns the overall statistics for the entire game.
 java.util.ArrayList<StatisticsEntry> getOverallStatistics(User user)
          Returns the overall statistics for the entire game for a specified user.
 java.util.ArrayList<StatisticsEntry> getQuestionStatistics()
          Returns the statistics for the last question for the all the users in the quiz.
 java.util.ArrayList<StatisticsEntry> getQuestionStatistics(User user)
          Returns the statistics for the last question for the requested user.
 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
 boolean startNextQuestion()
          Starts the next question in the quiz
 void startQuiz()
          Starts the quiz.
 
Methods inherited from class lecturequiz.server.gamemodes.AbstractGameMode
canJoinStarted, getCurrentQuestion, getGameStatus, getId, getName, getNumberOfPlayers, getOwner, getPlayers, getQuizCode, getTimeLeft, hasQuestionTimedOut, hasQuizEnded, isStarted, joinGame, setOwner, setParameters, timeoutReached
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentAnswers

protected java.util.HashMap<User,java.lang.Integer> currentAnswers

statistics

protected java.util.ArrayList<java.util.HashMap<User,java.lang.Integer>> statistics
Constructor Detail

PlainGame

public PlainGame(Quiz quiz,
                 java.lang.String quizCode)
Constructor. Calls the AbstractGameMode constructor and sets the id and name of this game mode.

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

startQuiz

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

Overrides:
startQuiz in class AbstractGameMode

startNextQuestion

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

Specified by:
startNextQuestion in class AbstractGameMode
Returns:
True for success, false if no more questions are vailable

receiveAnswer

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

Specified by:
receiveAnswer in class AbstractGameMode
Returns:
Error codes:
0 - Success
1 - Invalid answer
2 - Player has already answered
3 - Question timeout is reached

removeUser

public void removeUser(User user)
Description copied from class: AbstractGameMode
Remove a user from the game

Overrides:
removeUser in class AbstractGameMode
Parameters:
user - user to remove

getQuestionStatistics

public java.util.ArrayList<StatisticsEntry> getQuestionStatistics()
Returns the statistics for the last question for the all the users in the quiz. This implementation returns the correct answer id and the percentage of users who chose the different answer options. The answer is stored in the "currentAnswer" key and the percentage of users who chose the different anwers have the key of the answer ID they represent.

Specified by:
getQuestionStatistics in class AbstractGameMode
Returns:
A list of statistics entries, or null if statistics cannot be returned a this point

getQuestionStatistics

public java.util.ArrayList<StatisticsEntry> getQuestionStatistics(User user)
Returns the statistics for the last question for the requested user. This implementation only returns the correct answer id stored in the "correctAnswer" key.

Specified by:
getQuestionStatistics in class AbstractGameMode
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 java.util.ArrayList<StatisticsEntry> getOverallStatistics()
Returns the overall statistics for the entire game. In this game mode we return the percentage of answers that was correct and which users who answered the most correct questions
Fields:
"correct" - The percentage of correct answers as a float in string form
"questionCount" - The number of questions in this quiz
"mostCorrectUser" - The user who had the most correct answers
"mostCorrectCount" - The number of correct answers this user had

Specified by:
getOverallStatistics in class AbstractGameMode
Returns:
A list of statistics entries or null if the game is not over.

getOverallStatistics

public java.util.ArrayList<StatisticsEntry> getOverallStatistics(User user)
Returns the overall statistics for the entire game for a specified user. In this game mode we only return the percentage of answers that were correct
Fields:
"correct" - The percentage of correct answers as a float in string form

Specified by:
getOverallStatistics in class AbstractGameMode
Parameters:
user - The user to get statistics for
Returns:
A list of statistics entries or null if the game is not over.