Update Kanjin-Engine
This commit is contained in:
267
Kanjin-Engine
267
Kanjin-Engine
@@ -129,7 +129,7 @@ class Player:
|
||||
print(f'In your rucksack you have:\n')
|
||||
for item_key, item_value in self.inventory.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_list = list(values)
|
||||
count_value = values_list[0]
|
||||
@@ -137,10 +137,15 @@ class Player:
|
||||
f' {item_key.description}\n')
|
||||
|
||||
def add_inventory(self, object1):
|
||||
self.inventory[object1] = {"Count": object1.count,
|
||||
"object": "",
|
||||
"equipped": False}
|
||||
return f'{object1} has been added to your rucksack.'
|
||||
for scene, room in Map.scenes.items():
|
||||
if seed == scene:
|
||||
for list_key, list_value in room.available_items.items():
|
||||
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):
|
||||
"""Outputs final stats, armour, and inventory"""
|
||||
@@ -225,6 +230,7 @@ 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
|
||||
|
||||
@@ -235,11 +241,10 @@ class Engine(object):
|
||||
# this runs only once
|
||||
# this STARTS THE GAME
|
||||
|
||||
# this (below) is supposed to be an infinite loop (but mine is not)
|
||||
while not last_scene:
|
||||
next_scene_name = current_scene.enter()
|
||||
current_scene = self.scene_map.next_scene(next_scene_name)
|
||||
print("\n--------")
|
||||
print("\n--------\n")
|
||||
current_scene.enter()
|
||||
|
||||
# note: will throw error if no new scene passed in by next line:
|
||||
@@ -270,6 +275,13 @@ class DamageMod(Enum):
|
||||
CHARISMA = auto()
|
||||
|
||||
|
||||
class ItemType(Enum):
|
||||
ARMOR = auto()
|
||||
WEAPON = auto()
|
||||
MONEY = auto()
|
||||
ITEM = auto()
|
||||
|
||||
|
||||
class Item:
|
||||
"""The base class for all items"""
|
||||
|
||||
@@ -278,6 +290,8 @@ class Item:
|
||||
self.description = description
|
||||
self.value = value
|
||||
self.magical = magical
|
||||
self.type = Item
|
||||
self.count = 1
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.name}\n=====\n{self.description}\nValue: {self.value}\n"
|
||||
@@ -290,6 +304,7 @@ class Money(Item):
|
||||
self.name = name
|
||||
self.amt = amt
|
||||
self.magical = magical
|
||||
self.type = ItemType.MONEY
|
||||
super().__init__(name=self.name,
|
||||
description=f"A small round coin made of {self.name.lower()} "
|
||||
f"with the imperial city logo stamped on the face.",
|
||||
@@ -307,13 +322,17 @@ class Weapon(Item):
|
||||
self.dmgMod = dmgMod
|
||||
self.versatile = versatile
|
||||
self.thrown = thrown
|
||||
self.type = Weapon
|
||||
super().__init__(name, description, value, magical)
|
||||
|
||||
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: Two Handed - {self.damage2H}\n" \
|
||||
f"Damage Type: {self.dmgType}\nMagical: {self.magical}.\n"
|
||||
f"\nDamage: Two Handed - {self.damage2H}" \
|
||||
f"\nDamage Type: {self.dmgType}" \
|
||||
f"\nMagical: {self.magical}\n"
|
||||
|
||||
|
||||
class Armor(Item):
|
||||
@@ -324,43 +343,51 @@ class Armor(Item):
|
||||
self.ac = ac
|
||||
self.stealthDis = disadvantage
|
||||
self.dmgRes = dmgRes
|
||||
self.type = Armor
|
||||
super().__init__(name, description, value, magical)
|
||||
|
||||
def __repr__(self):
|
||||
if self.stealthDis:
|
||||
return f"{self.name}\n=====\n{self.description}\nValue: {self.value}\n" \
|
||||
f"AC: {self.ac}\nMagical: {self.magical}"
|
||||
return f"{self.name}\n" \
|
||||
f"=====\n" \
|
||||
f"{self.description}\n" \
|
||||
f"Value: {self.value}\n" \
|
||||
f"AC: {self.ac}\n" \
|
||||
f"Magical: {self.magical}"
|
||||
elif not self.stealthDis:
|
||||
return f"{self.name}\n=====\n{self.description}\nValue: {self.value}\n" \
|
||||
f"AC: {self.ac}\nDisadvantage on Stealth checks: {self.stealthDis}\nMagical: {self.magical}"
|
||||
return f"{self.name}\n=====" \
|
||||
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):
|
||||
# output = "Press enter to begin"
|
||||
# if command:
|
||||
# output = "Command not understood"
|
||||
output = None
|
||||
if command == "help":
|
||||
output = get_instructions()
|
||||
elif command == "inventory":
|
||||
output = user.current_inventory()
|
||||
user.current_inventory()
|
||||
elif command == "equipment":
|
||||
response = query_equip()
|
||||
if response == "view":
|
||||
output = user.current_equip()
|
||||
user.current_equip()
|
||||
elif response == "change":
|
||||
output = "Sorry that feature isn't ready yet."
|
||||
elif command == "examine":
|
||||
if object1 is not None:
|
||||
output = object1.descrip
|
||||
else:
|
||||
output = "Unable to examine that."
|
||||
for item_key, item_value in user.inventory.items():
|
||||
if object1 == item_key.name.lower():
|
||||
print(item_key)
|
||||
else:
|
||||
output = "Unable to examine that."
|
||||
elif command == "take":
|
||||
if object1 is not None:
|
||||
output = user.add_inventory(object1)
|
||||
else:
|
||||
output = "Unable to take that."
|
||||
elif command == "error":
|
||||
output = "Command not recognised."
|
||||
user.add_inventory(object1)
|
||||
print("")
|
||||
# else:
|
||||
# output = "Unable to take that."
|
||||
# elif command == "error":
|
||||
# output = "Command not recognised."
|
||||
|
||||
return output
|
||||
|
||||
@@ -387,37 +414,99 @@ rock = Weapon(
|
||||
tornRags = Armor(
|
||||
name="Torn Rags",
|
||||
description="A ripped and worn-out outfit.",
|
||||
value=0,
|
||||
value="No Value",
|
||||
grade="Light",
|
||||
ac=0,
|
||||
disadvantage=True,
|
||||
dmgRes="None",
|
||||
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(*startGame())
|
||||
|
||||
|
||||
# enter() needs to return a map name.
|
||||
class Begin(Scene):
|
||||
name = "Kanjin - An RPG Text Adventure"
|
||||
desc = "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 queues 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."
|
||||
class Tutorial(Scene):
|
||||
available_items = {
|
||||
"rock": {rock: 2},
|
||||
"paper": {paper: 3}
|
||||
}
|
||||
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.")
|
||||
has_visited = False
|
||||
current_seed = "tutorial"
|
||||
|
||||
def enter(self):
|
||||
print(f'\n===========\n'
|
||||
f'{self.name}')
|
||||
print(f'===========\n'
|
||||
f'{self.desc}')
|
||||
wait()
|
||||
user.new_char()
|
||||
if not self.has_visited:
|
||||
print("===========")
|
||||
print(self.name)
|
||||
print("===========")
|
||||
print(self.descrip)
|
||||
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"
|
||||
|
||||
def action(self):
|
||||
pass
|
||||
|
||||
|
||||
class CaveEntrance(Scene):
|
||||
name = "Cave Entrance"
|
||||
@@ -431,39 +520,38 @@ class CaveEntrance(Scene):
|
||||
"and a mountain face on the right."
|
||||
has_visited = False
|
||||
|
||||
available_items = {}
|
||||
|
||||
def enter(self):
|
||||
print(f'\n===========\n'
|
||||
f'{self.name}')
|
||||
print("===========")
|
||||
print(self.name)
|
||||
if not self.has_visited:
|
||||
print(self.descTrue)
|
||||
else:
|
||||
print(self.descTrue)
|
||||
|
||||
action = input(">> ")
|
||||
# action = input(">> ").lower()
|
||||
# try:
|
||||
# process_command(*parse(action))
|
||||
# action = input(">> ")
|
||||
# except:
|
||||
# pass
|
||||
|
||||
if action == "shoot!":
|
||||
return "death"
|
||||
elif action == "dodge":
|
||||
return "pod"
|
||||
elif action == "start game":
|
||||
return "begin"
|
||||
else:
|
||||
print(process_command(*parse(action)))
|
||||
|
||||
# def action(self):
|
||||
# pass
|
||||
def action(self):
|
||||
pass
|
||||
|
||||
|
||||
class A1(Scene):
|
||||
available_items = {}
|
||||
name = "Laser Weapon Armory"
|
||||
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."
|
||||
|
||||
def enter(self):
|
||||
print(f'\n===========\n'
|
||||
f'{self.name}'
|
||||
f'\n===========\n'
|
||||
f'{self.descrip}')
|
||||
print("===========")
|
||||
print(self.name)
|
||||
print("===========")
|
||||
print(self.descrip)
|
||||
|
||||
def action(self):
|
||||
pass
|
||||
@@ -489,66 +577,18 @@ class A1(Scene):
|
||||
#
|
||||
# def action(self):
|
||||
# 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
|
||||
# it does not make us move - Engine does that
|
||||
class Map(object):
|
||||
scenes = {
|
||||
'tutorial': Tutorial(),
|
||||
"begin": Begin(),
|
||||
'cave entrance': CaveEntrance(),
|
||||
'A1': A1(),
|
||||
# 'death': Death(),
|
||||
# 'bridge': TheBridge(),
|
||||
'tutorial': Tutorial(),
|
||||
"begin": Begin()
|
||||
|
||||
}
|
||||
|
||||
def __init__(self, start_scene_key):
|
||||
@@ -556,7 +596,8 @@ class Map(object):
|
||||
# above we make a local var named start_scene_key
|
||||
# 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)
|
||||
# above is how we get value out of the dictionary named scenes
|
||||
return val
|
||||
|
||||
Reference in New Issue
Block a user