Exemple #1
0
g = Game()

b = g.load_board('hac-maps/kneighbors.json',1)


g.player = Player(model=Sprites.FLYING_SAUCER,name='player')
g.change_level(1)

key = None

while True:
    if key == 'w':
        g.move_player(Constants.UP,1)
    elif key == 's':
        g.move_player(Constants.DOWN,1)
    elif key == 'a':
        g.move_player(Constants.LEFT,1)
    elif key == 'd':
        g.move_player(Constants.RIGHT,1)
    elif key == 'q':
        break
    g.clear_screen()
    g.display_board()
    for i in g.neighbors(1):
        print(f'Player: {i.name} ({i.pos[0]},{i.pos[1]})')
    
    for i in g.neighbors(1, g.current_board().item(7,7) ):
        print(f'NPC: {i.name} ({i.pos[0]},{i.pos[1]})')

    key = Utils.get_key()
Exemple #2
0
              size=[width, height],
              ui_borders=Utils.WHITE_SQUARE,
              ui_board_void_cell=Utils.BLACK_SQUARE))
    is_modified = True


# Main program
game = Game()
current_file = ''
game.player = Player(model='[]')
key = 'None'
current_object = BoardItemVoid(model='None')
object_history = []
current_menu = 'main'
while True:
    game.clear_screen()
    print(
        Utils.cyan_bright("HAC-GAME-LIB - EDITOR v" +
                          Constants.HAC_GAME_LIB_VERSION))

    print('Looking for existing maps in selected directories...', end='')
    with open('directories.json') as paths:
        directories = json.load(paths)
        hmaps = []
        try:
            for directory in directories:
                files = [f'{directory}/{f}' for f in os.listdir(directory)]
                hmaps += files
            print(Utils.green('OK'))
        except FileNotFoundError as e:
            print(Utils.red('KO'))
mygame.add_menu_entry("main_menu", "2", Utils.magenta_bright(option_magenta))
mygame.add_menu_entry("main_menu", "q", "Quit game")

mygame.add_menu_entry("help_menu", None, "---------")
mygame.add_menu_entry("help_menu", None, "Help Menu")
mygame.add_menu_entry("help_menu", None, "---------")
mygame.add_menu_entry("help_menu", "j", "Random help menu")
mygame.add_menu_entry("help_menu", "b", "Back to main menu")

# let's set a variable that hold the current menu category (for navigation)
current_menu = "main_menu"
# Now let's make a loop to dynamically navigate in the menu
key = None
while True:
    # clear screen
    mygame.clear_screen()

    # First print the message is something is in it the variable
    if message is not None:
        print(message)
        # We don't want to print the message more than once, so we put
        # the message to None once it's printed.
        message = None

    # Now let's display the main_menu
    mygame.display_menu(current_menu)

    # Take user input
    key = input("> ")

    if key == "1" or key == "2" or key == "j":