def handle_packet(packet_id, data_buffer): if packet_id == util.PACKET_SPAWN: try: player_id = data_buffer.readSByte() owned = data_buffer.readByte() x = data_buffer.readShort() y = data_buffer.readShort() # clear the buffer data_buffer.clear() except: return if owned: # create a new player instance as an owned object player = main.Player(player_id, True) #player_group.add(player) #player_group.center(player.rect.center) else: player = main.Player(player_id, False) player.x = x player.y = y players[player_id] = player elif packet_id == util.PACKET_DESPAWN: try: player_id = data_buffer.readSByte() # clear the buffer data_buffer.clear() except: return if player_id not in players: return del players[player_id] elif packet_id == util.PACKET_POSITION_UPDATE: try: player_id = data_buffer.readSByte() x = data_buffer.readShort() y = data_buffer.readShort() # clear the buffer data_buffer.clear() except: return if player_id not in players: return player = players[player_id] player.x = x player.y = y
def test_parse_player_info_happy_path(self) -> None: names = ["Bob", "Alice"] num_players = len(names) expected_response = [ main.Player("Bob"), main.Player("Alice"), ] with patch("builtins.input", side_effect=names): player_info = main.parse_player_info(num_players) for player, expected in zip(player_info, expected_response): self.assertEqual(player.name, expected.name) self.assertListEqual(player.frames, [])
def test_hand_qualified(self): name = 'test player' player = main.Player(name) hand = main.Hand(player) die_a = main.Die() hand.keep_roll(die_a.roll()) result = hand.qualified() self.assertEqual(result, False)
def test_hand_display_hand_empty(self): name = 'test player' player = main.Player(name) hand = main.Hand(player) result = io.StringIO() sys.stdout = result hand.display_hand() result = result.getvalue().rstrip() self.assertEqual(result, '[empty]')
def test_second_player_wins(): player1 = main.Player("Alice") player2 = main.Player("Bob") player1.take_card(main.Card(main.Suit.Spades, main.Rank._2)) player1.take_card(main.Card(main.Suit.Diamonds, main.Rank._5)) player1.take_card(main.Card(main.Suit.Spades, main.Rank.King)) player2.take_card(main.Card(main.Suit.Diamonds, main.Rank._2)) player2.take_card(main.Card(main.Suit.Diamonds, main.Rank._4)) player2.take_card(main.Card(main.Suit.Spades, main.Rank.King)) game = main.Game() winner = game.how_wins(player1, player2) winner.print() assert winner == player2, "test second player wins"
def test_bank_tie(self): name = 'test player' player = main.Player(name) result = main.Bank(player) initial_total = result.total ante = 10 result.ante = ante result.tie() self.assertEqual(initial_total, result.total) self.assertEqual(result.ante, 0)
def test_hand_keep_roll(self): name = 'test player' player = main.Player(name) result = main.Hand(player) die_a = main.Die() die_b = main.Die() die_c = main.Die() result.keep_roll(die_a.roll()) result.keep_roll(die_b.roll()) result.keep_roll(die_c.roll()) self.assertEqual(len(result.rolls), 3)
def test_hand_display_hand_not_empty(self): name = 'test player' player = main.Player(name) hand = main.Hand(player) die_a = main.Die() die_b = main.Die() hand.keep_roll(die_a.roll()) hand.keep_roll(die_a.roll()) result = io.StringIO() sys.stdout = result hand.display_hand() result = result.getvalue().rstrip() self.assertEqual(result.count('o'), sum(hand.rolls))
def test_get_player_score(self) -> None: player = main.Player("Bob") game_results = [ ("X-X-X-X-X-X-X-X-X-X,X,X", 300), # All Strikes ("X-X-X-X-X-X-5,2-X-X-X,X,X", 259), # Mostly Strikes with one normal frame ("0,0-0,0-0,0-0,0-0,0-0,0-0,0-0,0-0,0-0,0", 0), # All gutter balls ("2,/-2,/-2,/-2,/-2,/-2,/-2,/-2,/-2,/-2,/,2", 120), # All Spares ("4,5-5,4-3,6-2,7-0,9-6,3-8,1-1,8-9,0-7,2", 90), # All open frames ( "0,/-1,/-2,/-3,/-4,/-5,/-6,/-7,/-8,/-9,/,X", 155, ), # All spares with a final strike ] game = main.Game([]) for result, expected in game_results: frames = self._parse_frames(result) player.frames = frames score = game.get_player_score(player) self.assertEqual(score, expected)
def test_hand_calc_score(self): name = 'test player' player = main.Player(name) hand = main.Hand(player) die_a = main.Die() hand.keep_roll(die_a.roll()) hand.calc_score() result = hand.score #self.assertEqual(result, 0) die_b = main.Die() die_c = main.Die() die_d = main.Die() hand.keep_roll(die_b.roll()) hand.keep_roll(die_c.roll()) hand.calc_score() result = hand.score if 1 in hand.rolls and 4 in hand.rolls: self.assertIn(result, hand.rolls) else: self.assertEqual(result, 0)
def test_enemy_movement(self): player = main.Player() main.n_enemy = main.Enemy(1) main.enemy_movement(pygame.display.set_mode(main.RESOLUTION), player) self.assertEqual(main.n_enemy.pos_y, -64)
def setUp(self): player1 = main.Player() self.n_bullet = main.Bullet(player1)
def decode_player(dict_): if "name" in dict_: ply = main.Player(dict_["name"], dict_["business"]) return ply
def test_init_balance_value_given(self): player = main.Player('test2', 2) self.assertEqual(player.balance, 2)
def test_init_default_balance(self): player = main.Player('test') self.assertEqual(player.balance, 1000)
def test_bank_creation(self): name = 'test player' player = main.Player(name) result = main.Bank(player) self.assertEqual(result.player, player) self.assertEqual(result.ante, 0)
import main print("Welcome to BlackJack") replay = False game_on = True starting_money = main.Account(1000) deck = main.Deck() deck.shuffle() bob = main.Player("Bob") dealer = main.Player("Dealer") bet = False #card = main.Card(bob.hand) while game_on == True or replay == True: bet = False if replay == True: deck = main.Deck() deck.shuffle() bob.hand = [] dealer.hand = [] while bet == False: global amount amount = input("Please state your bet: ") try: starting_money.bet(int(amount)) starting_money.displayBalance() if int(amount) <= starting_money.balance: bet = True except:
LIGHT_CELL = (232, 208, 170) DARK_CELL = (166, 125, 93) FONT_SIZE = RESOLUTION // FIELD_SIZE + FIELD_SIZE CELL_SIZE = RESOLUTION // FIELD_SIZE # Create Window pygame.init() pygame.mixer.init() screen = pygame.display.set_mode((RESOLUTION, RESOLUTION)) pygame.display.set_caption("Checkers") pygame.display.set_icon(pygame.image.load("Icon.ico")) clock = pygame.time.Clock() field = main.Field(FIELD_SIZE) player1 = main.Player(field, white=True) player2 = main.Player(field, white=False) current_player = player1 MAIN_FONT = pygame.font.SysFont('Arial Bold', FONT_SIZE) def test(): new_field = [[0 for _ in range(FIELD_SIZE)] for _ in range(FIELD_SIZE)] new_field[0][5] = 3 new_field[5][4] = 2 new_field[2][3] = 2 new_field[1][2] = 2 new_field[5][2] = 2 # new_field[8][7] = 3 field.field = new_field
def test_hand_creation(self): name = 'test player' player = main.Player(name) result = main.Hand(player) self.assertEqual(result.player, player) self.assertEqual(result.score, 0)
def test_player_creation(self): name = 'test player' result = main.Player(name) self.assertEqual(result.name, name)
print "\nYou've mastered the use of Mermaid Man's utility belt and have shrunken " print "down to the size of a single cell. Using this ability, you have been allowed " print "to enter my brain and search for whatever you wish. Luckily for you, " print "my brain has been compartmentalized into four areas that you will discover " print "as you explore. Have fun, press enter to continue!\n" raw_input() import main from brain import area_object try_again = "" while try_again.lower() != "n": player = main.Player(area_object, 'brain') while player.is_alive: player.run_turn() try_again = raw_input("\nTry again? Y or N\n\n")
calls bring over action :return: updates text box """ if self.action_allowed: text = player.bring_item(random.choice(cats)) self.update_text(text) self.cat_loop() def update_text(self, text): """ updates text field :param text: the text to be added :return: updates the text box in root """ self.action_field.insert(INSERT, text) self.action_field.see(END) cats = [] player = main.Player() app = Window(root) # set window title root.wm_title("Mia's Cat House") # show window root.geometry("640x400") root.mainloop()
# (C) mishgribushenkov import main game = main.Game() level1 = main.Level(game, '1.png', '1.jpeg') game.set_level(0) player_sht = main.Spritesheet('player.png', 8, 4) enemy_sht = main.Spritesheet('enemy.png', 8, 4) player = main.Player(level1, 10, 10, st_velocity=4, delay=2) player.add_animation('walk_right', player_sht, [0, 1, 2, 3, 4, 5, 6, 7]) player.add_animation('walk_left', player_sht, [16, 17, 18, 19, 20, 21, 22, 23]) player.add_animation('jump_right', player_sht, [24, 25]) player.add_animation('jump_left', player_sht, [8, 9]) player.add_animation('stay_right', player_sht, [11]) player.add_animation('stay_left', player_sht, [27]) player.add_animation('jump_right', player_sht, [8, 9]) player.add_animation('jump_left', player_sht, [24, 25]) player.add_animation('fall_right', player_sht, [10]) player.add_animation('fall_left', player_sht, [26]) player.add_animation('land_right', player_sht, [11, 12, 9]) player.add_animation('land_left', player_sht, [27, 28, 25]) player.set_animation('walk_right') level1.sprites.add(player) enemy = main.Enemy(level1, 200, 10, st_velocity=4, delay=2) enemy.add_animation('walk_right', enemy_sht, [0, 1, 2, 3, 4, 5, 6, 7])