예제 #1
0
	def get(self):
		diff_str = self.request.get('diff')
		
		if diff_str: # requested new difficulty => start new game
			if self.session.get('gameID'): # need to delete old game
				logging.info("Deleting game ID %s", self.session['gameID'])
				ndb.Key('Game', int(self.session['gameID'])).delete()
			
			if int(diff_str) in [diff.rank for diff in game.difficulties()]:
				rank = int(diff_str)
			else:
				rank = 0
				
			game_instance = game.createGame(rank)
			self.session['gameID'] = game_instance.gameID
			self.template_values.update({ 'game': game_instance,
											'welcome': "You awaken in a dark room.<br /><br />There might be a way out ..." })
			
		else: # trying to continue game
			if self.session.get('gameID'):
				game_instance = self.template_values['game']
				self.template_values.update({ 'welcome': "You awaken again in a dark room.<br /><br />There might still be a way out ..." })
				
		try:
			#token = channel.create_channel( game_instance.client_id )
			#self.template_values.update({'token': token})

			template = jinja_environment.get_template( 'play.html' )	
			self.response.out.write(template.render(self.template_values))
		except:
			self.redirect("/")
예제 #2
0
	def get(self):
		num_events = 100
		
		logs = GameCompletion.recent().fetch(num_events)
		diffs = game.difficulties()
		
		#attempts = [0 for x in diffs]
		#total_moves = [0 for x in diffs]
		moves = [[] for x in diffs]
		times = [[] for x in diffs]
		most_recent = [datetime.datetime.fromordinal(1) for x in diffs]
		
		for log in logs:
			#attempts[log.diff_rank] += 1
			#total_moves[log.diff_rank] += log.moves
			moves[log.diff_rank].append(log.moves)
			times[log.diff_rank].append(log.time.total_seconds())
			if (log.finished > most_recent[log.diff_rank]):
				most_recent[log.diff_rank] = log.finished
		
		statslist = []
		statslist.append(	{'name':"Attempts", 'vals':[len(m) for m in moves]}	)
		statslist.append(	{'name':"Min moves", 'vals':[min(m) for m in moves]}	)
		statslist.append(	{'name':"Average moves", 'vals':[sum(m)/len(m) for m in moves]}	)
		statslist.append(	{'name':"Max moves", 'vals':[max(m) for m in moves]}	)
		statslist.append(	{'name':"Most recent completion", 'vals':[t.strftime("%A, %d. %B %Y %I:%M%p") for t in most_recent]}	)
		statslist.append(	{'name':"Quickest (secs)", 'vals':[min(t) for t in times]}	)
		statslist.append(	{'name':"Mean time (secs)", 'vals':[sum(t)/len(t) for t in times]}	)
		
		plotslist = []
		plotslist.append(	{'name':"Moves", 'vals':moves}	)
		plotslist.append(	{'name':"Times (secs)", 'vals':times}	)

		template_values = { 'difficulties': diffs,
							'stats': statslist,
							'plots': plotslist}	
		template = jinja_environment.get_template('stats.html')
		self.response.out.write(template.render(template_values))
예제 #3
0
    def get(self):
		#template_values = { 'difficulties': game.difficulties }	
		self.template_values.update({'difficulties': game.difficulties()})
		template = jinja_environment.get_template('index.html')
		self.response.out.write(template.render(self.template_values))