def setUp(self): self.g = Game() self.p1 = Player("u1", "player1", INITIAL_CHIPS) self.p2 = Player("u2", "player2", INITIAL_CHIPS) self.p3 = Player("u3", "player3", INITIAL_CHIPS) self.players = list(filter(lambda p: not p.is_leaving(), [self.p1, self.p2, self.p3])) for player in self.players: player.set_normal() self.g.start(self.players, 20, 1)
def pult_castles_callback(bot, update, user_data): data = update.callback_query.data chat_id = update.callback_query.message.chat_id status = pults_statuses.get(chat_id) telegram_id = update.callback_query.from_user.id if status is None: logging.warning("status is None for {}".format( update.callback_query.message.chat_id)) status = { '🍁': [], '☘': [], '🖤': [], '🐢': [], '🦇': [], '🌹': [], '🍆': [] } pults_statuses.update({chat_id: status}) player = Player(telegram_id) if player.update_from_database() == 1: bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text="Ваш профиль не найден в базе данных", show_alert=True) return tag = None for guild_tag, guild_chat_id in list(guilds_chat_ids.items()): if guild_chat_id == chat_id: tag = guild_tag break if tag is None: logging.warning("Guild tag for damage pult is None") else: if player.guild != tag: bot.answerCallbackQuery(callback_query_id=update.callback_query.id, text="Вы не в этой гильдии!", show_alert=True) return for players_list in list(status.values()): if player in players_list: players_list.remove(player) players_list = list(status.values())[int(data[2])] players_list.append(player) reply_markup, response = rebuild_pult("change castle", context=status, user_data=user_data) edit_pult_message(bot, chat_id=chat_id, message_id=update.callback_query.message.message_id, text=response, reply_markup=reply_markup, callback_query_id=update.callback_query.id)
def test_stake(self): player = Player(100) self.assertEqual(player.balance, 100) self.assertEqual(player.staked, 0) player.stake(50) self.assertEqual(player.balance, 50) self.assertEqual(player.staked, 50) with self.assertRaises(ValueError): player.stake(-1) with self.assertRaises(ValueError): player.stake(51)
def test_deposit(self): player = Player(5000) player.deposit(100) self.assertEqual(player.balance, 5100) with self.assertRaises(ValueError): player.deposit(-100)
def main_game(): """Función principal del juego""" # Guardar posicion global tnow, mx, my, t0, str_time, stats, badge, time_delta contador = 0 moving = False running = True # Activador del menu der = 0 # Restableciendo el movimiento. player = Player(pygame.image.load(asset('assets/img', 'player-anim.png')), (W // 2, H // 2)) sprites = YAwareGroup( player, Actor(pygame.image.load(asset('assets/img', 'player-anim.png')), (W // 2, H // 2))) # player_collider = pygame.sprite.Group(player.collide_rect) player_group = pygame.sprite.Group(player) #Cargando sistema de dialogos? while running: screen.fill('black') # Renderizar el piso bg.update(screen, (player.bg[0], player.bg[1])) # Moviendo tiendas Loop Gral for id2, imp in enumerate(bg.list_imp): store_pos = (imp[0] + player.bg[0], imp[1] + player.bg[1]) tot_price = [] tot_items = [] for id, store in enumerate(bg.list_store): if id == id2: store.movement(store_pos) #costo total de la tienda tot_price.append(store.vars['total_store']) tot_items.append(store.vars['total_items']) # print(f'Tienda: {id} - {tot_items}') # print(f'player {tot_price}') for id3, store_bg in enumerate(bg.list_store_bg): if id2 == id3: store_bg.movement(store_pos) time_delta = clock.tick(60) / 1000.0 # dialogue = DialogueBox() stats['frame_counter'] += 1 # Estadisticas active_stats() #posicion global del mouse mouse_pos = pygame.mouse.get_pos() for event in pygame.event.get(): # Enviando eventos a dialogue # Creando loop de mapa stores player.get_event(event) for store in bg.list_store: store.get_event(event) # store2.get_event(event) if event.type == QUIT: quit() if event.type == KEYDOWN: if event.key == K_ESCAPE and key_press['F4_key'] == True: # stores_vars = [] # for i in len(store_group.spritedict): # stores_vars.append(store_group.spritedict[i]) # with open('storevars.json',"w") as f: # json.dump(stores_vars, f, indent=4, sort_keys=True) print('Guardando el juego!!! Savegame!!! ;)') print('####################################\n') with open( '/home/restor/Documents/game-develop/mk2/savegame.json', "w") as f: game_dump = [] game_dump.append('Player vars') game_dump.append(player.vars) game_dump.append('Player items') game_dump.append(player.items.list) for store in bg.list_store: # game_dump.append(player.exis) game_dump.append(f'Store {(store)} vars') # game_dump.append(store2.vars) # game_dump.append('Store 2 vars') game_dump.append(store.vars) game_dump.append(store.items.list) json.dump(game_dump, f, indent=4, sort_keys=True) if event.key == K_ESCAPE: key_press["TAB_key"] = False audio_effect('menu') quit() main_menu() # Movimiento del personaje. if event.key in (K_UP, K_w): player.vars['up'] = True key_press["TAB_key"] = False if event.key in (K_DOWN, K_s): player.vars['down'] = True key_press["TAB_key"] = False if event.key in (K_LEFT, K_a): player.vars['left'] = True key_press["TAB_key"] = False if event.key in (K_RIGHT, K_d): player.vars['right'] = True key_press["TAB_key"] = False elif event.type == KEYUP: if event.key in (K_UP, K_w): player.vars['up'] = False if event.key in (K_DOWN, K_s): player.vars['down'] = False if event.key in (K_LEFT, K_a): player.vars['left'] = False if event.key in (K_RIGHT, K_d): player.vars['right'] = False # resetear el tiempo if event.key == K_F5: # Reset Time key_press["F5_key"] = True tnow[1] = False # Abrir el menu transparente, crear un evento de menus.... if event.key == K_TAB and key_press["TAB_key"] == False: key_press["TAB_key"] = True elif event.key == K_TAB and key_press["TAB_key"]: key_press["TAB_key"] = False # Abctivar-Descartivar estadisticas if event.key == K_F4 and key_press["F4_key"] == False: key_press["F4_key"] = True elif event.key == K_F4 and key_press["F4_key"]: key_press["F4_key"] = False # # Moviendo la rueda del raton # if event.type == MOUSEBUTTONDOWN: # if event.button == 4: # contador += 1 # print('adelante'+ str(contador)) # elif event.button == 5: # contador += 1 # print('atras' + str(contador)) if event.type == MOUSEBUTTONDOWN and key_press["F4_key"]: if player.rect.collidepoint(event.pos): print('player') moving = True for id, store in enumerate(bg.list_store): if store.rect.collidepoint(event.pos): moving = True print('shop', id) # if store2.rect.collidepoint(event.pos): # moving = True # print('shop2') if event.type == MOUSEBUTTONUP and key_press["F4_key"]: moving = False elif event.type == MOUSEMOTION and moving and key_press["F4_key"]: #Moviendo direccion del personaje con el mouse if player.rect.collidepoint(event.pos): player.control(event.rel[0], event.rel[1]) if event.rel[0] > 0: player.vars['last_dir'] = 'right' if event.rel[0] < 0: player.vars['last_dir'] = 'left' if event.rel[1] > 0: player.vars['last_dir'] = 'down' if event.rel[1] < 0: player.vars['last_dir'] = 'up' # interaction(player.rect) for store in bg.list_store: if store.rect.collidepoint(event.pos): store.control(event.rel[0], event.rel[1]) for store_bg in bg.list_store_bg: if store.rect.collidepoint(event.pos): store_bg.control(event.rel[0], event.rel[1]) # elif store2.rect.collidepoint(event.pos): # store2.control(event.rel[0],event.rel[1]) # store_bg2.control(event.rel[0],event.rel[1]) # print(event.rel) # Iniciando el evento particulas if event.type == PARTICLE_EVENT: particle1.add_particles([player.rect.x, player.rect.y]) #Eventos de gui ui_manager.process_events(event) if key_press['F4_key']: for store in bg.list_store: store.interaction() for store_bg in bg.list_store_bg: store_bg.interaction() player.interaction() # Desactivar particulas # particle1.emit() run_time() # Checar posision y desplazamiento... # for x, store in enumerate(bg.list_store): # for y, imp in enumerate(bg.list_imp): # store.rect.x = (x*128)+imp[0] # store.rect.y = (y*128)+imp[1] # print(imp, store.rect) # store.update(store.control(player.bg[0], player.bg[1])) # store2.update(store2.control(player.bg[0], player.bg[1])) # renderizar las tiendas bg.store_group.update() bg.store_group.draw(screen) # renderizar jugador player_group.update() player_group.draw(screen) # sprites.update() # sprites.draw(screen) # def movement(): # movex = store.rect.x + player.bg[0] # movey = store.rect.y + player.bg[1] # pos = [movex, movey] # store.rect.move_ip(movex, movey) # return pos # print(player.bg) for id, store_bg in enumerate(bg.list_store_bg): colliderect = pygame.Rect.colliderect(player.collide_rect, store_bg.rect) if colliderect: for id2, store in enumerate(bg.list_store): if id == id2: store.dialogue_box() # Haz tu magia... ;) player.dialogue_box() elif not colliderect: # Reiniciando el contador aleatorio de badges. badge = ActionBadges() # audio_effect('menu', 0.5) # #crear efecto dia noche... # daynight = pygame.Surface([W, H], pygame.SRCALPHA, 32) # daynight.set_colorkey('white') # daynight = daynight.convert_alpha() # Abrir menu items if key_press["TAB_key"]: menu.show() # number = 3 # for x in range(number): # for y in range(number): # pygame.draw.rect(screen, 'orange', ((x*256),(y*256), 128, 128), 1) # Renderizando la interfaz de usuario statistic = Stats() # Agregando items del jugador a las tiendas tot_price.append(player.vars['total_store']) tot_items.append(player.vars['total_items']) player_tot = player.vars['total_items'] print(f'Player {player_tot}') ui.gui(sum_totals(tot_price), sum_totals(tot_items)) #Renderizar particulas time_control() pygame.display.update()
from libs.ui import * from libs.player import Player ui.clear() print ''' _____ _ | __ \ | | | |__) |__ _ __ _ _ __ __ _ _ __ ___ | | __ | _ // _` |/ _` | '_ \ / _` | '__/ _ \| |/ / | | \ \ (_| | (_| | | | | (_| | | | (_) | < |_| \_\__,_|\__, |_| |_|\__,_|_| \___/|_|\_\\ __/ | |___/ By Ben ''' ui.mes('Training Grounds Receptionist', ['Hello, you look to be new here.', 'What is your name?']) current = Player() while current.name == '' or ('/' in current.name) or ('\\' in current.name): current.name = raw_input(ui.blue('[You]') + ' My name is ') if current.is_archived(): current.load() else: from libs.training_ground import TrainingGround TrainingGround.run(current)
def test_insure(self): player = Player(100) self.assertEqual(player.balance, 100) self.assertEqual(player.staked, 0) player.stake(50) player.insure() # insure for 25 self.assertEqual(player.balance, 25) self.assertEqual(player.staked, 50) self.assertEqual(player.insured, True) with self.assertRaises(ValueError): player.insure() # already insured player = Player(100) player.stake(100) with self.assertRaises(ValueError): player.insure() # insufficient funds to insure
import getpass from libs.card import Card from libs.deck import Deck from libs.hand import Hand from libs.player import Player house = Player(0) user = getpass.getuser() print('Welcome to Terminal Casino') deposit = input( 'How much would you like to play with today {}? £'.format(user)) player = Player(int(deposit)) print('Joining a Blackjack table') deck = Deck(8) deck.shuffle() while (player.balance > 0): # start a new round # get 2 cards for house house_hand = Hand() h1 = deck.pick() h2 = deck.pick() house_hand.dealt_card(h1) house_hand.dealt_card(h2) # serve 2 cards for user player.hands = [] c1 = deck.pick() c2 = deck.pick()
else: import os from libs.ui import * from libs.player import Player ui.clear() print ''' _____ _ | __ \ | | | |__) |__ _ __ _ _ __ __ _ _ __ ___ | | __ | _ // _` |/ _` | '_ \ / _` | '__/ _ \| |/ / | | \ \ (_| | (_| | | | | (_| | | | (_) | < |_| \_\__,_|\__, |_| |_|\__,_|_| \___/|_|\_\\ __/ | |___/ By Ben ''' ui.mes('Training Grounds Receptionist', ['Hello, you look to be new here.', 'What is your name?']) current = Player() while current.name == '' or ('/' in current.name) or ('\\' in current.name): current.name = raw_input(ui.blue('[You]') + ' My name is ') if current.is_archived(): current.load() else: from libs.training_ground import TrainingGround TrainingGround.run(current)