vers2 with scenery added
This commit is contained in:
parent
bea881624f
commit
4108771ad9
9
Python/Examples/Rooms.py
Normal file
9
Python/Examples/Rooms.py
Normal file
|
@ -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
|
|
@ -1,21 +1,51 @@
|
||||||
|
import json
|
||||||
import random
|
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",]
|
dice = ["1", "2",]
|
||||||
|
sides = ["4", "6", "8", "10", "12", "20"]
|
||||||
|
|
||||||
def parse_input(input_string):
|
def parse_input(input_string: str, my_list: List):
|
||||||
if input_string.strip() in dice:
|
if input_string.strip() in my_list:
|
||||||
return int(input_string)
|
return int(input_string)
|
||||||
else:
|
else:
|
||||||
print(f"Please enter a number from {dice[0]} to {dice[-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)
|
raise SystemExit(1)
|
||||||
|
|
||||||
def roll_dice(num_dice)
|
def roll_dice(num_dice: int, num_sides: int = 6):
|
||||||
roll_results = []
|
roll_results = []
|
||||||
for _ in range(num_dice):
|
for _ in range(num_dice):
|
||||||
roll = random.randint(1, 6)
|
roll = random.randint(1, num_sides)
|
||||||
roll_results.append(roll)
|
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_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)
|
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)
|
16
Python/Examples/room_data.json
Normal file
16
Python/Examples/room_data.json
Normal file
|
@ -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."
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user