0

我正在使用 python-tocd roguelike 引擎制作一个 roguelike 游戏。我的游戏基于 python libtcod roguelike 教程。

我正在制作一个用于生成地图的常量列表

game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'],
                  constants['map_width'], constants['map_height'],entities,player,
                  constants['maze_min_size'], constants['max_maze_rooms'], ['maze_max_size'])

现在我在函数中使用一些代码来确定房间的大小。

for r in range(max_rooms):
    # random width and height
    w = randint(room_max_size, room_min_size)
    h = randint(room_max_size, room_min_size)

    # random position without going out of the boundaries of the map
    x = randint(0, map_width - w - 1)
    y = randint(0, map_height - h - 1)

我在这里定义了变量

map_width = 80
map_height = 45

room_max_size = 10
room_min_size = 6
max_rooms = 30

现在当我启动游戏时,会出现这种情况?

  File "C:/Users/Al Abraham/Documents/CaveRL/CaveRL/engine.py", line 466, in <module>
    main()
  File "C:/Users/Al Abraham/Documents/CaveRL/CaveRL/engine.py", line 445, in main
    player, entities, game_map, message_log, game_state, ggender = get_game_variables(constants)
  File "C:\Users\Al Abraham\Documents\CaveRL\CaveRL\initialize_new_game.py", line 115, in get_game_variables
    constants['maze_min_size'], constants['max_maze_rooms'], ['maze_max_size'])
  File "C:\Users\Al Abraham\Documents\CaveRL\CaveRL\map_objects\game_map.py", line 110, in make_map
    w = randint(room_max_size, room_min_size)
  File "C:\Python37\lib\random.py", line 222, in randint
    return self.randrange(a, b+1)
  File "C:\Python37\lib\random.py", line 184, in randrange
    istart = _int(start)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

我应该怎么办?

4

1 回答 1

0

当您使用 int() 函数时,您必须有一个字符串或某个数字。这个错误的意思是至少你的一个参数是一个列表,而不是一个数字。

您应该检查声明“w”变量的行,看来问题的根源来自 room_max_size 或 room_min_size。

于 2018-09-09T01:37:04.287 回答