From 704ae05175f25b76caa475df8841c669e57fc416 Mon Sep 17 00:00:00 2001 From: Dominic DiTaranto Date: Fri, 29 Aug 2025 22:05:10 -0400 Subject: [PATCH] fix random world selection --- main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index d241d2c..d92e417 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -import argparse import os import random @@ -284,21 +283,26 @@ class Map: if __name__ == '__main__': + world_map_key_list = list(WORLD_MAP.keys()) + def get_world_response(): 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 response 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}') random_idx = idx + 1 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) g = Game()