def test_win_game(): p = game.Player('Player1', '1') q = game.Player('Player2', '2') g = game.Game(p, q) for i in range(3): g.play(p, 1) g.play(q, 2) assert g.status == 'IN_PROGRESS' g.play(p, 1) assert g.status == 'DONE' assert g.winner == p
def test_game(): p = game.Player('Player1', '1') q = game.Player('Player2', '2') g = game.Game(p, q) with pytest.raises(game.OutOfTurnError): g.play(q, 0) move_number = g.play(p, 0) assert move_number == 0 with pytest.raises(game.OutOfTurnError): g.play(p, 0) move_number = g.play(q, 0) assert move_number == 1
def setUp(self): self.manager = game.Manager(game.Configuration()) # We'll create players in postiions 0, 2, 3, and 7 for idx in range(self.manager.config.max_players): self.manager.add_player(game.Player("name{}".format(idx), 0)) for idx in [1, 4, 5, 6, 8, 9]: self.manager.remove_player(idx)
def connected(): print("connected") if request.sid not in client_list: client_list.append(request.sid) socket.emit('server_connect', {'message': request.sid}) # tell the new player about the room socket.emit('init_room', { 'room_width': game.room.width, 'room_height': game.room.height }, room=request.sid) newChar = game.Player(request.sid) # tell everyone about the new player socket.emit( 'init_player', { 'sessionId': newChar.sessionId, 'x_position': newChar.x_position, 'y_position': newChar.y_position }) # tell the new player about everyone else for key, value in game.playerDict.items(): if value != newChar: socket.emit('init_player', { 'sessionId': key, 'x_position': value.x_position, 'y_position': value.y_position, 'hp': newChar.hp }, room=request.sid)
def main(): printHeadline() rolls = game.Rolls name = get_players_name() player1 = game.Player(name) player2 = game.Computer() run_game(player1, player2, rolls)
def __init__(self, cx, cy, px, py): self.field = [[game.Cell('grass') for i in range(cx)] for j in range(cy)] self.player = game.Player('P1', [px, py], 10) self.player.backpack.load_recipes('resources/recipes.txt') self.em = None self.inventory_opened = False self.actions = None
def setUp(self): self.manager = game.Manager(game.Configuration(ante=100)) # We'll create players in postiions 0, 1 for idx in range(2): self.manager.add_player(game.Player("name{}".format(idx), 500)) # Add the recorder last because we don't care about the add events. self.recorder = game.RecordingListener() self.manager.add_listener(self.recorder)
async def login(request): player = game.Player(core) return web.json_response({ "id": player.id, "token": _generate_token(player), "quote_to_find": player.quote_to_find.content, "suggestion": player.authors_suggestion.authors })
def setUp(self): self.manager = game.Manager(game.Configuration(ante=100)) # We'll create players in postiions 0, 2, 4 for idx in range(5): self.manager.add_player(game.Player("name{}".format(idx), 1000)) for idx in [1, 3]: self.manager.remove_player(idx) self.recorder = game.RecordingListener() self.manager.add_listener(self.recorder)
def test_game_victory_should_add_to_points(self): player_1 = game.Player('Mr Hero Man', 'player_1', 0) goldgame_ui.victory() expected = 1 actual = player_1.points self.assertEqual(actual, expected)
def setUp(self): ''' 2 of Hearts is the top card in deck after building the deck ''' self.player = game.Player("Bob") self.pile = game.Pile() self.deck = game.Deck() # Drew 2 of Hearts (top card) self.player.draw(self.deck, self.pile)
def handlemessage(originclient, message): splat = message.split(" "); if splat[0] == "CREATEROOM": room = Room(random.randint(1, 1)) #logica achter het gekozen id steken rooms[room.roomId] = room if splat[0] == "GETROOMS": send(originclient, json.dumps(rooms, cls=MyEncoder, indent=2)) if splat[0] == "JOINROOM": #JOINROOM roomid playername room = rooms.get(int(splat[1])) #handle null if room.join(game.Player(splat[2])): send(originclient, "you joined room ")
async def skills(self, ctx): player = game.Player(ctx.author) embed = self.create_embed(ctx.author, title="Character skills") skills = player.get_skills() for skill in skills: embed.add_field(name=skill, value=skills[skill]) await ctx.send(embed=embed)
async def me(self, ctx): player = game.Player(ctx.author) embed = self.create_embed(ctx.author, title="Character") attributes = player.get_attributes() for attribute in attributes: embed.add_field(name=attribute, value=attributes[attribute]) await ctx.send(embed=embed)
def initialize(self, config): self.manager = game.Manager(config) # We'll create players in postiions 0, 1, 2 for idx in range(3): self.manager.add_player(game.Player("name{}".format(idx), 1000)) self.manager.button_pos = 2 self.manager.start_game() self.assertEqual(0, self.manager.button_pos) self.manager.proceed() self.assertEqual(game.GameState.HOLE_CARDS_DEALT, self.manager.state)
def load_player(filename): name = os.path.basename(filename)[:-3] players_dir = os.path.dirname(filename) try: fp, pathname, description = imp.find_module(name, [players_dir]) p = imp.load_module(name, fp, pathname, description) move_function = p.move # Get module classes from imported modules except Exception as e: raise LoadError("Error loading player '{}': {}".format(name, e)) return game.Player(name, move_function)
def test_add_player(self): player = game.Player("myname", 1000) self.assertEqual(0, self.manager.add_player(player)) self.assertEqual("myname", self.manager.players[0].name) self.assertEqual(1000, self.manager.players[0].stack) self.assertEqual(0, self.manager.players[0].position) self.assertEqual(1, len(self.recorder.events)) self.assertEqual( "Event(EventType.PLAYER_ADDED, player=Player(myname, 1000, 0))", str(self.recorder.events[0]))
async def equipment(self, ctx): player = game.Player(ctx.author) embed = self.create_embed(ctx.author, title="Equipment") equipment_items = player.get_equipment() for part in equipment_items: embed.add_field(name=part, value=equipment_items[part].name) await ctx.send(embed=embed)
def set_options_for_new_map(self): '''Reads values from new game options and sets options for new map''' self.map_.size = self.new_game_options.map_size map_area = self.map_.size[0] * self.map_.size[1] self.map_.hex_number = int(self.new_game_options.hex_number / 100 * map_area) if self.new_game_options.players_number > self.map_.hex_number: self.new_game_options.players_number = self.map_.hex_number self.map_.players = [] self.map_.players.append(game.Player((255, 0, 0))) for player in range(self.new_game_options.players_number - 1): self.map_.players.append( game.Player((random.randrange(40, 215), random.randrange(40, 215), random.randrange(40, 215)))) self.gameplay.die_sides_number = self.new_game_options.die_sides_number self.gameplay.max_dice = self.new_game_options.max_dice_on_single_hex
def test_quit_game(): p = game.Player('Player1', '1') q = game.Player('Player2', '2') r = game.Player('Player3', '3') g = game.Game(p, q, r) assert g.status == 'IN_PROGRESS' g.quit(p) # can't play if you already quit with pytest.raises(ValueError): g.play(p, 0) # make sure other players can play g.play(q, 1) g.play(r, 1) # only 1 player left, so that player wins g.quit(q) assert g.status == 'DONE' assert g.winner == r
def main(): logging.basicConfig(level=logging.INFO) keyboard = controller.Keyboard() mouse = controller.Mouse() player = game.Player(keyboard, mouse) bobber_finder = get_bobber_finder() player.init() for i in range(20): print('attempt ' + str(i)) fishing(player, bobber_finder)
def setUp(self): self.manager = game.Manager(game.Configuration()) self.manager._deck_factory = in_order_deck_factory # We'll create players in postiions 0, 2, 4 for idx in range(5): self.manager.add_player(game.Player("name{}".format(idx), 0)) for idx in [1, 3]: self.manager.remove_player(idx) # Add the recorder last because we don't care about the add/remove events. self.recorder = game.RecordingListener() self.manager.add_listener(self.recorder) # we do long string diffs self.maxDiff = None
async def inventory(self, ctx): player = game.Player(ctx.author) inventory = player.get_inventory_contents() embed = self.create_embed( ctx.author, title="Inventory", ) for item in inventory: embed.add_field(name=f"{item.name} \"*{item.entity_id}*\"", value=item.desc) await ctx.send(embed=embed)
def test_remove_player(self): self.manager.add_player(game.Player("name0", 0)) self.manager.add_player(game.Player("name1", 1000)) self.manager.add_player(game.Player("name2", 2000)) # We clear the recorder here because we don't care what # happened before the thing we wanted to test. self.recorder.clear() removed = self.manager.remove_player(1) self.assertEqual("name1", removed.name) self.assertEqual(1000, removed.stack) self.assertEqual(1, removed.position) self.assertEqual(1, len(self.recorder.events)) self.assertEqual( "Event(EventType.PLAYER_REMOVED, player=Player(name1, 1000, 1))", str(self.recorder.events[0])) with self.assertRaises(game.NoSuchPlayerError): self.manager.remove_player(4) with self.assertRaises(game.NoSuchPlayerError): self.manager.remove_player(9999)
def main(): parser = argparse.ArgumentParser() parser.add_argument('commands', type=str, nargs='+') args = parser.parse_args(sys.argv[1:]) cwd = os.getcwd() players = [game.Player(i, cwd, cmd) for i, cmd in enumerate(args.commands)] g = game.Game(players) try: g.play() for p in g.players: print('Player {}: {}'.format(p.pk, p.wealth)) finally: for p in g.players: p.cleanup()
def __init__(self): pygame.init() players = [game.Player((255, 0, 0))] resolution = pygame.display.Info() self.window_size = (resolution.current_w, resolution.current_h) self.map_ = map.Map((5, 5), 10, players, 4, 32, self.window_size) self.map_.create_map() self.gameplay = game.Gameplay(self.map_, 6, 2000, 8) self.graphics = graphics.Graphics(self.map_, self.gameplay, self.window_size) self.event_handler = events.EventHandler(self.map_, self.graphics, self.gameplay)
def setUp(self): self.manager = game.Manager(game.Configuration(max_players=4, game_type=game.GameType.LIMIT, limits=[10,20], blinds=[5, 10])) self.manager._deck_factory = in_order_deck_factory # We'll create players in postiions 0, 1, 2 for idx in range(3): self.manager.add_player(game.Player("name{}".format(idx), 1000)) # Button will be advanced to 0 self.manager.button_pos = 3 self.recorder = game.RecordingListener() self.manager.add_listener(self.recorder) # we do long string diffs self.maxDiff = None
def start_game(player_count): players.clear() print("start game {} {} {} {}".format(pi.read(PLAYER0_HOOK_PIN), pi.read(PLAYER1_HOOK_PIN), pi.read(PLAYER2_HOOK_PIN), pi.read(PLAYER3_HOOK_PIN))) if (pi.read(PLAYER0_HOOK_PIN) == 1) or \ (pi.read(PLAYER1_HOOK_PIN) == 1) or \ (pi.read(PLAYER2_HOOK_PIN) == 1) or \ (pi.read(PLAYER3_HOOK_PIN) == 1): Text(app, text="All Phones Must Be On HOOK", size=65, font=font, grid=[0, 2], color=main_font_color, align='center') return clear_screen() message_index = randint(0, len(phrases) - 1) message = phrases[message_index] Text(app, text=message, size=font_size, font=font, color=phrase_color, grid=[0, 0, 3, 1], align='left') Text(app, text="1 - Undo 0 - Space", size=int(font_size / 2), font=font, color=phrase_color, grid=[2, 10], align='bottom') for i in range(player_count): print("creating player {}".format(i)) players.append(game.Player(i, app, message)) print("player count {}".format(len(players)))
def create_player(): """ Creates a new player based on JSON sent and adds the new player to the database. Associates based on logged in user_id. """ new_player_request = request.get_json() name = new_player_request['name'] player_type = new_player_request['type'] mutation_id = random.choice(game.Mutation.query.all()).mutation_id player_class = game.Player_Class.query.filter( game.Player_Class.name == player_type).one() new_player = game.Player(user_id=session['user_id'], name=name, mutation_id=mutation_id, alive=True, score=0, stats=player_class.base_stats, exp=0, level=1, player_class=player_class.class_id) game.db.session.add(new_player) game.db.session.commit() return "" # this does return nothing, but feels weird
def new_player_handler(client_socket): print("new_player_handler") player = game.Player() current_game = add_player_to_game(player) while True: if current_game.game_started: data = protocol_commands.pack_join_reply(keys.PLAY) client_socket.send(data) if (protocol_commands.is_it_ok(client_socket.recv(2))): threading.Thread(target=client_send_handler, args=[client_socket, player, current_game]).start() threading.Thread(target=client_recv_handler, args=[client_socket, player, current_game]).start() break else: client_socket.send(protocol_commands.pack_join_reply(keys.WAIT)) client_socket.recv(2)