Update Kanjin-Engine
This commit is contained in:
231
Kanjin-Engine
231
Kanjin-Engine
@@ -1,5 +1,5 @@
|
|||||||
import time
|
import time
|
||||||
from functions import startGame
|
from functions import startGame, wait, parse, process_command
|
||||||
from random import randint
|
from random import randint
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
|
|
||||||
@@ -124,6 +124,24 @@ class Player:
|
|||||||
f"\n{self.weapon.name}\n"
|
f"\n{self.weapon.name}\n"
|
||||||
f" {self.weapon.description}\n")
|
f" {self.weapon.description}\n")
|
||||||
|
|
||||||
|
def current_inventory(self):
|
||||||
|
"""Prints a list of items in your backpack that aren't equipped to your person."""
|
||||||
|
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:
|
||||||
|
values = item_value.values()
|
||||||
|
values_list = list(values)
|
||||||
|
count_value = {values_list[0]}
|
||||||
|
print(f'{item_key.name} x {count_value}\n'
|
||||||
|
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.'
|
||||||
|
|
||||||
def new_char(self):
|
def new_char(self):
|
||||||
"""Outputs final stats, armour, and inventory"""
|
"""Outputs final stats, armour, and inventory"""
|
||||||
self.allocation()
|
self.allocation()
|
||||||
@@ -135,7 +153,7 @@ class Player:
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
self.current_equip()
|
self.current_equip()
|
||||||
print(' ')
|
print(' ')
|
||||||
# current_inventory()
|
self.current_inventory()
|
||||||
print(' ')
|
print(' ')
|
||||||
|
|
||||||
def health_check(self):
|
def health_check(self):
|
||||||
@@ -158,6 +176,8 @@ class Player:
|
|||||||
# roll 4d6
|
# roll 4d6
|
||||||
for roll in range(4):
|
for roll in range(4):
|
||||||
r = randint(1, 6)
|
r = randint(1, 6)
|
||||||
|
if r < 6:
|
||||||
|
r = randint(1, 6)
|
||||||
rolls.append(r)
|
rolls.append(r)
|
||||||
# Drop the lowest number and then add to single value
|
# Drop the lowest number and then add to single value
|
||||||
del rolls[rolls.index(min(rolls))]
|
del rolls[rolls.index(min(rolls))]
|
||||||
@@ -191,11 +211,13 @@ class Player:
|
|||||||
|
|
||||||
|
|
||||||
class Scene(object):
|
class Scene(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.objects = []
|
||||||
|
|
||||||
def enter(self):
|
# def enter(self):
|
||||||
print(self.name) # works
|
# print(self.name) # works
|
||||||
print(self.descrip) # works
|
# print(self.descrip) # works
|
||||||
# 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):
|
class Engine(object):
|
||||||
@@ -251,11 +273,13 @@ class DamageMod(Enum):
|
|||||||
class Item:
|
class Item:
|
||||||
"""The base class for all items"""
|
"""The base class for all items"""
|
||||||
|
|
||||||
def __init__(self, name, description, value, magical):
|
def __init__(self):
|
||||||
self.name = name
|
self.name = ""
|
||||||
self.description = description
|
self.description = "Not much to look at."
|
||||||
self.value = value
|
self.use_description = "Nothing happens."
|
||||||
self.magical = magical
|
self.aliases = []
|
||||||
|
self.value = ""
|
||||||
|
self.magical = None
|
||||||
|
|
||||||
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"
|
||||||
@@ -264,28 +288,26 @@ class Item:
|
|||||||
class Money(Item):
|
class Money(Item):
|
||||||
"""The currency item used in the world of Kanjin"""
|
"""The currency item used in the world of Kanjin"""
|
||||||
|
|
||||||
def __init__(self, name, amt, magical):
|
def __init__(self):
|
||||||
self.name = name
|
super().__init__()
|
||||||
self.amt = amt
|
self.name = ""
|
||||||
self.magical = magical
|
self.description = f"A small round coin made of {self.name.lower()} " \
|
||||||
super().__init__(name=self.name,
|
f"with the imperial city logo stamped on the face."
|
||||||
description=f"A small round coin made of {self.name.lower()} "
|
self.amt = ""
|
||||||
f"with the imperial city logo stamped on the face.",
|
self.magical = None
|
||||||
value=self.amt,
|
|
||||||
magical=self.magical)
|
|
||||||
|
|
||||||
|
|
||||||
class Weapon(Item):
|
class Weapon(Item):
|
||||||
"""The base class for all weapons"""
|
"""The base class for all weapons"""
|
||||||
|
|
||||||
def __init__(self, name, description, value, damage1H, damage2H, dmgType, dmgMod, vers, thrown, magical):
|
def __init__(self):
|
||||||
self.damage1H = damage1H
|
super().__init__()
|
||||||
self.damage2H = damage2H
|
self.damage1H = None
|
||||||
self.dmgType = dmgType
|
self.damage2H = None
|
||||||
self.dmgMod = dmgMod
|
self.dmgType = None
|
||||||
self.vers = vers
|
self.dmgMod = None
|
||||||
self.thrown = thrown
|
self.versatile = None
|
||||||
super().__init__(name, description, value, magical)
|
self.thrown = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{self.name}\n=====\n{self.description}\nValue: {self.value}" \
|
return f"{self.name}\n=====\n{self.description}\nValue: {self.value}" \
|
||||||
@@ -297,12 +319,12 @@ class Weapon(Item):
|
|||||||
class Armor(Item):
|
class Armor(Item):
|
||||||
"""The base class for all armor"""
|
"""The base class for all armor"""
|
||||||
|
|
||||||
def __init__(self, name, description, value, grade, ac, disadvantage, dmgRes, magical):
|
def __init__(self):
|
||||||
self.grade = grade
|
self.grade = None
|
||||||
self.ac = ac
|
self.ac = None
|
||||||
self.stealthDis = disadvantage
|
self.stealthDis = None
|
||||||
self.dmgRes = dmgRes
|
self.dmgRes = None
|
||||||
super().__init__(name, description, value, magical)
|
super().__init__()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.stealthDis:
|
if self.stealthDis:
|
||||||
@@ -314,40 +336,50 @@ class Armor(Item):
|
|||||||
|
|
||||||
|
|
||||||
# Different types of coins
|
# Different types of coins
|
||||||
GP1 = Money("Gold", 1, False)
|
GP1 = Money()
|
||||||
SP1 = Money("Silver", 1, False)
|
GP1.name = "Gold"
|
||||||
CP1 = Money("Copper", 1, False)
|
GP1.amt = 1
|
||||||
|
GP1.magical = False
|
||||||
|
|
||||||
rock = Weapon(
|
SP1 = Money()
|
||||||
name="Rock",
|
SP1.name = "Silver"
|
||||||
description="A fist-sized rock, suitable for bludgeoning.",
|
SP1.amt = 1
|
||||||
value="No value",
|
SP1.magical = False
|
||||||
damage1H=randint(1, 6),
|
|
||||||
damage2H=0,
|
|
||||||
dmgType=DamageType.CRUSHING,
|
|
||||||
dmgMod=DamageMod.STRENGTH,
|
|
||||||
vers=False,
|
|
||||||
thrown=True,
|
|
||||||
magical=False
|
|
||||||
)
|
|
||||||
tornRags = Armor(
|
|
||||||
name="Torn Rags",
|
|
||||||
description="A ripped and worn-out outfit.",
|
|
||||||
value=0,
|
|
||||||
grade="Light",
|
|
||||||
ac=0,
|
|
||||||
disadvantage=True,
|
|
||||||
dmgRes="None",
|
|
||||||
magical=False
|
|
||||||
)
|
|
||||||
|
|
||||||
# user = Player("Jamie", "Male", 29, "Elf", "Mage")
|
CP1 = Money()
|
||||||
|
CP1.name = "Copper"
|
||||||
|
CP1.amt = 1
|
||||||
|
CP1.magical = False
|
||||||
|
|
||||||
user = Player(*startGame())
|
# starting equip
|
||||||
|
rock = Weapon()
|
||||||
|
rock.name = "Rock"
|
||||||
|
rock.description = "A fist-sized rock, suitable for bludgeoning."
|
||||||
|
rock.value = "No value"
|
||||||
|
rock.damage1H = randint(1, 6)
|
||||||
|
rock.damage2H = 0
|
||||||
|
rock.dmgType = DamageType.CRUSHING
|
||||||
|
rock.dmgMod = DamageMod.STRENGTH
|
||||||
|
rock.vers = False
|
||||||
|
rock.thrown = True
|
||||||
|
rock.magical = False
|
||||||
|
|
||||||
|
tornRags = Armor()
|
||||||
|
tornRags.name = "Torn Rags"
|
||||||
|
tornRags.description = "A ripped and worn-out outfit."
|
||||||
|
tornRags.value = 0
|
||||||
|
tornRags.grade = "Light"
|
||||||
|
tornRags.ac = 0
|
||||||
|
tornRags.disadvantage = True
|
||||||
|
tornRags.dmgRes = "None"
|
||||||
|
tornRags.magical = False
|
||||||
|
|
||||||
|
user = Player("Jamie", "Male", 29, "Elf", "Mage")
|
||||||
|
|
||||||
|
|
||||||
|
# user = Player(*startGame())
|
||||||
|
|
||||||
# enter() needs to return a map name.
|
# enter() needs to return a map name.
|
||||||
|
|
||||||
|
|
||||||
class Begin(Scene):
|
class Begin(Scene):
|
||||||
name = "Kanjin - An RPG Text Adventure"
|
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, " \
|
desc = "Welcome to Kanjin.\nThis game is based off of the D&D SRD ruleset, and will see you, our adventurer, " \
|
||||||
@@ -357,19 +389,25 @@ class Begin(Scene):
|
|||||||
"After character creation, type 'Help' to view a list of commands and explanations."
|
"After character creation, type 'Help' to view a list of commands and explanations."
|
||||||
|
|
||||||
def enter(self):
|
def enter(self):
|
||||||
|
|
||||||
print(f'\n===========\n'
|
print(f'\n===========\n'
|
||||||
f'{self.name}')
|
f'{self.name}')
|
||||||
print(f'\n===========\n'
|
print(f'===========\n'
|
||||||
f'{self.desc}')
|
f'{self.desc}')
|
||||||
|
wait()
|
||||||
user.new_char()
|
user.new_char()
|
||||||
return "Cave entrance"
|
return "Cave entrance"
|
||||||
|
|
||||||
|
|
||||||
class CaveEntrance(Scene):
|
class CaveEntrance(Scene):
|
||||||
name = "Cave Entrance"
|
name = "Cave Entrance"
|
||||||
descTrue = "You are standing at the entryway to a cave."
|
descTrue = "A small broken statue at the mouth of a cave marks the entrance to a dungeon.\n" \
|
||||||
descFalse = "You return to the cave entrance."
|
"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" \
|
||||||
|
"\nBehind you is the forest you traversed through to get here, about 1500m away from the road.\n" \
|
||||||
|
"To the east, a canyon. Too wide to cross and too deep to see the bottom.\n" \
|
||||||
|
"On the west is a mountain face. You are not prepared to take that on.\n"
|
||||||
|
descFalse = "You return to the cave entrance with the road behind you, a canyon to the east, " \
|
||||||
|
"and a mountain face on the right."
|
||||||
has_visited = False
|
has_visited = False
|
||||||
|
|
||||||
def enter(self):
|
def enter(self):
|
||||||
@@ -386,20 +424,19 @@ class CaveEntrance(Scene):
|
|||||||
return "death"
|
return "death"
|
||||||
elif action == "dodge":
|
elif action == "dodge":
|
||||||
return "pod"
|
return "pod"
|
||||||
|
elif action == "start game":
|
||||||
|
return "begin"
|
||||||
else:
|
else:
|
||||||
print("error")
|
print(process_command(*parse(action)))
|
||||||
return "central corridor"
|
|
||||||
|
|
||||||
# def action(self):
|
# def action(self):
|
||||||
# pass
|
# pass
|
||||||
|
|
||||||
|
|
||||||
class A1(Scene):
|
class A1(Scene):
|
||||||
|
name = "Laser Weapon Armory"
|
||||||
def __init__(self):
|
descrip = "Shelves and cases line the walls of this room. Weapons of every description " \
|
||||||
self.name = "Laser Weapon Armory"
|
"fill the shelves and cases. There is a digital keypad set into the wall."
|
||||||
self.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):
|
def enter(self):
|
||||||
print(f'\n===========\n'
|
print(f'\n===========\n'
|
||||||
@@ -454,7 +491,9 @@ class Tutorial(Scene):
|
|||||||
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'."
|
||||||
|
"See what else you can do, then enter 'continue' to move to the next step.")
|
||||||
|
|
||||||
def enter(self):
|
def enter(self):
|
||||||
print(f'\n===========\n'
|
print(f'\n===========\n'
|
||||||
@@ -462,30 +501,31 @@ class Tutorial(Scene):
|
|||||||
f'\n===========\n'
|
f'\n===========\n'
|
||||||
f'{self.descrip}')
|
f'{self.descrip}')
|
||||||
action = input(">> ")
|
action = input(">> ")
|
||||||
|
if action != "continue":
|
||||||
if action == "shoot!":
|
pass
|
||||||
print("result")
|
|
||||||
return "death"
|
|
||||||
elif action == "dodge":
|
|
||||||
print("result")
|
|
||||||
return "pod"
|
|
||||||
else:
|
else:
|
||||||
print("error")
|
process_command(*parse(action))()
|
||||||
return "central corridor"
|
|
||||||
|
|
||||||
def action(self):
|
# if action == "shoot!":
|
||||||
pass
|
# 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 = {
|
||||||
'Cave entrance': CaveEntrance(),
|
'cave entrance': CaveEntrance(),
|
||||||
'A1': A1(),
|
'A1': A1(),
|
||||||
# 'death': Death(),
|
# 'death': Death(),
|
||||||
# 'bridge': TheBridge(),
|
# 'bridge': TheBridge(),
|
||||||
'Tutorial': Tutorial(),
|
'tutorial': Tutorial(),
|
||||||
"begin": Begin()
|
"begin": Begin()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,16 +543,9 @@ class Map(object):
|
|||||||
|
|
||||||
def opening_scene(self):
|
def opening_scene(self):
|
||||||
return self.next_scene(self.start_scene_key)
|
return self.next_scene(self.start_scene_key)
|
||||||
# this function exists only for starting, using the first
|
|
||||||
# string we passed in ('corridor')
|
|
||||||
# it combines the previous 2 functions and is called only once
|
|
||||||
# (called in Engine)
|
|
||||||
|
|
||||||
|
|
||||||
# print("\nType one of the following words: pod, corridor, bridge, armory, death.")
|
seed = "tutorial" # starts the game
|
||||||
seed = "begin" # or input("> ")
|
myMap = Map(seed) # instantiate a new Map object w/ one arg
|
||||||
# this is for testing only - get the "seed" for the map
|
myGame = Engine(myMap) # instantiate a new Engine object w/ one arg
|
||||||
|
myGame.play() # call function from that Engine instance
|
||||||
mymap = Map(seed) # instantiate a new Map object w/ one arg
|
|
||||||
mygame = Engine(mymap) # instantiate a new Engine object w/ one arg
|
|
||||||
mygame.play() # call function from that Engine instance
|
|
||||||
|
|||||||
Reference in New Issue
Block a user