fix random world selection

This commit is contained in:
Dominic DiTaranto 2025-08-29 22:05:10 -04:00
parent b09dca22e5
commit 704ae05175

12
main.py
View file

@ -1,4 +1,3 @@
import argparse
import os import os
import random import random
@ -284,21 +283,26 @@ class Map:
if __name__ == '__main__': if __name__ == '__main__':
world_map_key_list = list(WORLD_MAP.keys())
def get_world_response(): def get_world_response():
response = input('Which world would you like to play? Input a number: ') response = input('Which world would you like to play? Input a number: ')
if response not in [str(idx) for idx, _ in enumerate(list(WORLD_MAP.keys()))]: if response not in [str(idx) for idx, _ in enumerate(world_map_key_list)] and response != str(len(world_map_key_list)):
return get_world_response() return get_world_response()
return response return response
os.system('clear') os.system('clear')
for idx, name in enumerate(list(WORLD_MAP.keys())): for idx, name in enumerate(world_map_key_list):
print(f'[{idx}] {name}') print(f'[{idx}] {name}')
random_idx = idx + 1 random_idx = idx + 1
print(f'[{random_idx}] random world') print(f'[{random_idx}] random world')
world = list(WORLD_MAP.keys())[int(get_world_response())] response = int(get_world_response())
if int(response) == random_idx:
response = random.randint(0, len(world_map_key_list))
world = list(WORLD_MAP.keys())[response]
levels = WORLD_MAP.get(world) levels = WORLD_MAP.get(world)
g = Game() g = Game()