コード例 #1
0
ファイル: main.py プロジェクト: FilipHarald/TournamentHelper
 def post(self):
     nick_n_char_code = self.request.get("nick_n_char_code")
     q = db.GqlQuery("Select * FROM TournamentBrackets")
     t_b = q.get()
     if nick_n_char_code and t_b:
         nick, char_code = nick_n_char_code.split('.')
         winner_bracket_keys = t_b.winner_bracket
         loser_bracket_keys = t_b.loser_bracket
         count = 0
         fixed = False
         for p in winner_bracket_keys:
             if p:
                 player = db.get(p)
                 if nick is player.nick:
                     if char_code is player.char_code:
                         t_b.winner_bracket[count-1/2] = player.key()
                         fixed = True
                         break
             count += 1
         if not fixed:
             count = 0
             for p in loser_bracket_keys:
                 if p:
                     player = db.get(p)
                     if nick is player.nick:
                         if char_code is player.char_code:
                             t_b.loser_bracket[count-1/2] = player.key()
                             break
                 count += 1
         t_b.put()
     self.redirect('/admin/projectorview')
コード例 #2
0
ファイル: game.py プロジェクト: flakmonkey/Talisman
 def check_items(self, player):
     # Break out if player is dead
     if not player.life:
         return None
     items = []
     for i in self.board.tiles[player.key()].contents:
         try:
             if i.value:
                 items.append(i)
         except AttributeError:
             pass
     if items:
         player.pickup_items(items)
         for i in items:
             try:
                 self.board.tiles[player.key()].contents.remove(i)
             except ValueError:
                 print("ERROR: Item not in tile so I cant remove anything!")
コード例 #3
0
ファイル: game.py プロジェクト: flakmonkey/Talisman
 def encounter(self, player):
     #List contents of tile that current player is on
     options = [obj for obj in self.board.tiles[player.key()].contents
                if obj is not player]
     # Break out if current player is only one on the tile
     # if not options:
         # return None
     print("\nHere is your encounter:")
     print("======================================")
     print("0. Adventure Card")
     #List out menu of possible options
     for i, opt in enumerate(options, start=1):
         print("%s" % self.generate_encounter_msg(i, opt))
     print("======================================")
     while True:
         try:
             choice = int(input(">> "))
             if choice == 0:
                 self.draw_adv_card()
                 return None
             elif choice in range(1, len(options) + 1):
                 break
             else:
                 print("Invalid choiz")
         except ValueError:
             print("Invalid choice")
     selection = options[choice - 1]
     #Fight some other player
     try:
         if selection.username:
             try:
                 player.fight([options[choice - 1]])
             except AttributeError:
                 #Probably tried to fight something that's not a player
                 pass
             #Check if enemies defeated me (death=True)
             if self.check_player_death(player):
                 winner = options[choice - 1]
                 #Winner loots whatever I just dropped
                 self.check_items(winner)
             else:
                 for opt in options:
                     #Perhaps I defeated enemies
                     if self.check_player_death(opt):
                         # I loot whatever enemy just dropped
                         self.check_items(player)
     except AttributeError:
         pass
     #Pick up item sitting on tile
     try:
         if selection.value:
             player.pickup_items(selection)
     except AttributeError:
         pass
コード例 #4
0
ファイル: game.py プロジェクト: flakmonkey/Talisman
 def check_player_death(self, player):
     #Check that life = 0
     if not player.life:
         k = player.key()
         #Only drop gold if > 0
         if player.gold.value:
             self.board.load_tile(player.gold, k)
         for item in player.items:
             self.board.load_tile(item, k)
         self.board.unload_tile(player)
         self.players.remove(player)
         if not self.assign_player_card(player.username):
             print("Sorry %s. You can't rejoin.\n" % player.username)
         else:
             print("%s respawned as %s" %
                  (player.username, self.get_player(player.username)))
             #Add respawned player to board
             self.board.load_tile(self.get_player(player.username))
         return True
     else:
         return False