Beispiel #1
0
class Game:

	

	def __init__(self):
		self.ID = 0 # The GameID
		self.my_message_alerts = 0
		self.nudge = False
		self.coins = 0
		self.my_turn = False
		self.type = ''
		self.opponent = None #User()
		self.my_rack_tiles = []	# List of available tiles
		self.remaining_tiles = 0 # Tiles to come
		self.board = Board()
		self.turns_played = 0
		self.turns_passed = 0
		self.last_turn = None
		self.my_score = 0
		self.opponent_score = 0
		self.chat_enable = False
		self.lang_distribution = '' # Whatever this is
		self.language = ''
		self.dictionary_version = ''
		self.created = ''
		self.expiration_date = ''
		self.game_status = ''
		self.extras = []
		self.removed_by_opponent = False


	def parseJSON(self, dct):
		if 'id'					in dct: self.ID					= dct['id']
		if 'my_message_alerts'	in dct: self.my_message_alerts	= dct['my_message_alerts']
		if 'nudge'				in dct: self.nudge				= dct['nudge']
		if 'coins'				in dct: self.coins				= dct['coins']
		if 'my_turn'			in dct: self.my_turn			= dct['my_turn']
		if 'type'				in dct: self.type				= dct['type']
		if 'remaining_tiles'	in dct: self.remaining_tiles	= dct['remaining_tiles']
		if 'turns_played'		in dct: self.turns_played		= dct['turns_played']
		if 'turns_passed'		in dct: self.turns_passed		= dct['turns_passed']
		if 'my_score'			in dct: self.my_score			= dct['my_score']
		if 'opponent_score'		in dct: self.opponent_score		= dct['opponent_score']
		if 'chat_enable'		in dct: self.chat_enable		= dct['chat_enable']
		if 'lang_distribution'	in dct: self.lang_distribution	= dct['lang_distribution']
		if 'language'			in dct: self.language			= dct['language']
		if 'dictionary_version'	in dct: self.dictionary_version	= dct['dictionary_version']
		if 'created'			in dct: self.created			= dct['created']
		if 'expiration_date'	in dct: self.expiration_date	= dct['expiration_date']
		if 'game_status'		in dct: self.game_status		= dct['game_status']
		if 'extras'				in dct: self.extras				= dct['extras'] # Right now we don't care about the extras, so we will add it as an object
		if 'removed_by_opponent'in dct: self.removed_by_opponent= dct['removed_by_opponent']

		# The opponent is just a User
		if 'opponent'			in dct:
			self.opponent = User()
			self.opponent.parseJSON(dct['opponent'])

		# The last played turn
		if 'last_turn'			in dct:
			self.last_turn = Turn()
			self.last_turn.parseJSON(dct['last_turn'])

		# For the available tiles, transform from string to list
		if 'my_rack_tiles'		in dct:	
			my_rack_tiles = [x.strip() for x in dct['my_rack_tiles'].split(',')]

		# Parse the board
		if 'board_tiles'		in dct:
			board_tiles = dct['board_tiles'] # In the format 'A|156,R|187,E|126,N|141,E|112,O|142,O|172,L|157,D|113,I|114,D|115,O|116,C|111',
			self.board = Board()
			self.board.initFromTileString(board_tiles)