def cellar(p: Player, scr: Screen) -> bool: cards = [i for i in p.current_hand] scr.show_main_content([ "Which cards do you want to discard?", "Separate your choices with a comma." ] + format_cards(cards, r_main_content.width)) chosen_cards = input_cards_selection(cards, scr, min=1, max=len(p.current_hand)) if chosen_cards == []: return False p.add_actions(1, scr) for card in chosen_cards: scr.log("Discarding: {0}".format(card.name)) p.current_hand.remove(card.name) p.discardpile.append(card.name) p.draw_cards(len(chosen_cards), scr) return True
def moneylender(p: Player, scr: Screen) -> bool: if "copper coin" in p.current_hand: p.trash_hand_card("copper coin", scr) p.add_money(3, scr) return True else: scr.log("No copper coin to remove from your hand!", 2) return False
def end_turn(p: Player, scr: Screen) -> None: scr.clear_main_content() scr.clear_history() # Reset player balance p.current_hand_balance = 0 p.bonus_coins = 0 p.amount_spent = 0 if session_objects.s_game_mode == "castle race": if any(card == "castle" for card in p.deck): scr.log("=== GAME WON ===", 1) scr.log("You've won the castle race!") scr.log("Turns taken: " + str(session_objects.s_turn_counter), 1) scr.log("Press enter to exit.", 2) scr.retrieve_user_input() exit(0) p.played_cards_to_discard() # Put all remaining cards in hard onto the discard pile scr.log("Putting hand cards in discard pile...") p.hand_to_discard() # Draw 5 cards p.draw_cards(5, scr, verbose=False) scr.log("Ended turn.")
def playerinfo(self, ids, statstype): output = Player.header() + '\n' for id_ in ids: #print(url) data = self.dp.fetchplayer(id_, statstype) nickname = self.dp.id2nick(int(data['account_id'])) player = Player(nickname, data) #print(json.dumps(data)) output += player.str() + '\n' return output
def start_turn(p: Player, scr: Screen) -> None: # Get balance p.current_hand_balance = p.get_hand_value() # Set actions and purchases left p.purchases_left = 1 p.actions_left = 1 session_objects.s_turn_counter += 1 scr.log("Started turn {0}.".format(session_objects.s_turn_counter))
def create_player_from_table(player_data, game, player=None): # create the player if he didn't already exist if not player: player_name = player_data.select('td > a')[0].text.split('-')[0].strip() played = not any([re.search('DN[PD]', elem.text) for elem in player_data.select('td')]) player = Player(player_name, played, game) # populate player stats if player.played: player.traditional_stats = populate_traditional_stats(player_data.select('td')[1:]) return player
def newgame(self): self.game = Game((156, 104, 128)) user = Player(self.game.world) for i in range(20): x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)] self.game.world.space.maketree((x,y, self.game.world.space.groundlevel(x,y))) kind = (Goblin,Tortoise,SmallSpider) for i in range(20): race = choice(kind) x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)] creature = race(None, (x,y,self.game.world.space.groundlevel(x,y))) self.game.schedule(creature) for i in range(7): x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)] creature = Dwarf(user, (x,y,self.game.world.space.groundlevel(x,y))) self.game.schedule(creature) x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)] loc = x, y, self.game.world.space.groundlevel(x,y) handle = Handle(choice(Wood.__subclasses__()), loc) blade = PickaxHead(choice(Metal.__subclasses__()), loc) self.game.world.additem(handle) self.game.world.additem(blade) x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)] loc = x, y, self.game.world.space.groundlevel(x,y) handle = Handle(choice(Wood.__subclasses__()), loc) blade = AxHead(choice(Metal.__subclasses__()), loc) self.game.world.additem(Ax(loc, handle, blade)) x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)] self.game.world.additem(Workbench((x,y, self.game.world.space.groundlevel(x,y)), choice(Wood.__subclasses__()))) for i in range(10): x, y = [randint(0, self.game.dimensions[i]-1) for i in range(2)] self.game.world.additem(Barrel((x,y, self.game.world.space.groundlevel(x,y)), choice(Wood.__subclasses__()))) self.child = Renderer(self.game, user, self.zoom) user.foundsettlement('the fortress')
def Setup(self): self.gameOver = False self.gOScreen = pygame.image.load("data/GameOver.png") self.gameWon = False self.gWScreen = pygame.image.load("data/YouWon.png") self.gameStart = True self.SplashScreen = pygame.image.load("data/SplashScreen.png") self.gui = [] #On crée un joueur joueur = Player.Player("Player", self.engine) graine = Graine.Graine("Graine", self.engine) file = "data/TestLevel.json" self.walls, self.wells = GenLevel(file, self.engine) self.gui.append(SeveBar.Seve("Seve", self.engine)) self.plante = [] self.mask = pygame.Surface((self.engine.rendu.get_size())) pygame.draw.circle( self.mask, (255, 255, 255), (self.engine.Rlongueur // 2, self.engine.Rlargeur - 24 - 30), 12)
def playerheroesinfo(self, ids, statstype, sort_by, order, arglimit): output = '' for id_ in ids: data = self.dp.fetchplayer(id_, statstype) nickname = self.dp.id2nick(int(data['account_id'])) player = Player(nickname, data) stats = player.playerheroes(self.dp, statstype, sort_by, order) limit = arglimit if arglimit else len(stats) output += self.dp.id2nick(id_) + '\n' output += Player.PlayerHeroHeader + '\n' for i in range(limit): stat = stats[i] stat['hero'] = self.dp.heroid2name(stat['heroid'])[:10] output += Player.PlayerHeroFormat.format(**stat) + '\n' return output
def chapel(p: Player, scr: Screen) -> bool: cards = [i for i in p.current_hand] scr.show_main_content([ "Which cards do you want to remove from your deck?", "Separate your choices with a comma." ] + format_cards(cards, r_main_content.width)) chosen_cards = input_cards_selection(cards, scr, min=1, max=4) if chosen_cards == []: return False for card in chosen_cards: p.trash_hand_card(card.name, scr) return True
def add_player(p): if not p in goalPerPlayer: goalPerPlayer[p] = 0 timePerPlayer[p] = 0 try: fname, lname = p.split(' ', 1) except ValueError: fname = p lname = '' player = Player.get_or_create(session, fname, lname, None) return player
def start_new_game(p: Player, scr) -> None: """ Function that gets called at the start of a new game. p: The player object to start the game with. """ # Reset turn counter session_objects.s_turn_counter = 0 # Add starter cards into deck p.deck = ["copper coin"] * 7 p.deck += ["land"] * 3 # Copy deck into drawpile p.drawpile = p.deck.copy() # shuffle draw pile random.shuffle(p.drawpile) # Draw 5 cards p.draw_cards(5, main_screen, verbose=False)
def gift_card(p: Player, card: str, scr, pile: str = None) -> bool: """ Gifts a player a certain card. """ if pile is None: pile = "discard" # Card doesn't exist in the store if card not in s_store.keys(): scr.log("This card doesn't exist in the store!", 2) return False # Card has 0 left in the store elif s_store.get(card) == 0: scr.log("There are no more copies left of this card.", 2) return False else: scr.log("Received card: " + card, 1) # Decide where to add the card if pile == "hand": p.add_hand_card(card) elif pile == "draw": p.add_drawpile_card(card) else: p.add_discardpile_card(card) remove_card(card, scr) return True
def purchase_card(p: Player, card: str, scr: Screen) -> bool: """ The transaction method. Buys a card for a player using their balance. The purchased card gets taken out of the shop, and placed into the player's discard pile. """ # Card doesn't exist in the store if card not in s_store: scr.log("This card doesn't exist in the store!", 2) return False # Card has 0 left in the store elif s_store.get(card) == 0: scr.log("This card cannot be bought anymore!", 2) return False # Player can't purchase any more cards elif p.purchases_left == 0: scr.log("You can't buy any more cards this turn!", 2) return False else: # Load in the card card_bought = load_card(card) if card_bought.cost > (p.current_hand_balance + p.bonus_coins - p.amount_spent): scr.log("Insufficient funds!", 2) return False # Confirm purchase p.purchases_left -= 1 scr.log("Bought card: {0}".format(card), 1) p.add_discardpile_card(card_bought.name) # Subtract cost from balance p.amount_spent += card_bought.cost remove_card(card, scr) return True
def mine(p: Player, scr: Screen) -> bool: money_cards = {} for card in p.current_hand: if "money" in load_card(card).cardtype: money_cards.update({card: card}) if len(money_cards.keys()) == 0: scr.log("No money cards to upgrade!", 2) return False scr.show_main_content( ["Which card do you want to upgrade?"] + format_cards(money_cards.keys(), r_main_content.width)) chosen_card = input_card_selection(list(money_cards.keys()), scr) if chosen_card is None: return card_name = chosen_card.name upgrade_card = "" if card_name == "platinum coin": scr.log("Sorry, the fun stops here.", 2) return False elif card_name == "gold coin": upgrade_card = "platinum coin" elif card_name == "silver coin": upgrade_card = "gold coin" elif card_name == "copper coin": upgrade_card = "silver coin" else: return False if store.gift_card(p, upgrade_card, scr, pile="hand"): p.trash_hand_card(money_cards[card_name], scr) return True else: return False
def act_add_player_match_from_name(self, team, fname, lname, comment=None, bulk=False): player = Player.get_or_create(self.session, fname, lname, comment) try: player_match = self.session.query(PlayerMatch).filter(PlayerMatch.match == self.match). \ filter(PlayerMatch.player == player).one() except NoResultFound: player_match = PlayerMatch() player_match.player = player player_match.match = self.match player_match.team = team self.session.add(player_match) if not bulk: self.session.commit()
def smithy(p: Player, scr: Screen) -> bool: p.draw_cards(3, scr) return True
def woodcutter(p: Player, scr: Screen) -> bool: p.add_money(2, scr) p.add_purchases(1, scr) return True
def magic_spell(p: Player, scr: Screen) -> bool: p.draw_cards(2, scr) return True
p.deck += ["land"] * 3 # Copy deck into drawpile p.drawpile = p.deck.copy() # shuffle draw pile random.shuffle(p.drawpile) # Draw 5 cards p.draw_cards(5, main_screen, verbose=False) ### Start of game # Create player mainguy = Player() # Create screen main_screen = Screen() main_screen.init_screen() main_screen.calibration_routine() main_screen.display_main() # Start the game as this new dude start_new_game(mainguy, main_screen) turns.start_turn(mainguy, main_screen) main_screen.update_turn_overview( mainguy.get_hand_value(), mainguy.actions_left, mainguy.purchases_left, mainguy.bonus_coins, mainguy.current_hand_balance + mainguy.bonus_coins - mainguy.amount_spent
def playerinfo(self, ids, statstype): tmpl_header, tmpl_footer = Html.loadtemplates() output = tmpl_header.substitute() output += '<h1>Player stats</h1>' output += '<table cellspacing="0" cellpadding="2">' output += '<tr>' + Html.list2cols(['Nick', 'MMR', 'K', 'D', 'A', 'W/G', 'CD', 'KDR', 'GP', 'Wins', 'Losses', 'W%'], 'th') + '</tr>' for id_ in ids: data = self.dp.fetchplayer(id_, statstype) nickname = self.dp.id2nick(int(data['account_id'])) player = Player(nickname, data) pdata = [player.rating(statstype), player.kills(statstype), player.deaths(statstype), player.assists(statstype), round(player.wards(statstype)/player.gamesplayed(statstype), 2), round(player.denies(statstype)/player.gamesplayed(statstype), 2), round(player.kills(statstype)/player.deaths(statstype), 2), player.gamesplayed(statstype), player.wins(statstype), player.losses(statstype), round(player.wins(statstype)/player.gamesplayed(statstype) * 100, 2)] output += '<tr><td><a href="/matches/{nick}">{nick}</a></td>'.format(nick=nickname) output += Html.list2cols(pdata) output += '</tr>' output += '</table>' output += tmpl_footer.substitute() return output
def village(p: Player, scr: Screen) -> bool: p.add_actions(2, scr) p.draw_cards(1, scr) return True
def import_from_2012(): old_session = OldSession() session = Session() # Match and teams match = Match() match.name = "24 ore 2012" first_team = session.query(Team).filter(Team.name == "Matematici").one() second_team = session.query(Team).filter(Team.name == "Fisici").one() match.team_a = first_team match.team_b = second_team # Team mapping _team_map = {} old_first_team = old_session.query(OldTeam).filter(OldTeam.name == "Matematici").one() old_second_team = old_session.query(OldTeam).filter(OldTeam.name == "Fisici").one() _team_map[old_first_team.id] = first_team _team_map[old_second_team.id] = second_team team_map = lambda x: _team_map[x.id] # Player mapping _player_map = {} player_matches = [] found_player_id = set() for old_player in old_session.query(OldPlayer).all(): player = Player.get_or_create(session, old_player.fname, old_player.lname, None) _player_map[old_player.id] = player player_match = PlayerMatch() player_match.player = player player_match.match = match player_match.team = team_map(old_player.team) player_matches.append(player_match) player_map = lambda x: _player_map[x.id] # Events events = [] for old_event in old_session.query(OldEvent).order_by(OldEvent.timestamp).all(): if old_event.type == 'sched_begin': match.sched_begin = old_event.timestamp elif old_event.type == 'begin': match.begin = old_event.timestamp elif old_event.type == 'sched_end': match.sched_end = old_event.timestamp elif old_event.type == 'end': match.end = old_event.timestamp else: event = Event() event.match = match event.timestamp = old_event.timestamp event.source = Event.EV_SOURCE_MANUAL event.type = old_event.type if old_event.type in [Event.EV_TYPE_GOAL, Event.EV_TYPE_GOAL_UNDO]: event.team = _team_map[int(old_event.param)] elif old_event.type == Event.EV_TYPE_SWAP: old_red_team_id, old_blue_team_id = map(int, old_event.param.split(',')) event.red_team = _team_map[old_red_team_id] event.blue_team = _team_map[old_blue_team_id] elif old_event.type == Event.EV_TYPE_CHANGE: old_team_id, old_player_a_id, old_player_b_id = map(int, old_event.param.split(',')) event.team = _team_map[old_team_id] event.player_a = _player_map[old_player_a_id] event.player_b = _player_map[old_player_b_id] found_player_id.add(event.player_a.id) found_player_id.add(event.player_b.id) else: assert(False, "Command not supported") events.append(event) session.add(match) for pm in player_matches: if pm.player.id in found_player_id: session.add(pm) for ev in events: session.add(ev) assert(ev.check_type()) session.flush() old_session.rollback() session.commit()
async def _handle_add_player(ws, **player): data.players.append(Player(player)) await send_all(data)
def festival(p: Player, scr: Screen) -> bool: p.add_actions(2, scr) p.add_purchases(1, scr) p.add_money(2, scr) return True
def council(p: Player, scr: Screen) -> bool: p.draw_cards(4, scr) p.add_purchases(1, scr) return True
def laboratory(p: Player, scr: Screen) -> bool: p.draw_cards(2, scr) p.add_actions(1, scr) return True
def create_player(self, id, ai=True): self.create_city() self.players.append(Player(id, self.city[-1], ai)) self.city[-1].player = self.players[-1] self.city[-1].check_outputs()
def get_or_create_player(session, ctx): player = session.query(Player).filter(Player.user_id == ctx.message.author.id, Player.guild_id == ctx.message.server.id).one_or_none() if not player: player = Player(user_id=ctx.message.author.id, guild_id=ctx.message.server.id, name=ctx.message.author.name) session.add(player) return player