def get(self): map_name = self.request.get("maps") player1 = self.request.get("player1") player2 = self.request.get("player2") player_code = self.request.get("code").replace('\r','') if not player_code: player_code = "def turn(b,r,c):"+'\n'+" return 'E'"; self.response.out.write( header() ) pl = tron_db.Program.all().fetch(50) mp = tron_db.Map.all().fetch(50) s = "<b>play an (unranked) match. it's you against the machine, or bot vs bot</b><p>" s += "<form action=/play>" s += "<textarea rows=10 cols=90 name=code>"+player_code+"</textarea><br>" s += "<select name=player1 title=player1>" if player1: s += "<option>" + player1 + "</option>\n" s += "<option> ME </option>\n" for p in pl: s += "<option>" + p.name + "</option>\n" s += "</select>" s += "<select name=player2 title=player2 >" if player2: s += "<option>" + player2 + "</option>\n" for p in pl: s += "<option>" + p.name + "</option>\n" s += "<option> ME </option>\n" s += "</select>" s += "<select name=maps title=map>" if map_name: s += "<option>" + map_name + "</option>\n" for m in mp: g,r,c,p = tron.parse_map(m.text) if p == 2: s += "<option>" + str(m.key().name()) + "</option>\n" s += "</select> " s += "<input type=submit value='play a game'>" s += "</form>" if map_name and player1 and player2: map = tron_db.Map.get_by_key_name(map_name) if player1=="ME" and player_code: pl1 = tron_db.Program(text=player_code,name=player1) else: pl1 = tron_db.Program.all().filter("name",player1).get() if player2=="ME" and player_code: pl2 = tron_db.Program(text=player_code,name=player2) else: pl2 = tron_db.Program.all().filter("name",player2).get() if map and pl1 and pl2: g = tron.Game() playgame(g,[pl1,pl2],map.text, map_name) plan = [player1,player2] hist = [g.players[0]['hist'],g.players[1]['hist']] rank = [g.players[0]['score'],g.players[1]['score']] s += drawReplay(42,plan,hist,g.errors,rank,map_name,map.text,g.turn ) else: logging.warn("invalid setup " + str(map) + " " + str(pl1) + " " + str(pl2)) self.response.out.write( s ) self.response.out.write( footer() )
def get(self): key = self.request.get("key") try: w = self.request.get("w") h = self.request.get("h") except: pass if not w : w=400 if not h : h=400 game = tron_db.GameInfo.get_by_id(int(key)) if not game: self.response.out.write( sorry_404( "game " + key ) ) return s = header() map = tron_db.Map.get_by_key_name(game.mapname) s += drawReplay(key,game.players,game.history,game.errors,game.rank,game.mapname,map.text,game.turn,w,h) s += footer() self.response.out.write( s )