From 2a182c4fb6840d05a6eb2a6976fb29b5b21ebd53 Mon Sep 17 00:00:00 2001 From: Dominic DiTaranto Date: Fri, 29 Aug 2025 21:46:48 -0400 Subject: [PATCH] readme and world picker --- README.md | 15 +++++++++++++-- main.py | 23 ++++++++++++++--------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 31fb19b..201952c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,12 @@ Welcome to PYSOKOBAN! The object of the game is to move all of the boulders to specific storage -positions in the shortest amount of moves possible. +positions in the shortest amount of moves possible. + +With 13 worlds and 617 different levels, you will never be bored (unless you do not like sokoban, of course)! + +All levels were STOLEN from [here](http://www.sneezingtiger.com/sokoban/levels.html). I did not write any of the levels... maybe I will one day. + ``` KEY MOVEMENT +===========================================+ @@ -10,8 +15,14 @@ positions in the shortest amount of moves possible. | @ | you || \ | / | \ | / | | # | wall || h- . -l | 4- . -6 | | 0 | boulder || / | \ | / | \ | -| . | storage || b j n | 1 2 3 | +| * | stored^ || b j n | 1 2 3 +| . | storage || | | +===========================================+ ``` +## Getting Started +1. Create virtual environment with: `python3 -m venv venv` +2. Activate virtual environment with: `sourve venv/bin/activate` +3. Install Requirements with: `pip install -r requirements.txt` +4. Play the game with: `python3 main.py` diff --git a/main.py b/main.py index ae63be8..0a00786 100644 --- a/main.py +++ b/main.py @@ -281,17 +281,22 @@ class Map: if __name__ == '__main__': + def get_world_response(): + response = input('Which world would you like to play? Input a number: ') - parser = argparse.ArgumentParser(prog='pysokoban') - parser.add_argument('-w', '--world', dest='world', choices=WORLD_MAP.keys()) - args = parser.parse_args() + if response not in [str(idx) for idx, _ in enumerate(list(WORLD_MAP.keys()))]: + return get_world_response() - if args.world in WORLD_MAP: - world = args.world - levels = WORLD_MAP.get(args.world) - else: - world = list(WORLD_MAP.keys())[random.randint(0, len(WORLD_MAP.keys()))] - levels = WORLD_MAP.get(world) + return response + + os.system('clear') + for idx, name in enumerate(list(WORLD_MAP.keys())): + print(f'[{idx}] {name}') + random_idx = idx + 1 + print(f'[{random_idx}] random world') + + world = list(WORLD_MAP.keys())[int(get_world_response())] + levels = WORLD_MAP.get(world) g = Game() g.initialize_level()