def __fetch_players_list_thread(self): # fetch players list from remote server players = ServerCom.fetch_players() if players.__len__() > 0: PlayerData.setPlayers(players) self.__updatenum_players() # generate missing player names for player in players: SoundManager.create_player_sound(player)
def on_enter(self): self.all_players = PlayerData.get_players() self.elo_ranges = PlayerData.get_ranges() Clock.schedule_once(lambda dt: self.__setup_player_dropdown(), 0.2) self.current_player_slot = 0 for (i, val) in enumerate(self.players): for p in self.all_players: if p['id'] == self.players[i].get('id', 0): self.players[i] = p
def __handle_rfid(self, rfid): self.current_rfid = rfid SoundManager.play(Trigger.RFID) # RFID --> player ID player_id = PlayerData.get_player_by_rfid(rfid) # player ID --> player dict player = PlayerData.get_player_by_id(player_id) if player: time.sleep(0.5) self.current_player = player else: self.current_player = {}
def main(): # Init display & clock display = pygame.display.set_mode((800, 600), DOUBLEBUF) pygame.display.set_caption("Infinity Swarm") gem_list = ["amber", "amethyst", "emerald", "ruby", "sapphire", "topaz"] display_icon = pygame.transform.scale( pygame.image.load("assets/materials/" + random.choice(gem_list) + ".png"), (64, 64)) pygame.display.set_icon(display_icon) clock = pygame.time.Clock() # Player data holder player_data = PlayerData("Player") # Init screens screen_main = layouts.ScreenMain(display, player_data) screen_levelinfo = layouts.ScreenLevelInfo(display) screen_game = layouts.ScreenGame(display, player_data) current_screen = "main" screens = { "main": screen_main, "levelinfo": screen_levelinfo, "game": screen_game } frame = 0 loop = True while loop: caught_events = pygame.event.get() for event in caught_events: if event.type == pygame.QUIT: loop = False break frame = (frame + 1) % 60 if frame % 5 == 0: player_data.ccps_tick(12) cur_screen = screens[current_screen] upd_rects = cur_screen.update(caught_events) screen_switch = cur_screen.get_switch_screen() if screen_switch: current_screen = screen_switch screens[current_screen].init_screen(cur_screen) pygame.display.update(upd_rects) clock.tick(60)
def __handle_rfid(self, rfid): # RFID --> player ID player_id = PlayerData.get_player_by_rfid(rfid) # player ID --> player dict player = PlayerData.get_player_by_id(player_id) Logger.info('ScoreTracker: RFID: {0} - ID: {1} - Player: {2}'.format(rfid, player_id, player)) # player does not exist if player == None: self.denied() # player does exist else: if self.dropdown_player: self.dropdown_player.dismiss() self.set_player(player)
def __submit_score_thread(self): # submit score to remote server (error, elo) = ServerCom.submit_score(self.players, GameData.get_score()) if error is None: self.submit_success = True self.__set_elo(elo) # fetch ranking ranking_attacker = ServerCom.fetch_ranking('attacker') if ranking_attacker: PlayerData.set_ranking('attacker', ranking_attacker) ranking_defender = ServerCom.fetch_ranking('defender') if ranking_defender: PlayerData.set_ranking('defender', ranking_defender) else: self.submit_success = False
def __fetch_data(self, dt): cmd = 'wpa_cli status | egrep "(wpa_state|id_str|ip_address)"' proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) output = proc.communicate()[0] entries = {} for line in output.splitlines(): line = line.strip() if '=' in line: (key, value) = line.split('=') entries[key] = value self.state = entries.get('wpa_state', 'DISCONNECTED') self.ip_address = entries.get('ip_address', '') self.id_str = entries.get('id_str', '') connected = (self.state == 'COMPLETED' and self.ip_address != '') if connected != self.connected: self.connected = connected if self.connected: try: player_id = int(self.id_str) self.player = PlayerData.get_player_by_id(player_id) except Exception, e: print e self.player = None else: self.player = None self.say_connection_status() # notify all registered clients for cb_function in self.callbacks: cb_function(self.get_data())
def __setup_player_dropdown(self): self.dropdown_player = DropDown() self.dropdown_player.bind(on_select=self.on_player_select) players = sorted(PlayerData.get_players(), key=lambda player: player['name']) for player in players: btn = PlayerButton(data=player) btn.bind(on_release=lambda btn: self.dropdown_player.select(btn.data)) self.dropdown_player.add_widget(btn)
def __setup_player_dropdown(self): # only create if not existing if not self.dropdown_player: self.dropdown_player = DropDown(auto_dismiss=False) self.dropdown_player.bind(on_select=self.on_player_select) self.dropdown_player.bind(on_dismiss=self.on_dropdown_dismiss) players = sorted(PlayerData.get_players(), key=lambda player: player['name']) for player in players: btn = PlayerButton(data=player) btn.bind(on_release=lambda btn: self.dropdown_player.select(btn.data)) self.dropdown_player.add_widget(btn)
class EvaluatingApp(App): pdata = ObjectProperty(PlayerData()) def build(self): '''kivy's app init point''' self.build_root() self.build_data() self.show_prepare() def build_root(self): self.build_scene(self.root.scene) def build_scene(self, scene): Builder.load_file('prepare.kv') Builder.load_file('result.kv') scene.prepare = self.build_prepare() scene.lwin = self.build_result(self.pdata.lwin) scene.draw = self.build_result(self.pdata.draw) scene.rwin = self.build_result(self.pdata.rwin) def build_prepare(self): prepare = PrepareScene() prepare.build() prepare.associate(self.pdata) return prepare def build_result(self, ratefunc): result = ResultScene() result.build() result.associate(self.pdata, ratefunc) return result def build_data(self): players = self.pdata.players cteam = self.pdata.cteam for name in PLAYERS: players[name] = (MEAN, STDDEV) cteam.append(name) def show_prepare(self): self.root.show_prepare()
def __fetch_players_list_thread(self): # fetch players list from remote server players = ServerCom.fetch_players() if players: PlayerData.set_players(players) self.__updatenum_players() # generate missing player names for player in players: SoundManager.create_player_sound(player) # fetch ranking ranking_attacker = ServerCom.fetch_ranking('attacker') if ranking_attacker: PlayerData.set_ranking('attacker', ranking_attacker) ranking_defender = ServerCom.fetch_ranking('defender') if ranking_defender: PlayerData.set_ranking('defender', ranking_defender)
filter(PlayerGameStat.create_dt > cutoff_dt).\ filter(Player.nick != None).\ filter(Player.player_id > 2).\ filter(Player.active_ind == True).\ limit(NUM_PLAYERS).all() else: players = DBSession.query(distinct(Player.player_id)).\ filter(Player.player_id == PlayerElo.player_id).\ filter(Player.player_id == PlayerGameStat.player_id).\ filter(PlayerGameStat.create_dt > cutoff_dt).\ filter(Player.nick != None).\ filter(Player.player_id > 2).\ filter(Player.active_ind == True).\ all() playerdata = PlayerData() if len(players) > 0: stop = datetime.now() td = stop-start print "Query took %.2f seconds" % (datetime_seconds(td)) print "Creating badges for %d players ..." % len(players) start = datetime.now() data_time, render_time = 0,0 for player_id in players: req.matchdict['id'] = player_id sstart = datetime.now() playerdata.get_data(player_id) sstop = datetime.now()
def add_entry(self): PlayerData.add_rfid(self.current_rfid, self.current_player.get('id')) self.__reset()
def on_current_player(self, instance, value): self.ids.btnPlayer.iconText = self.current_player.get('name', u'---') SoundManager.play(Trigger.PLAYER_SELECTED, self.current_player) # enable "accept" button if current player is set and was not stored before self.ids.btnAccept.disabled = not (self.current_player.has_key('id') and self.current_player.get('id') != PlayerData.get_rfid_map().get(self.current_rfid))
filter(PlayerGameStat.create_dt > cutoff_dt).\ filter(Player.nick != None).\ filter(Player.player_id > 2).\ filter(Player.active_ind == True).\ limit(NUM_PLAYERS).all() else: players = DBSession.query(distinct(Player.player_id)).\ filter(Player.player_id == PlayerElo.player_id).\ filter(Player.player_id == PlayerGameStat.player_id).\ filter(PlayerGameStat.create_dt > cutoff_dt).\ filter(Player.nick != None).\ filter(Player.player_id > 2).\ filter(Player.active_ind == True).\ all() playerdata = PlayerData() if len(players) > 0: stop = datetime.now() td = stop - start print "Query took %.2f seconds" % (datetime_seconds(td)) print "Creating badges for %d players ..." % len(players) start = datetime.now() data_time, render_time = 0, 0 for player_id in players: req.matchdict['id'] = player_id sstart = datetime.now() playerdata.get_data(player_id) sstop = datetime.now()
def on_current_rfid(self, instance, value): # enable "remove" button if rfid mapping exists self.ids.btnClear.disabled = not PlayerData.get_rfid_map().has_key(self.current_rfid) # disable player selection box if no RFID is set self.ids.btnPlayer.disabled = not self.current_rfid self.teaching = True if self.current_rfid else False
def __updatenum_players(self): self.num_players = PlayerData.get_players().__len__()
def remove_entry(self): PlayerData.remove_rfid(self.current_rfid) self.__reset()