地牢爬行-地图

时间:2018-07-03 14:06:01

标签: python dictionary random pygame

网络上的许多教程都指导我如何创建一个随机生成的,具有不同大小房间的地图等。我不想要这个,我想要一个绑定Isaac样式的地图,其中每个房间都是相同大小,并且是唯一的屏幕上的东西。

因此,我试图找到一种生成地图的方法,即从房间游泳池中挑选出一组说说8-10个随机选择的房间并将其分组以创建地图。

我曾经尝试过这样做,但还没有走得很远。这是我用来使事物随机化的代码

def main():

rooms = []

room = Room1()
rooms.append(room)

room = Room2()
rooms.append(room)

room = Room3()
rooms.append(room)

room = Room4()
rooms.append(room)

current_room_no = random.randint(0, 2)
current_room = rooms[current_room_no]




# Game Logic

player.move(current_room.wall_list)

if player.rect.x < -15:
    if current_room_no == 0:
        current_room_no = random.randint(0, 3)
        current_room = rooms[current_room_no]
        player.rect.x = 790
    elif current_room_no == 3:
        current_room_no = random.randint(0, 3)
        current_room = rooms[current_room_no]
        player.rect.x = 790
    elif current_room_no == 2:
        current_room_no = random.randint(0, 3)
        current_room = rooms[current_room_no]
        player.rect.x = 790
    else:
        current_room_no = 0
        current_room = rooms[current_room_no]
        player.rect.x = 790

if player.rect.x > 801:
    if current_room_no == 0:
        current_room_no = random.randint(0, 3)
        current_room = rooms[current_room_no]
        player.rect.x = 0
    elif current_room_no == 1:
        current_room_no = random.randint(0, 3)
        current_room = rooms[current_room_no]
        player.rect.x = 0
    elif current_room_no == 2:
        current_room_no = random.randint(0, 3)
        current_room = rooms[current_room_no]
        player.rect.x = 0
    else:
        current_room_no = 0
        current_room = rooms[current_room_no]
        player.rect.x = 0

让我知道是否需要更多代码!

1 个答案:

答案 0 :(得分:0)

希望我可以在您的游戏中再次有用。 有一个特定的功能需要一组数字,并根据需要使用任意数量的数字。假设您希望它选择具有六个值的两个数字。首先,您必须import random,然后必须random.sample(set([1, 2, 3, 4, 5, 6]), 2)。那将在1到6之间选择两个值。您可以在游戏中做同样的事情,切换变量的数字。每个房间。您可以将它们作为数字,但是数字1可以是Room1,依此类推。

希望这会有所帮助!