diff --git a/Python/Examples/Rooms.py b/Python/Examples/Rooms.py new file mode 100644 index 0000000..2c74a5a --- /dev/null +++ b/Python/Examples/Rooms.py @@ -0,0 +1,9 @@ +from dataclasses import dataclass + +@dataclass +class Room(): + grid_col: int = 0 + grid_row: int = 0 + name: str = "" + description: str = "" + dark: bool = False \ No newline at end of file diff --git a/Python/Examples/dice.py b/Python/Examples/dice.py index 7dd9a01..5e14e6d 100644 --- a/Python/Examples/dice.py +++ b/Python/Examples/dice.py @@ -1,21 +1,51 @@ +import json import random +from pathlib import Path +from typing import List +from Rooms import Room + +my_rooms = [] +raw_room_data = Path('room_data.json').read_text() +room_data = json.loads(raw_room_data) +for room in room_data: + my_rooms.append(Room(room['grid_col'], room['grid_row'], room['name'], room['description'], room['dark'])) dice = ["1", "2",] +sides = ["4", "6", "8", "10", "12", "20"] -def parse_input(input_string): - if input_string.strip() in dice: +def parse_input(input_string: str, my_list: List): + if input_string.strip() in my_list: return int(input_string) else: - print(f"Please enter a number from {dice[0]} to {dice[-1]}.") - raise SystemExit(1) + show_list = "" + for element in my_list: + show_list += f"{element}," + show_list = show_list[:-1] + print(f"Please enter a number from [{show_list}].") + raise SystemExit(1) -def roll_dice(num_dice) +def roll_dice(num_dice: int, num_sides: int = 6): roll_results = [] for _ in range(num_dice): - roll = random.randint(1, 6) + roll = random.randint(1, num_sides) roll_results.append(roll) + return roll_results +#User Inout on howmany dice to roll num_dice_input = input(f"How many dice do you want to roll? [{dice[0]}-{dice[-1]}] ") -num_dice = parse_input(num_dice_input) +num_dice = parse_input(num_dice_input, dice) print(num_dice) +my_list = "" +for sided in sides: + my_list += f"{sided}," +my_list = my_list[:-1] +num_sides_input = input(f"How many sides from [{my_list}] ") +num_sides = parse_input(num_sides_input, sides) +print(num_sides) + +#Results of ice roll + +num_dice_input = roll_dice(num_dice, num_sides) + +print(num_dice_input) \ No newline at end of file diff --git a/Python/Examples/room_data.json b/Python/Examples/room_data.json new file mode 100644 index 0000000..d229cc8 --- /dev/null +++ b/Python/Examples/room_data.json @@ -0,0 +1,16 @@ +[ + { + "grid_col": 0, + "grid_row": 0, + "name": "Forest Clearing", + "dark": false, + "description": "You see a large, dirty rock in the center of a small clearing. Several birds rest on the rock." + }, + { + "grid_col": 1, + "grid_row": 0, + "name": "Narrow Path", + "dark": true, + "description": "You are on a narrow ledge following near the ridge of a steep mountain path." + } +] \ No newline at end of file