Update Kanjin-Engine

This commit is contained in:
KansaiGaijin
2022-01-29 16:09:35 +13:00
committed by GitHub
parent f2b5b4ed8d
commit ebcc0d2a03

View File

@@ -129,7 +129,7 @@ class Player:
print(f'In your rucksack you have:\n') print(f'In your rucksack you have:\n')
for item_key, item_value in self.inventory.items(): for item_key, item_value in self.inventory.items():
for key, value in item_value.items(): for key, value in item_value.items():
if key == "equipped" and value == False: if (key == "equipped") and not value:
values = item_value.values() values = item_value.values()
values_list = list(values) values_list = list(values)
count_value = values_list[0] count_value = values_list[0]
@@ -137,10 +137,15 @@ class Player:
f' {item_key.description}\n') f' {item_key.description}\n')
def add_inventory(self, object1): def add_inventory(self, object1):
self.inventory[object1] = {"Count": object1.count, for scene, room in Map.scenes.items():
"object": "", if seed == scene:
"equipped": False} for list_key, list_value in room.available_items.items():
return f'{object1} has been added to your rucksack.' for var, count in list_value.items():
if object1 in list_key:
self.inventory[var] = {"Count": count,
"object": var.type,
"equipped": False}
print(f'{var.name} has been added to your rucksack.')
def new_char(self): def new_char(self):
"""Outputs final stats, armour, and inventory""" """Outputs final stats, armour, and inventory"""
@@ -225,6 +230,7 @@ class Engine(object):
def __init__(self, scene_map): def __init__(self, scene_map):
self.name = "name" self.name = "name"
self.descrip = "descrip" self.descrip = "descrip"
self.seed = "seed"
self.scene_map = scene_map self.scene_map = scene_map
# gets the game's map from instance "mymap" at bottom of this file # gets the game's map from instance "mymap" at bottom of this file
@@ -235,11 +241,10 @@ class Engine(object):
# this runs only once # this runs only once
# this STARTS THE GAME # this STARTS THE GAME
# this (below) is supposed to be an infinite loop (but mine is not)
while not last_scene: while not last_scene:
next_scene_name = current_scene.enter() next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name) current_scene = self.scene_map.next_scene(next_scene_name)
print("\n--------") print("\n--------\n")
current_scene.enter() current_scene.enter()
# note: will throw error if no new scene passed in by next line: # note: will throw error if no new scene passed in by next line:
@@ -270,6 +275,13 @@ class DamageMod(Enum):
CHARISMA = auto() CHARISMA = auto()
class ItemType(Enum):
ARMOR = auto()
WEAPON = auto()
MONEY = auto()
ITEM = auto()
class Item: class Item:
"""The base class for all items""" """The base class for all items"""
@@ -278,6 +290,8 @@ class Item:
self.description = description self.description = description
self.value = value self.value = value
self.magical = magical self.magical = magical
self.type = Item
self.count = 1
def __repr__(self): def __repr__(self):
return f"{self.name}\n=====\n{self.description}\nValue: {self.value}\n" return f"{self.name}\n=====\n{self.description}\nValue: {self.value}\n"
@@ -290,6 +304,7 @@ class Money(Item):
self.name = name self.name = name
self.amt = amt self.amt = amt
self.magical = magical self.magical = magical
self.type = ItemType.MONEY
super().__init__(name=self.name, super().__init__(name=self.name,
description=f"A small round coin made of {self.name.lower()} " description=f"A small round coin made of {self.name.lower()} "
f"with the imperial city logo stamped on the face.", f"with the imperial city logo stamped on the face.",
@@ -307,13 +322,17 @@ class Weapon(Item):
self.dmgMod = dmgMod self.dmgMod = dmgMod
self.versatile = versatile self.versatile = versatile
self.thrown = thrown self.thrown = thrown
self.type = Weapon
super().__init__(name, description, value, magical) super().__init__(name, description, value, magical)
def __repr__(self): def __repr__(self):
return f"{self.name}\n=====\n{self.description}\nValue: {self.value}" \ return f"{self.name}\n=====" \
f"\n{self.description}" \
f"\nValue: {self.value}" \
f"\nDamage: One Handed - {self.damage1H}" \ f"\nDamage: One Handed - {self.damage1H}" \
f"\nDamage: Two Handed - {self.damage2H}\n" \ f"\nDamage: Two Handed - {self.damage2H}" \
f"Damage Type: {self.dmgType}\nMagical: {self.magical}.\n" f"\nDamage Type: {self.dmgType}" \
f"\nMagical: {self.magical}\n"
class Armor(Item): class Armor(Item):
@@ -324,43 +343,51 @@ class Armor(Item):
self.ac = ac self.ac = ac
self.stealthDis = disadvantage self.stealthDis = disadvantage
self.dmgRes = dmgRes self.dmgRes = dmgRes
self.type = Armor
super().__init__(name, description, value, magical) super().__init__(name, description, value, magical)
def __repr__(self): def __repr__(self):
if self.stealthDis: if self.stealthDis:
return f"{self.name}\n=====\n{self.description}\nValue: {self.value}\n" \ return f"{self.name}\n" \
f"AC: {self.ac}\nMagical: {self.magical}" f"=====\n" \
f"{self.description}\n" \
f"Value: {self.value}\n" \
f"AC: {self.ac}\n" \
f"Magical: {self.magical}"
elif not self.stealthDis: elif not self.stealthDis:
return f"{self.name}\n=====\n{self.description}\nValue: {self.value}\n" \ return f"{self.name}\n=====" \
f"AC: {self.ac}\nDisadvantage on Stealth checks: {self.stealthDis}\nMagical: {self.magical}" f"\n{self.description}\n" \
f"Value: {self.value}\n" \
f"AC: {self.ac}\n" \
f"Disadvantage on Stealth checks: {self.stealthDis}\n" \
f"Magical: {self.magical}\n"
def process_command(command, object1): def process_command(command, object1):
# output = "Press enter to begin" output = None
# if command:
# output = "Command not understood"
if command == "help": if command == "help":
output = get_instructions() output = get_instructions()
elif command == "inventory": elif command == "inventory":
output = user.current_inventory() user.current_inventory()
elif command == "equipment": elif command == "equipment":
response = query_equip() response = query_equip()
if response == "view": if response == "view":
output = user.current_equip() user.current_equip()
elif response == "change": elif response == "change":
output = "Sorry that feature isn't ready yet." output = "Sorry that feature isn't ready yet."
elif command == "examine": elif command == "examine":
if object1 is not None: for item_key, item_value in user.inventory.items():
output = object1.descrip if object1 == item_key.name.lower():
else: print(item_key)
output = "Unable to examine that." else:
output = "Unable to examine that."
elif command == "take": elif command == "take":
if object1 is not None: user.add_inventory(object1)
output = user.add_inventory(object1) print("")
else: # else:
output = "Unable to take that." # output = "Unable to take that."
elif command == "error": # elif command == "error":
output = "Command not recognised." # output = "Command not recognised."
return output return output
@@ -387,37 +414,99 @@ rock = Weapon(
tornRags = Armor( tornRags = Armor(
name="Torn Rags", name="Torn Rags",
description="A ripped and worn-out outfit.", description="A ripped and worn-out outfit.",
value=0, value="No Value",
grade="Light", grade="Light",
ac=0, ac=0,
disadvantage=True, disadvantage=True,
dmgRes="None", dmgRes="None",
magical=False magical=False
) )
paper = Item(
name="Paper",
description="A blank piece of paper",
value=0,
magical=False
)
user = Player("Jamie", "Male", 29, "Elf", "Mage") user = Player("Jamie", "Male", 29, "Elf", "Mage")
# user = Player(*startGame()) # user = Player(*startGame())
# enter() needs to return a map name. # enter() needs to return a map name.
class Begin(Scene): class Tutorial(Scene):
name = "Kanjin - An RPG Text Adventure" available_items = {
desc = "Welcome to Kanjin.\nThis game is based off of the D&D SRD ruleset, and will see you, our adventurer, " \ "rock": {rock: 2},
"exploring, adventuring, and plundering.\n\nTo play Kanjin is very simple.\nRead the instructions, " \ "paper": {paper: 3}
"understand the scene, and take control.\nAll directional queues will be given and clear but you " \ }
"can also use specific commands at almost anytime when you give your input.\n" \ name = "Tutorial Level"
"After character creation, type 'Help' to view a list of commands and explanations." descrip = ("There are certain commands that will be available almost anytime you are able to type,\n"
"such as viewing your inventory, checking your equipped items, and also changing them.\n"
"You can also view your stats including your current and max hp.\n"
"Give it a go starting with 'Check inventory', 'Check equipment', and 'View stats'.\n"
"See what else you can do, then enter 'continue' to move to the next step.")
has_visited = False
current_seed = "tutorial"
def enter(self): def enter(self):
print(f'\n===========\n' if not self.has_visited:
f'{self.name}') print("===========")
print(f'===========\n' print(self.name)
f'{self.desc}') print("===========")
wait() print(self.descrip)
user.new_char() self.has_visited = True
action = input(">> ").lower()
while action not in ("continue", "scene"):
process_command(*parse(action))
action = input(">> ").lower()
else:
if action == "continue":
return "begin"
elif action == "scene":
print(self.descrip)
return self.current_seed
def action(self):
pass
class Begin(Scene):
available_items = {}
name = "Kanjin - An RPG Text Adventure"
descrip = "Welcome to Kanjin.\nThis game is based off of the D&D SRD ruleset, and will see you, our adventurer, " \
"exploring, adventuring, and plundering.\n\nTo play Kanjin is very simple.\nRead the instructions, " \
"understand the scene, and take control.\nAll directional cues will be given and clear but you " \
"can also use specific commands at almost anytime when you give your input.\n" \
"After character creation, type 'Help' to view a list of commands and explanations.\n"
has_visited = True
seed_name = "begin"
def enter(self):
if not self.has_visited:
print("===========")
print(self.name)
print("===========")
print(self.descrip)
wait()
# user.new_char()
self.has_visited = True
print(seed)
action = input(">> ").lower()
while action not in ("continue", "scene"):
process_command(*parse(action))
action = input(">> ").lower()
else:
if action == "continue":
return "begin"
elif action == "scene":
print(self.descrip)
return self.seed_name
return "Cave entrance" return "Cave entrance"
def action(self):
pass
class CaveEntrance(Scene): class CaveEntrance(Scene):
name = "Cave Entrance" name = "Cave Entrance"
@@ -431,39 +520,38 @@ class CaveEntrance(Scene):
"and a mountain face on the right." "and a mountain face on the right."
has_visited = False has_visited = False
available_items = {}
def enter(self): def enter(self):
print(f'\n===========\n' print("===========")
f'{self.name}') print(self.name)
if not self.has_visited: if not self.has_visited:
print(self.descTrue) print(self.descTrue)
else: else:
print(self.descTrue) print(self.descTrue)
action = input(">> ") # action = input(">> ").lower()
# try:
# process_command(*parse(action))
# action = input(">> ")
# except:
# pass
if action == "shoot!": def action(self):
return "death" pass
elif action == "dodge":
return "pod"
elif action == "start game":
return "begin"
else:
print(process_command(*parse(action)))
# def action(self):
# pass
class A1(Scene): class A1(Scene):
available_items = {}
name = "Laser Weapon Armory" name = "Laser Weapon Armory"
descrip = "Shelves and cases line the walls of this room. Weapons of every description " \ descrip = "Shelves and cases line the walls of this room. Weapons of every description " \
"fill the shelves and cases. There is a digital keypad set into the wall." "fill the shelves and cases. There is a digital keypad set into the wall."
def enter(self): def enter(self):
print(f'\n===========\n' print("===========")
f'{self.name}' print(self.name)
f'\n===========\n' print("===========")
f'{self.descrip}') print(self.descrip)
def action(self): def action(self):
pass pass
@@ -489,66 +577,18 @@ class A1(Scene):
# #
# def action(self): # def action(self):
# pass # pass
#
#
# class TheBridge(Scene):
#
# def __init__(self):
# self.name = "The Bridge"
# self.descrip = "Clearly this is a central command station of the spaceship. A wide view screen shows the" \
# " stars against a black curtain of empty space."
#
# def enter(self):
# print(f'\n===========\n'
# f'{self.name}'
# f'\n===========\n'
# f'{self.descrip}')
#
# def action(self):
# pass
class Tutorial(Scene):
name = "Tutorial Level"
descrip = ("There are certain commands that will be available almost anytime you are able to type,\n"
"such as viewing your inventory, checking your equipped items, and also changing them.\n"
"You can also view your stats including your current and max hp.\n"
"Give it a go starting with 'Check inventory', 'Check equipment', and 'View stats'.\n"
"See what else you can do, then enter 'continue' to move to the next step.")
def enter(self):
print(f'\n===========\n'
f'{self.name}'
f'\n===========\n'
f'{self.descrip}')
action = input(">> ").lower()
while action != "continue":
process_command(*parse(action))
action = input(">> ")
if action == "continue":
return "begin"
# if action == "shoot!":
# print("result")
# return "death"
# elif action == "dodge":
# print("result")
# return "pod"
# else:
# print("error")
# return "central corridor"
# Map tells us where we are and where we can go # Map tells us where we are and where we can go
# it does not make us move - Engine does that # it does not make us move - Engine does that
class Map(object): class Map(object):
scenes = { scenes = {
'tutorial': Tutorial(),
"begin": Begin(),
'cave entrance': CaveEntrance(), 'cave entrance': CaveEntrance(),
'A1': A1(), 'A1': A1(),
# 'death': Death(), # 'death': Death(),
# 'bridge': TheBridge(),
'tutorial': Tutorial(),
"begin": Begin()
} }
def __init__(self, start_scene_key): def __init__(self, start_scene_key):
@@ -556,7 +596,8 @@ class Map(object):
# above we make a local var named start_scene_key # above we make a local var named start_scene_key
# start_scene_key remains unchanged throughout the game # start_scene_key remains unchanged throughout the game
def next_scene(self, scene_name): @staticmethod
def next_scene(scene_name):
val = Map.scenes.get(scene_name) val = Map.scenes.get(scene_name)
# above is how we get value out of the dictionary named scenes # above is how we get value out of the dictionary named scenes
return val return val