def main(): p = Party() last_t = time.time() frame_time = 1.0 / 60 while True: cur_t = time.time() p.update(cur_t - last_t) update_t = time.time() - cur_t sleep_t = frame_time - update_t last_t = cur_t if sleep_t > 0: time.sleep(sleep_t)
def list_parties(): # try: return Party.jsonify_parties() # except Exception as e: return json.dumps({'err': str(e)})
def test_payoff_not_dividable(self): party = Party('party', ['@A', '@B', '@C']) party.waste('@A', 100) expected = [('@B', '@A', 33.33), ('@C', '@A', 33.33)] self.assertEqual(party.payoff(), expected)
def test_members(self): party = Party('party', ['@A', '@B', '@C']) self.assertEqual(party.members_list(), ['@A', '@B', '@C'])
class guildmaster: def __init__(self): """Start the game and create resources""" pygame.init() self.party = Party(self, abyss_temple, 1, 1) self.stats = GameStats(self) self.fighter = Fighter() self.mage = Mage() self.thief = Thief() self.abyss = abyss_temple() self.death_farm = death_farm() self.cuddle_cavern = cuddle_cavern() # self.characters = [Fighter(), Mage(), Thief()] # self.party_member = random.choice(self.characters) self.characters = [Fighter(), Mage(), Thief()] FPS = 30 fpsClock = pygame.time.Clock() fpsClock.tick(FPS) pygame.display.set_caption("Guild Master") def select_quest(self): """Ask the player where they want to quest to""" quest = input( f"Where do you want to go? The Abyss Temple (1), the Death Farm (2), or the Cuddle Cavern (3)?" ) if quest == '1': self.party.quest.name = self.abyss.name self.party.quest.difficulty = self.abyss.difficulty elif quest == '2': self.party.quest.name = self.death_farm.name self.party.quest.difficulty = self.death_farm.difficulty elif quest == '3': self.party.quest.name = self.cuddle_cavern.name self.party.quest.difficulty = self.cuddle_cavern.difficulty else: print(f"Fine, be a smart ass!") quit() def game_loop(self): """"Main game-play loop""" print(f"Let's Play!") while True: self.select_quest() print(f"You head out on your Quest to the {self.party.quest.name}") # Figure out the party's stats self.calc_party_stats() # Party takes damage for _ in range(self.party.quest.difficulty): if random.randrange(0, 21) > self.party.health: self.party_member_takes_damage() if not self.characters: break if random.randrange(0, 21) > self.party.morale: self.party_member_takes_spririt_damage() if not self.characters: break # Lets you know who is in the party for character in self.characters: print( f"{character.name} at {character.injury} HP and {character.resolve}" ) # Ends the game with defeat if you have no on in party self.party.abandon_quest() if self.party.abandon is True: print("You have failed the quest!") quit() else: print("You have completed the quest!") retire = input("Would you like to retire? (Y/N)").upper() if retire == 'Y': quit() def calc_party_stats(self): """Calculate's the party's stats using the characters chosen""" self.party.health = self.fighter.ferocity self.party.morale = self.mage.trickery def party_member_takes_damage(self): """Party member suffers some damage""" party_member = random.choice(self.characters) print("Your party consists of:") for character in self.characters: print( f"{character.name} at {character.injury} HP and {character.resolve}" ) party_member.take_damage() if party_member.char_lost(): self.characters.remove(party_member) self.party.members -= 1 def party_member_takes_spririt_damage(self): """Party member suffers some damage""" party_member = random.choice(self.characters) print("Your party consists of:") for character in self.characters: print( f"{character.name} at {character.injury} HP and {character.resolve}" ) party_member.lose_spirit() if party_member.char_lost(): self.characters.remove(party_member) self.party.members -= 1
N = 100 # threshold M = 0 # 'uninitialized' modulo parties = [] try: n = int(input("How many Parties would you like to create: ")) if (n <= 2): raise Exception("Error! Please create more than 2 Parties.") else: # Initialize modulo M = n * N # Create parties print("\n---------- Creating {} Parties ----------\n".format(n)) for i in range(0, n): parties.append(Party("Party_" + str(i), n, M)) # Secret sharing for i in range(0, n): for j in range(0, n): parties[j].give_random_value(parties[i].get_random_value(j)) # Share column sums for i in range(0, n): for j in range(0, n): parties[i].give_column_sum(parties[j].get_column_sum()) # Validate function output print("\n---------- Computing Common Function f(x) ----------\n") for party in parties: print("{} has computed f(x) = {}".format(party.name,
def generate_parties(self, n): for i in range(n): name = "P" + format(i, 'd') self.parties.append(Party(self, name, i)) self.log.write("Created party: " + name) self.tracker.add_party(name)
def spawn_party(self, id_num, api_secrets): print "api_secrets: ", api_secrets party = Party.spawn(self, id_num, api_secrets) self.parties_list.append(party) self.parties_len += 1 return (party)
def create_party(u_id, party_name, party_location): # try: new_party = Party(user_map[u_id], party_name, party_location) return json.dumps({'party_id': new_party.party_id}) # except Exception as e: return json.dumps({'err': str(e)})
def party(name, members: list, sink=Service(), **kwargs): kwargs['chat_data']['party'] = Party(name, members) sink('🍾 💃 🕺 Вечерина {} начинается!'.format(name))