def _player_input(game_map):
    log.debug(f'_player_input function was caled')
    global player_position

    log.info(
        f"Your action : {[f'{key} - {val},' for key, val in _player_move_comand.items()]}"
    )
    action_type = int(input('-> '))

    result = True
    log.debug(
        f'_player_input: players action is {_player_move_comand[action_type]}')
    if action_type == 5:
        game_save(game_map)
    else:
        player_position_new = _player_move_finctions[action_type](
            player_position)
        cell_type = game_map[player_position_new[1]][player_position_new[0]]

        if cell_type == cell_treasure or cell_type == cell_trap:
            log.debug(f'_player_input: player is find a {cell_type}')
            result = False
        else:
            game_map[player_position[1]][player_position[0]] = cell_free
            player_position = player_position_new
            game_map[player_position[1]][player_position[0]] = cell_player
            log.debug(
                f'_player_input: players new position is x = {player_position[0]}, y = {player_position[1]}'
            )

    return result
Esempio n. 2
0
def _spell_game_state(game_map):
    global player_position

    for val in _player_move_finctions.values():
        player_neighbored_point = val(player_position)
        if game_map[player_neighbored_point[1]][
                player_neighbored_point[0]] == cell_trap:
            log.info('Trap is near')
        elif game_map[player_neighbored_point[1]][
                player_neighbored_point[0]] == cell_treasure:
            log.info('Treasure is near')
Esempio n. 3
0
    def logigng_param_and_result_of_function(*args, **kvargs):

        dec_log.debug(f'{func.__name__} params :')
        for param in args:
            dec_log.debug(param)
        for param in kvargs:
            dec_log.debug(param)

        result = func(*args, **kvargs)
        dec_log.debug(f'{func.__name__} return value : {result}')
        dec_log.debug(result)

        return result
def loop(game_map):
    log.debug(f'loop function was called')
    global player_position

    _spell_game_state(game_map)
    while _player_input(game_map):
        log.debug(f'loop: game loop is running')
        _spell_game_state(game_map)

    log.debug(f'loop: game loop was stoped')
    cell_type = game_map[player_position[1]][player_position[0]]
    if cell_type == cell_treasure:
        log.info('You WON!')
    else:
        log.info('You lose...')
Esempio n. 5
0
def new_map():
    log.debug(f'new_map function was called')
    game_map = [[cell_free for j in range(game_map_size + 2)]
                for i in range(game_map_size + 2)]

    for i in range(game_map_size + 2):
        game_map[i][0] = cell_trap
        game_map[0][i] = cell_trap

        game_map[i][game_map_size + 1] = cell_trap
        game_map[game_map_size + 1][i] = cell_trap

    for i in range((game_map_size**2) // 20):
        fill_free_cell(game_map, cell_trap)
        fill_free_cell(game_map, cell_trap)
        fill_free_cell(game_map, cell_treasure)

    return game_map
    def loop(self):

        self._print_the_spawn_location()
        while self.player.HP > 0 and self.player.score < 3:
            self._spell_game_state()
            try:
                players_action = self._player_input()
            except IndexError:
                log.error('Incorect input')
            else:
                if players_action in Player.move_types:
                    self.player.move(players_action)
                    self._proscess_player_move()
                elif players_action == 'Save game':
                    try:
                        self.save()
                    except Ellipsis as error:
                        log.error('Can not save game')
                        log.error(error)

        else:
            print(f'You {"Won" if self.player.score == 3 else "Lose"}')
            self.map_.set_cell_type(self.player.position,
                                    self.map_.cell_player)
            print(self)
Esempio n. 7
0
def find_player_position(game_map):
    log.debug(f'find_player_position function was called')
    for i in range(1, game_map_size + 2):
        for j in range(1, game_map_size + 2):
            if game_map[i][j] == cell_player:
                log.debug(
                    f'find_player_position: player position is x = {j}, y = {i}'
                )
                return [j, i]
    log.error(f'find_player_position: player wasn`t found')
Esempio n. 8
0
def fill_free_cell(game_map, cell_type):
    log.debug(
        f'fill_free_cell function was called wit cell type : {cell_type}')
    while (True):
        log.debug(f'looking for free cell')
        i = rint(1, game_map_size)
        j = rint(1, game_map_size)

        if game_map[i][j] == cell_free:
            game_map[i][j] = cell_type
            log.debug(
                f'free cell is is found with cordinate : x = {j}, y = {i}')
            return [j, i]
Esempio n. 9
0
    def start_end_wraper(*args, **kvargs):

        dec_log.debug(f'{func.__name__} : started')
        result = func(*args, **kvargs)
        dec_log.debug(f'{func.__name__} : ended')
        return result
def saved_game():
    global g_map
    log.debug('saved_game function was called')
    g_map = game_load()
    game.player_position = gmap.find_player_position(g_map)
def new_game():
    global g_map
    log.debug('new_game function was called')
    g_map = gmap.new_map()
    game.player_position = gmap.fill_free_cell(g_map, gmap.cell_player)
def new_game():
    global g_map
    log.debug('new_game function was called')
    g_map = gmap.new_map()
    game.player_position = gmap.fill_free_cell(g_map, gmap.cell_player)


def saved_game():
    global g_map
    log.debug('saved_game function was called')
    g_map = game_load()
    game.player_position = gmap.find_player_position(g_map)


while (True):
    log.debug('Main loop')
    player_answer = input("Start the Game? y/n : ")
    log.debug(f'Player amsver to "Start the Game? y/n : " is {player_answer}')

    if player_answer == 'y':
        player_answer = input('(1) new game or (2) saved game : ')
        log.debug(
            f'Player amsver to "(1) new game or (2) saved game : " is {player_answer}'
        )

        if player_answer == '1':
            new_game()
        elif player_answer == '2':
            saved_game()
        else:
            #To 'Start the Game?'