Ejemplo n.º 1
0
	def post(self):
		user = users.get_current_user()
		game_key = self.request.get("game_key")
		self.channel = Channel()
		if not game_key:
			#if the client did not specify a game_key, then obviously they have no friends so we'll create a game_key for them
			game_key = str(random.getrandbits(32)) + user.user_id() # a relatively long pseudo random number should ensure enough uniqueness that we require (after all, it's not secret!)
			token = self.channel.createToken(user, game_key)

			self.game = Game(key_name = str(game_key))
			self.game.put()
			gameupdater = GameUpdater(self.game)
			gameupdater.setup()
			
			self.response.headers['Content-Type'] = 'application/json'
			self.response.write(json.dumps({'game_key': game_key, 'token' : token})) #Return a JSON with the token inside		
		else:
			game = Game.get_by_key_name(self.request.get('game_key'))
			if not game :
				self.response.headers['Content-Type'] = 'application/json'
				self.response.write(json.dumps({'error' : 'no game exists'})) #Return a JSON with the token inside
			else :
				game_key =  self.request.get('game_key')
				token = self.channel.createToken(user, game_key)
				self.response.headers['Content-Type'] = 'application/json'
				self.response.write(json.dumps({'game_key': game_key, 'token' : token})) #Return a JSON with the token inside
Ejemplo n.º 2
0
	def post(self):
		query = Game.gql("WHERE inProgress = False")
		games = query.fetch(20)
		self.response.headers['Content-Type'] = 'application/json'
		output = []
		for game in games :
			output.append({'key' : game.key().name(), 'players' : 4 - len(game.pieces)})
		self.response.write(json.dumps(output))
Ejemplo n.º 3
0
	def post(self):
		user = users.get_current_user()
		if not user:
			self.response.headers['Content-Type'] = 'application/json'
			self.response.write(json.dumps({'status': 'no_login'}))
			return #end the script
		game = Game.get_by_key_name(self.request.get('game_key'))
		gu = GameUpdater(game)
		gu.rollTheDice(user)
Ejemplo n.º 4
0
	def post(self):
		user = users.get_current_user()
		game = Game.get_by_key_name(self.request.get('game_key'))
		action = self.request.get('action')
		property = self.request.get('property')
		gu = GameUpdater(game)
		if action == 'buy' :
			gu.buyHouse(user, property)
		elif action == 'sell' :
			#gu.sellHouse(user, property)
			pass
Ejemplo n.º 5
0
	def post(self):
		user = users.get_current_user()
		game = Game.get_by_key_name(self.request.get('game_key'))
		GameUpdater(game).unmortgageProperty(user, self.request.get('property_id'))
Ejemplo n.º 6
0
	def post(self):
		user = users.get_current_user()
		game = Game.get_by_key_name(self.request.get('game_key'))
		gu = GameUpdater(game)
		gu.chat(user, self.request.get('message'))
Ejemplo n.º 7
0
	def post(self):
		user = users.get_current_user()
		game = Game.get_by_key_name(self.request.get('game_key'))
		gu = GameUpdater(game)
		gu.buyProperty(user)
Ejemplo n.º 8
0
	def post(self):
		#start game(game_key) iff client_id is the game creator
		game = Game.get_by_key_name(self.request.get('game_key'))
		gu = GameUpdater(game)
		gu.startGame()