GameEngine.Core
Class Message

java.lang.Object
  extended by GameEngine.Core.Message

public class Message
extends java.lang.Object

responsible for create general messages that are used in all modes. the messages that are specific to mode will be created in GameMode class or child class

Author:
tranlongtien

Field Summary
static java.lang.String HANDSHAKE_MASTER
          Handshake string.
static java.lang.String HANDSHAKE_MOBILE
           
static int MAX_NUMBER_OF_FIELDS_IN_MSG
           
static char MSG_ANSWER
           
static char MSG_END_OF_GAME
           
static char MSG_END_OF_ROUND
           
static char MSG_EXIT
           
static char MSG_GAME_MODE
           
static char MSG_LECTURE_ID
           
static char MSG_LOGIN
           
static char MSG_MOBILE_LOGIN
           
static char MSG_NEXT_QUESTION
           
static char MSG_NUMBER_OF_QUES
           
static char MSG_QUESTION
           
static char MSG_START
           
static char MSG_UNKNOWN_MESSAGE
          These characters are prepended to messages that are sent to Game Engine, to show what type of messages they are
protected  java.lang.String msgContent
           
protected  java.lang.String msgRaw
           
protected  char msgType
           
 
Constructor Summary
Message(java.lang.String rawMessage)
           
 
Method Summary
static java.lang.String createEndGame4Mobile(GameEngine.Core.MobileCommunicator c)
           
static java.lang.String createEndGameMessage()
           
static java.lang.String createExitMessage()
           
static java.lang.String createLoginOk()
           
static java.lang.String createMobileLoginMsg(java.lang.String user)
           
static java.lang.String createStartGameMessage()
           
 int getAnswerIndex()
           
 java.lang.String getMsgContent()
           
 java.lang.String getRawMessage()
           
 char getTypeOfMsg()
           
 boolean isAnswer()
          check if the message received is an answer from mobile
 java.lang.String makeClientQuestion(GameEngine.Core.Question q)
          Creates the question to be sendt to the StudentClient.
 java.lang.String makeMasterQuestion(GameEngine.Core.Question q)
          Creates the question to be sendt to the MasterClient.
private  java.lang.String makeQuestionRoot(GameEngine.Core.Question q)
          Creates the root of the question to be sendt to eighter the studenclients or the masterclient.
 void printMsg()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

msgType

protected char msgType

msgContent

protected java.lang.String msgContent

msgRaw

protected java.lang.String msgRaw

MAX_NUMBER_OF_FIELDS_IN_MSG

public static final int MAX_NUMBER_OF_FIELDS_IN_MSG
See Also:
Constant Field Values

MSG_UNKNOWN_MESSAGE

public static final char MSG_UNKNOWN_MESSAGE
These characters are prepended to messages that are sent to Game Engine, to show what type of messages they are

See Also:
Constant Field Values

MSG_NUMBER_OF_QUES

public static final char MSG_NUMBER_OF_QUES
See Also:
Constant Field Values

MSG_GAME_MODE

public static final char MSG_GAME_MODE
See Also:
Constant Field Values

MSG_START

public static final char MSG_START
See Also:
Constant Field Values

MSG_EXIT

public static final char MSG_EXIT
See Also:
Constant Field Values

MSG_LECTURE_ID

public static final char MSG_LECTURE_ID
See Also:
Constant Field Values

MSG_END_OF_GAME

public static final char MSG_END_OF_GAME
See Also:
Constant Field Values

MSG_END_OF_ROUND

public static final char MSG_END_OF_ROUND
See Also:
Constant Field Values

MSG_QUESTION

public static final char MSG_QUESTION
See Also:
Constant Field Values

MSG_ANSWER

public static final char MSG_ANSWER
See Also:
Constant Field Values

MSG_LOGIN

public static final char MSG_LOGIN
See Also:
Constant Field Values

MSG_MOBILE_LOGIN

public static final char MSG_MOBILE_LOGIN
See Also:
Constant Field Values

MSG_NEXT_QUESTION

public static final char MSG_NEXT_QUESTION
See Also:
Constant Field Values

HANDSHAKE_MASTER

public static final java.lang.String HANDSHAKE_MASTER
Handshake string. Each end of the connection sends this string to the other just after the connection is opened. This is done to confirm that the program on the other side of the connection is a proper program.

See Also:
Constant Field Values

HANDSHAKE_MOBILE

public static final java.lang.String HANDSHAKE_MOBILE
See Also:
Constant Field Values
Constructor Detail

Message

public Message(java.lang.String rawMessage)
Method Detail

getTypeOfMsg

public char getTypeOfMsg()

getMsgContent

public java.lang.String getMsgContent()

getRawMessage

public java.lang.String getRawMessage()

makeQuestionRoot

private java.lang.String makeQuestionRoot(GameEngine.Core.Question q)
Creates the root of the question to be sendt to eighter the studenclients or the masterclient. The root is similar, thus this only needs one method. The last part of the question is different though. Example of output: 7Who am I?|3|me|you|them|30| this is translated to question: who am I? number of alternatives: 3 alternative 1: me alternative 2: you alternative 3: them timelimit: 30 s

Returns:
a question root

makeClientQuestion

public java.lang.String makeClientQuestion(GameEngine.Core.Question q)
Creates the question to be sendt to the StudentClient. Appends: 0 - not last question in lecture 1 - last question in round 2 - last question i lecture

Parameters:
questionState - the state of the question
Returns:
String formatted and ready to be sendt to the StudentClient

makeMasterQuestion

public java.lang.String makeMasterQuestion(GameEngine.Core.Question q)
Creates the question to be sendt to the MasterClient. Appends first the correct alternative (which is not sendt to the clients)

Parameters:
questionState - the state of the question
Returns:
String formatted and ready to be sendt to the StudentClient

createExitMessage

public static java.lang.String createExitMessage()

createEndGameMessage

public static java.lang.String createEndGameMessage()

createStartGameMessage

public static java.lang.String createStartGameMessage()

createLoginOk

public static java.lang.String createLoginOk()

createEndGame4Mobile

public static java.lang.String createEndGame4Mobile(GameEngine.Core.MobileCommunicator c)

printMsg

public void printMsg()

isAnswer

public boolean isAnswer()
check if the message received is an answer from mobile


getAnswerIndex

public int getAnswerIndex()

createMobileLoginMsg

public static java.lang.String createMobileLoginMsg(java.lang.String user)