Update Kanjin-Engine

This commit is contained in:
KansaiGaijin
2022-02-09 18:00:14 +13:00
committed by GitHub
parent 93b3ce9a49
commit ea3e1b30a4

View File

@@ -1,11 +1,38 @@
import time import time
from functions import startGame, wait, parse, get_instructions, query_equip from functions import startGame, wait, parse, get_instructions, query_equip, error_message, change_equip
from random import randint from random import randint
from enum import Enum, auto from enum import Enum, auto
# pyinstaller --onefile --paths=C:\Users\kasai\PycharmProjects\pythonProject\Kanjin\KanjinEngine.py # pyinstaller --onefile --paths=C:\Users\kasai\PycharmProjects\pythonProject\Kanjin\KanjinEngine.py
class Engine(object):
def __init__(self, scene_map):
# self.name = "name"
# self.descrip = "descrip"
self.seed = None
self.scene_map = scene_map
# gets the game's map from instance "mymap" at bottom of this file
def play(self):
current_scene = self.scene_map.opening_scene()
last_scene = self.scene_map.next_scene('finished')
while current_scene != last_scene:
next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name)
current_scene.enter()
# # note: will throw error if no new scene passed in by next line:
# next_scene_name = current_scene.action()
# # get the name of the next scene from the action() function that
# # runs in the current scene - what it returns
#
# current_scene = self.scene_map.next_scene(next_scene_name)
# # here we use that val returned by current scene to go to
# # the next scene, running function in Map
class Player: class Player:
"""Character Creation""" """Character Creation"""
@@ -55,6 +82,10 @@ class Player:
"object": Weapon, "object": Weapon,
"equipped": True "equipped": True
}, },
paper: {"Count": 1,
"object": Weapon,
"equipped": False
},
tornRags: {"Count": 1, tornRags: {"Count": 1,
"object": Armor, "object": Armor,
"equipped": True "equipped": True
@@ -126,26 +157,64 @@ class Player:
def current_inventory(self): def current_inventory(self):
"""Prints a list of items in your backpack that aren't equipped to your person.""" """Prints a list of items in your backpack that aren't equipped to your person."""
print(f'In your rucksack you have:\n') print(f'In your rucksack you have:')
for item_key, item_value in self.inventory.items(): for item_key, item_value in self.inventory.items(): # string, dictionary
for key, value in item_value.items(): for key, value in item_value.items(): # variable/object, integer
if (key == "equipped") and not value: if (key == "equipped") and not value: # if equipped = False
values = item_value.values() values = item_value.values() # make a variable of all values
values_list = list(values) values_list = list(values) # turn variable into a list
count_value = values_list[0] count_value = values_list[0] # take the first value from list - why?
print(f'{item_key.name} x {count_value}\n' print(f'{item_key.name} x {count_value}\n'
f' {item_key.description}\n') f' {item_key.description}')
def add_inventory(self, object1): def drop_item(self, object1):
for scene, room in Map.scenes.items(): pass
if seed == scene:
for list_key, list_value in room.available_items.items(): def loot_object(self, object1):
for var, count in list_value.items(): for scene, room in Map.scenes.items(): # iterate map scenes
if object1 in list_key: if Engine.seed == scene: # set new Engine seed in each room.enter()
self.inventory[var] = {"Count": count, for list_key, list_value in room.lootable_items.items(): # string, dictionary
if object1 in list_key: # if user input is in the lootable items
for var, count in list_value.items(): # variable/object, integer
if var in self.inventory: # if object is in inventory
self.inventory[var]["Count"] += count # increase item count
print(f'{var.name} x {count} has been added to your existing stack.')
elif var not in self.inventory[var]: # if variable not in inventory
self.inventory[var] = {"Count": count, # add it in
"object": var.type, "object": var.type,
"equipped": False} "equipped": False}
print(f'{var.name} has been added to your rucksack.') print(f'{var.name} x {count} has been added to your rucksack.')
del room.lootable_items[object1] # remove item from lootable list
break
else:
print("You don't see one of those to loot.")
break
def add_inventory(self, object1):
for scene, room in Map.scenes.items(): # iterate map scenes
if Engine.seed == scene: # set new Engine seed in each room.enter()
for list_key, list_value in room.available_items.items(): # string, dictionary
if object1 in list_key: # if user input is in the available items
for var, count in list_value.items(): # variable/object, integer
if var in self.inventory: # if object is in inventory
self.inventory[var]["Count"] += count # increase item count
print(f'{var.name} x {count} has been added to your existing stack.')
elif var not in self.inventory[var]: # if variable not in inventory
self.inventory[var] = {"Count": count, # add it in
"object": var.type,
"equipped": False}
print(f'{var.name} x {count} has been added to your rucksack.')
del room.available_items[object1] # remove item from available list
break
elif object1 not in list_key:
print("You don't see any lying around..")
break
def new_char(self): def new_char(self):
"""Outputs final stats, armour, and inventory""" """Outputs final stats, armour, and inventory"""
@@ -225,38 +294,6 @@ class Scene(object):
# # this applies to all classes under Scene, but Zed does it differently # # this applies to all classes under Scene, but Zed does it differently
class Engine(object):
def __init__(self, scene_map):
self.name = "name"
self.descrip = "descrip"
self.seed = "seed"
self.scene_map = scene_map
# gets the game's map from instance "mymap" at bottom of this file
def play(self):
current_scene = self.scene_map.opening_scene()
last_scene = self.scene_map.next_scene('Finished')
# see the Map object: runs function named opening_scene()
# this runs only once
# this STARTS THE GAME
while not last_scene:
next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name)
print("\n--------\n")
current_scene.enter()
# note: will throw error if no new scene passed in by next line:
next_scene_name = current_scene.action()
# get the name of the next scene from the action() function that
# runs in the current scene - what it returns
current_scene = self.scene_map.next_scene(next_scene_name)
# here we use that val returned by current scene to go to
# the next scene, running function in Map
class DamageType(Enum): class DamageType(Enum):
SLASHING = auto() SLASHING = auto()
CRUSHING = auto() CRUSHING = auto()
@@ -374,7 +411,7 @@ def process_command(command, object1):
if response == "view": if response == "view":
user.current_equip() user.current_equip()
elif response == "change": elif response == "change":
output = "Sorry that feature isn't ready yet." output = change_equip()
elif command == "examine": elif command == "examine":
for item_key, item_value in user.inventory.items(): for item_key, item_value in user.inventory.items():
if object1 == item_key.name.lower(): if object1 == item_key.name.lower():
@@ -383,11 +420,10 @@ def process_command(command, object1):
output = "Unable to examine that." output = "Unable to examine that."
elif command == "take": elif command == "take":
user.add_inventory(object1) user.add_inventory(object1)
print("") elif command == "loot":
# else: user.loot_object(object1)
# output = "Unable to take that." elif command == "error":
# elif command == "error": output = error_message()
# output = "Command not recognised."
return output return output
@@ -437,34 +473,43 @@ user = Player("Jamie", "Male", 29, "Elf", "Mage")
# enter() needs to return a map name. # enter() needs to return a map name.
class Tutorial(Scene): class Tutorial(Scene):
available_items = { available_items = {
"rock": {rock: 2}, "rock": {rock: 12},
"paper": {paper: 3} "paper": {paper: 3}
} }
lootable_items = {
"chest": {GP1: 5, rock: 1},
"corpse": {GP1: 100}
}
name = "Tutorial Level" name = "Tutorial Level"
descrip = ("There are certain commands that will be available almost anytime you are able to type,\n" # 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" # "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" # "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" # "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.") # "See what else you can do, then enter 'continue' to move to the next step.")
descrip = f'Scattered around the room you see {available_items["rock"][rock]}x rock.'
has_visited = False has_visited = False
current_seed = "tutorial" current_seed = "tutorial"
def enter(self): def enter(self):
Engine.seed = "tutorial"
if not self.has_visited: if not self.has_visited:
print("===========") print("===========")
print(self.name) print(self.name)
print("===========") print("===========")
print(self.descrip) print(self.descrip)
else:
print("Welcome back to the tutorial.")
self.has_visited = True self.has_visited = True
action = input(">> ").lower() action = input(">> ").lower()
while action not in ("continue", "scene"):
while action not in ("continue", "scene"): # move scene to parser
process_command(*parse(action)) process_command(*parse(action))
action = input(">> ").lower() action = input(">> ").lower()
else: else:
if action == "continue": if action == "continue":
return "begin" return "begin"
elif action == "scene": elif action == "scene":
print(self.descrip) print(self.available_items)
return self.current_seed return self.current_seed
def action(self): def action(self):
@@ -472,17 +517,20 @@ class Tutorial(Scene):
class Begin(Scene): class Begin(Scene):
available_items = {} available_items = {
"rock": {rock: 10},
"paper": {paper: 13}}
name = "Kanjin - An RPG Text Adventure" 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, " \ 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, " \ "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 " \ "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" \ "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" "After character creation, type 'Help' to view a list of commands and explanations.\n"
has_visited = True has_visited = False
seed_name = "begin" current_seed = "begin"
def enter(self): def enter(self):
Engine.seed = "begin"
if not self.has_visited: if not self.has_visited:
print("===========") print("===========")
print(self.name) print(self.name)
@@ -490,18 +538,22 @@ class Begin(Scene):
print(self.descrip) print(self.descrip)
wait() wait()
# user.new_char() # user.new_char()
else:
print("Welcome back to the beginning")
self.has_visited = True self.has_visited = True
print(seed)
action = input(">> ").lower() action = input(">> ").lower()
while action not in ("continue", "scene"):
while action not in ("continue", "scene", "back"):
process_command(*parse(action)) process_command(*parse(action))
action = input(">> ").lower() action = input(">> ").lower()
else: else:
if action == "continue": if action == "continue":
return "begin" return "cave entrance"
elif action == "back":
return "tutorial"
elif action == "scene": elif action == "scene":
print(self.descrip) print(self.descrip)
return self.seed_name return self.current_seed
return "Cave entrance" return "Cave entrance"
def action(self): def action(self):
@@ -509,8 +561,9 @@ class Begin(Scene):
class CaveEntrance(Scene): class CaveEntrance(Scene):
available_items = {}
name = "Cave Entrance" name = "Cave Entrance"
descTrue = "A small broken statue at the mouth of a cave marks the entrance to a dungeon.\n" \ descrip = "A small broken statue at the mouth of a cave marks the entrance to a dungeon.\n" \
"Beyond the broken statue lies a massive, rugged room, too dark to see into.\n" \ "Beyond the broken statue lies a massive, rugged room, too dark to see into.\n" \
"You make out the silhouette of broken pottery sprawled around.\n" \ "You make out the silhouette of broken pottery sprawled around.\n" \
"\nBehind you is the forest you traversed through to get here, about 1500m away from the road.\n" \ "\nBehind you is the forest you traversed through to get here, about 1500m away from the road.\n" \
@@ -519,23 +572,31 @@ class CaveEntrance(Scene):
descFalse = "You return to the cave entrance with the road behind you, a canyon to the east, " \ descFalse = "You return to the cave entrance with the road behind you, a canyon to the east, " \
"and a mountain face on the right." "and a mountain face on the right."
has_visited = False has_visited = False
current_seed = "cave entrance"
available_items = {}
def enter(self): def enter(self):
Engine.seed = "cave entrance"
if not self.has_visited:
print("===========") print("===========")
print(self.name) print(self.name)
if not self.has_visited: print("===========")
print(self.descTrue) print(self.descrip)
else: else:
print(self.descTrue) print("Welcome back to the cave")
self.has_visited = True
action = input(">> ").lower()
# action = input(">> ").lower() while action not in ("continue", "scene", "back"):
# try: process_command(*parse(action))
# process_command(*parse(action)) action = input(">> ").lower()
# action = input(">> ") else:
# except: if action == "continue":
# pass return "begin"
elif action == "back":
return "begin"
elif action == "scene":
print(self.descrip)
return "Cave entrance"
def action(self): def action(self):
pass pass
@@ -546,6 +607,7 @@ class A1(Scene):
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."
current_seed = "A1"
def enter(self): def enter(self):
print("===========") print("===========")
@@ -588,7 +650,7 @@ class Map(object):
'cave entrance': CaveEntrance(), 'cave entrance': CaveEntrance(),
'A1': A1(), 'A1': A1(),
# 'death': Death(), # 'death': Death(),
# 'finished': Finished()
} }
def __init__(self, start_scene_key): def __init__(self, start_scene_key):