def setup(self): self.setup_map("./maps/map_2/map.tmx") self.bg_sprites = [["walls", self.wall_list], ["floor", self.floor_list], ["deadly", self.deadly_list]] self.fg_sprites = [self.bullets, self.players] ## Parse Config File settings = parseconf.parsefile() # Player setups self.player1 = logic.Player(self, "sprites/duck_pixel.png", TILE_SCALING - 0.2, settings["p1_movement"], settings["p1_action"], 100, self.window.height / 2, settings["p1_name"], Vec2d(1, 0)) self.player2 = logic.Player( self, "sprites/duck_pixel_red.png", TILE_SCALING - 0.2, settings["p2_movement"], settings["p2_action"], self.window.width - 200, self.window.height / 2, settings["p2_name"], Vec2d(-1, 0)) self.agents = list() mode = settings["mode"] if mode != "PvP": self.player2.is_ai = True agent = ai_interface.Agent(settings["p2_ai"], self.player2) agent.observation = self.boardstate self.agents.append(agent) if mode == "EvE": self.player1.is_ai = True agent = ai_interface.Agent(settings["p1_ai"], self.player1) agent.observation = self.boardstate self.agents.append(agent) self.players.append(self.player1) self.players.append(self.player2) self.nonpassable.append(self.player1) self.nonpassable.append(self.player2) for player in self.players: # Physics engine currently only handles player-wall collisions player.physics_engine = arcade.PhysicsEngineSimple( player, self.nonpassable) for _ in range(len(self.players)): self.player_damage_timers.append(self.damage_intervall) ## Boardstate background setup for spritelist in self.bg_sprites: for sprite in spritelist[1]: x = [int(i * COORDINATE_MAPPING) for i in sprite.position] self.boardstate[x[0]][x[1]][0] = spritelist[0]
def test_get_allowed_fields(self): board = logic.Board() walter = logic.Player('Walter', 'white') peter = logic.Player('Peter', 'black') for square, i in [('outer', 0), ('mid', 1), ('outer', 2)]: board.move_piece(walter, new_field=logic.Field(square, i, walter)) board.move_piece(peter, new_field=logic.Field('outer', 1, peter)) allowed = board.get_allowed_fields(logic.Field('mid', 1, walter)) self.assertIn(logic.Field('mid', 0), allowed['mid']) self.assertIn(logic.Field('mid', 2), allowed['mid']) self.assertNotIn(logic.Field('outer', 1), allowed['outer'])
def test_is_in_mill(self): board = logic.Board() walter = logic.Player('Walter', 'white') for i in range(3): board.move_piece(walter, new_field=logic.Field('outer', i, walter)) for field in board.get_all_fields(walter)['outer']: self.assertTrue(board.is_in_mill(field)) field = logic.Field('mid', 1, walter) self.assertFalse(board.is_in_mill(field))
def data_received(self, data): message = json.loads(data.decode('utf8')) if not self.player: username = message.get('username', None) if not username: logging.error("No username from {}".format(self.peer)) self.transport.write('{"ERROR": "username please"}') return self.player = logic.Player(self, username) # TODO: broadcast self.player.incoming_message(message)
def game_loop(): crashed = False current_frame = "phase2" card_deck = logic.Card_deck() card_deck.shuffle_deck() player_info = logic.Player(card_deck) ai_info = logic.Player(card_deck) text1 = ("[H]it, [S]tand, [D]ouble down") text2 = ("[H]it, [S]tand") text3 = ("[C]ontinue, [Q]uit") text4 = ("Dealer won!") text5 = ("You won!") text6 = ("Tie!") text7 = ("Game over! [Q]uit" ) text_blank = "" text_var = text1 text_var2 = text_blank while not crashed: player_score = pygame_handler.pygame_text("Your score: " + str(player_info.score()), 40, 150, 500) player_balance = pygame_handler.pygame_text("Your balance: " + str(player_info.get_money()), 40, 200, 650) instructions = pygame_handler.pygame_text(text_var, 50, 375, 850) result = pygame_handler.pygame_text(text_var2, 90, 850, 700) for event in pygame.event.get(): starter_class.game_display.blit(background_image.get_image(), (0, 0)) instructions.display(starter_class.game_display) result.display(starter_class.game_display) player_score.display(starter_class.game_display) player_balance.display(starter_class.game_display) display_hand(player_info.get_hand()) if current_frame != "phase3" and current_frame != "phase4": ai_score = pygame_handler.pygame_text("Dealer's score: " + str(ai_info.ai_score()), 40, 850, 500) display_hand(ai_info.get_hand()[:1], 200) ai_score.display(starter_class.game_display) else: ai_score = pygame_handler.pygame_text("Dealer's score: " + str(ai_info.score()), 40, 850, 500) display_hand(ai_info.get_hand()[:], 200) ai_score.display(starter_class.game_display) if current_frame == "phase1": if card_deck.get_length() < 9: card_deck = logic.Card_deck() card_deck.shuffle_deck() else: card_deck = card_deck text_var2 = text_blank player_info = logic.Player(card_deck, player_info.get_money()) ai_info = logic.Player(card_deck) text_var = text1 current_frame = "phase2" pygame.display.update() if current_frame == "phase2": bet = logic.Bet(100) if len(player_info.get_hand()) == 2 and player_info.score() == 21: ai_info.set_hand() bet.add_bet(50) current_frame = "phase3" if event.type == KEYDOWN: if event.key == pygame.K_h: if len(player_info.get_hand()) < 10: player_info.hit() text_var = text2 if event.key == pygame.K_s: current_frame = "phase3" if event.key == pygame.K_d: bet.add_bet(100) player_info.hit() current_frame = "phase3" if player_info.score() > 21: current_frame = "phase3" if current_frame == "phase3": for i in range(2): if ai_info.score() < 17 and ai_info.score() < player_info.score() and player_info.score() <= 21: ai_info.hit() if player_info.score() > 21 and ai_info.score() <= 21: text_var2 = text4 player_info.decrease_money(bet.get_bet()) elif player_info.score() == ai_info.score(): text_var2 = text6 #player_info.increase_money(bet.get_bet()) elif player_info.score() <= 21 and ai_info.score() > 21: text_var2 = text5 player_info.increase_money(bet.get_bet()) elif player_info.score() > ai_info.score(): text_var2 = text5 player_info.increase_money(bet.get_bet()) #player_balance_var = player_info.get_money() elif player_info.score() < ai_info.score(): text_var2 = text4 player_info.decrease_money(bet.get_bet()) #player_balance_var = player_info.get_money() else: text_var2 = text6 current_frame = "phase4" if current_frame == "phase4": text_var = text3 display_hand(ai_info.get_hand()[:], 200) if player_info.get_money() > 50: if event.type == KEYDOWN: if event.key == K_q: crashed = True if event.key == K_c: current_frame = "phase1" else: text_var2 = text7 text_var = "" if event.type == KEYDOWN: if event.key == K_q: crashed = True if event.type == pygame.QUIT: crashed = True pygame.display.update()
def __init__(self, window: tk.Tk): self.player = logic.Player() self.window = window self.window['bg'] = self.DEFAULT_BG self.window.geometry('800x600') self.clicker_colors = [ _from_rgb((255, 255 - i, 255 - i)) for i in range(40, 255) if i % 40 == 0 ] self.upgrade_colors = [ _from_rgb((255 - i, 255 - i, 255)) for i in range(40, 255) if i % 40 == 0 ] self.main_label_text = tk.Label(self.window) self.auto_gain_text = tk.Label(self.window) self.clicker_buttons_text = [ tk.StringVar() for i in range(self.player.shop.NUMB_OF_CLICKERS + 1) ] self.clicker_left_text = [ tk.Label() for i in range(self.player.shop.NUMB_OF_CLICKERS + 1) ] self.clicker_buttons = [ tk.Button( self.window, padx="10", pady="10", bg=self.clicker_colors[i % len(self.clicker_colors)], textvariable=self.clicker_buttons_text[i], command=self.ButtonCommand(i, self.player, self.window, self.clicker_buttons_text[i], self.main_label_text).click_button) for i in range(self.player.shop.NUMB_OF_CLICKERS) ] self.main_button_gain = tk.Label() self.main_button = tk.Button(self.window, padx='50', pady='50', text='Click', command=self.click_main_button, bg='green') self.upgrade_buttons_text = [ tk.StringVar() for i in range(self.player.shop.NUMB_OF_CLICKERS + 1) ] self.upgrade_left_text = [ tk.Label() for i in range(self.player.shop.NUMB_OF_CLICKERS + 1) ] self.upgrade_buttons = [ tk.Button(self.window, padx="10", pady="10", bg=self.upgrade_colors[i % len(self.upgrade_colors)], textvariable=self.upgrade_buttons_text[i], command=self.ButtonCommand( i, self.player, self.window, self.upgrade_buttons_text[i], self.main_label_text, self.upgrade_left_text, self.clicker_left_text).click_upgrade) for i in range(self.player.shop.NUMB_OF_CLICKERS) ] self.main_upgrade = tk.Button(self.window, padx='40', pady='30', text='level 1', command=self.click_main_upgrade, bg=_from_rgb((0, 150, 0))) self.main_upgrade_cost = tk.Label() self.victory = tk.Button(self.window, padx='40', pady='20', text='100 000 to win', command=self.victory_func, bg='gold')