def refresh_screen(mygame, player, menu): mygame.clear_screen() # print(Utils.magenta_bright(f"\t\t~+~ Welcome to {mygame.name} ~+~")) mygame.display_player_stats() mygame.display_board() if player.inventory.size() > 0: # If inventory is not empty print it items_by_type = {} for item_name in player.inventory.items_name(): item = player.inventory.get_item(item_name) if item.type in items_by_type.keys(): items_by_type[item.type]['cumulated_size'] += item.size() else: items_by_type[item.type] = { 'cumulated_size': item.size(), 'model': item.model, 'name': item.name, } count = 1 for k in items_by_type.keys(): print(f" {items_by_type[k]['model']} : \ {items_by_type[k]['cumulated_size']} ", end='') count += 1 if count == 5: count = 0 print("\n", end='') print("\n", end='') print( Utils.yellow_dim('\nWhere should ') + Utils.cyan_bright(player.name) + Utils.yellow_dim(' go?')) mygame.display_menu(menu) Utils.debug(f"Player stored position is ({player.pos[0]},{player.pos[1]})")
if edit_mode: print(Utils.green_bright("EDIT"), end='') else: print(Utils.red_bright('DELETE'), end='') print( f' | Board: {game.current_board().name} - {game.current_board().size} | Cursor @ {game.player.pos}' ) game.display_board() if len(object_history) > 10: del (object_history[0]) if current_menu == 'main': print('Item history:') cnt = 0 for o in object_history: print(f"{cnt}: {o.model}", end=' ') cnt += 1 print('') print(f'Current item: {current_object.model}') if not (current_menu == 'main' and menu_mode == 'hidden'): game.display_menu(current_menu, Constants.ORIENTATION_VERTICAL, 15) for m in dbg_messages: Utils.debug(m) for m in info_messages: Utils.info(m) for m in warn_messages: Utils.warn(m) if current_menu == 'boards_list': key = input('Enter your choice (and hit ENTER): ') else: key = Utils.get_key()
ui_board_void_cell=Utils.BLACK_SQUARE, # Cells with nothing inside are going to be black squares player_starting_position=[10,20] ) # Then create a player playerone = Player( model=Utils.yellow_bright('××') ) # Place it on the board myboard.place_item(playerone, 10,10) # Now let's display our board myboard.display() # And make a short loop that moves the player and display the board # WARNING: in real life we would use the Game object to manage the game and the screen for k in range(1,10,1): # Clear screen Utils.clear_screen() # Print a debug message Utils.debug(f'Round {k} player position is ({playerone.pos[0]},{playerone.pos[1]}) -- BEFORE moving') # Ask myboard to move playerone to the right by one cell myboard.move(playerone, Constants.RIGHT, 1 ) # print another debug message Utils.debug(f'Round {k} player position is now ({playerone.pos[0]},{playerone.pos[1]}) -- AFTER moving') # and display the board myboard.display() # Wait a second to let you admire the work! time.sleep(1)
'a': 'A hole.', 'k': ['hole'], }, { 'q': 'I have no feet, no hands, no wings, but I \ climb to the sky.\nWhat am I?', 'a': 'Smoke.', 'k': ['smoke'], }, { 'q': 'Why do mummies like Christmas so much?', 'a': 'Because of all the wrapping.', 'k': ['wrap'], }] while key != 'q': refresh_screen(game, p, current_menu) Utils.debug(f"Current game speed: {game_speed}") Utils.debug(f"Current menu: {current_menu}") key = Utils.get_key() if current_menu == 'main_menu': if key == 'w' or key == '8': game.move_player(cst.UP, 1) elif key == 's' or key == '2': game.move_player(cst.DOWN, 1) elif key == 'a' or key == '4': p.model = sprite_player['left'] game.move_player(cst.LEFT, 1) elif key == 'd' or key == '6': p.model = sprite_player['right'] game.move_player(cst.RIGHT, 1) elif key == '9':
# Now add the boards to the game so the Game object can manage them # the parameters of add_board() are a level number and a board. mygame.add_board(1, lvl1) mygame.add_board(2, lvl2) mygame.add_board(3, lvl3) # Now we also want our player to be managed by the game mygame.player = nazbrok # Now let's show a clean screen to our player mygame.clear_screen() # We haven't place nazbrok on any board, but that's ok because we are going # to use Game to manage the starting position of our player # First let's display nazbrok's position Utils.debug(f"Nazbrok is at position ({nazbrok.pos[0]}, {nazbrok.pos[0]})" f" -- BEFORE changing level") # Now the only thing we need is to change level mygame.change_level(1) # and Nazbrok is auto-magically at the starting position for our lvl1 board! Utils.debug(f"Nazbrok is at position ({nazbrok.pos[0]}, {nazbrok.pos[0]})" f" -- AFTER changing level to level 1") # Now let's display the current board mygame.current_board().display() # Let's wait a little countdown() # Now do it all again: clear the screen, print Nazbrok's position, change # level, print the new position and wait a little mygame.clear_screen()