Update Kanjin-Engine

This commit is contained in:
KansaiGaijin
2022-02-09 20:21:57 +13:00
committed by GitHub
parent 251549c6b5
commit d3c5c40aae

View File

@@ -1,5 +1,6 @@
import time import time
from functions import startGame, wait, parse, get_instructions, query_equip, error_message, change_equip from functions import wait, startGame, query_equip, change_equip, get_instructions
from functions import error_message, parse
from random import randint from random import randint
from enum import Enum, auto from enum import Enum, auto
@@ -7,11 +8,11 @@ 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): class Engine(object):
seed = None
def __init__(self, scene_map): def __init__(self, scene_map):
# self.name = "name" # self.name = "name"
# self.descrip = "descrip" # self.descrip = "descrip"
self.seed = None
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
@@ -168,14 +169,23 @@ class Player:
f' {item_key.description}') f' {item_key.description}')
def drop_item(self, object1): def drop_item(self, object1):
pass x = None
for list_key, list_value in self.inventory.items(): # string, dictionary
if object1 in list_key.name.lower(): # if user input is in the inventory list
x = self.inventory.copy()
del x[list_key]
print("Did I drop it?")
return x
def update_inventory(self, x):
self.inventory = x
def loot_object(self, object1): def loot_object(self, object1):
for scene, room in Map.scenes.items(): # iterate map scenes for scene, room in Map.scenes.items(): # iterate map scenes
if Engine.seed == scene: # set new Engine seed in each room.enter() if Engine.seed == scene: # set new Engine seed in each room.enter()
for list_key, list_value in room.lootable_items.items(): # string, dictionary 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 for var, count in list_value.items(): # variable/object, integer
if object1 in list_key: # if user input is in the lootable items
if var in self.inventory: # if object is in inventory if var in self.inventory: # if object is in inventory
self.inventory[var]["Count"] += count # increase item count self.inventory[var]["Count"] += count # increase item count
@@ -187,7 +197,7 @@ class Player:
"equipped": False} "equipped": False}
print(f'{var.name} x {count} 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 room.lootable_items[object1][var] = 0 # set item to 0
break break
else: else:
print("You don't see one of those to loot.") print("You don't see one of those to loot.")
@@ -197,22 +207,46 @@ class Player:
for scene, room in Map.scenes.items(): # iterate map scenes for scene, room in Map.scenes.items(): # iterate map scenes
if Engine.seed == scene: # set new Engine seed in each room.enter() if Engine.seed == scene: # set new Engine seed in each room.enter()
for list_key, list_value in room.available_items.items(): # string, dictionary 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 for var, count in list_value.items(): # variable/object, integer
if object1 in list_key: # if user input is in the available items
if var in self.inventory: # if object is in inventory response = input(f'There are {room.available_items[object1][var]}.\n'
f'How many will you take?\n>> ').lower()
if response in ("0", "none"):
break
elif response == "all":
if var in self.inventory:
self.inventory[var]["Count"] += count # increase item count self.inventory[var]["Count"] += count # increase item count
print(f'{var.name} x {count} has been added to your existing stack.') print(f'{var.name} x {count} has been added to your existing stack.')
room.available_items[object1][var] = 0
elif var not in self.inventory[var]: # if variable not in inventory elif var not in self.inventory: # if objects not in inventory
self.inventory[var] = {"Count": count, # add it in self.inventory[var] = {"Count": count, # add it in
"object": var.type, "object": var.type,
"equipped": False} "equipped": False}
print(f'{var.name} x {count} has been added to your rucksack.') print(f'{var.name} x {count} has been added to your rucksack.')
room.available_items[object1][var] = 0
elif int(response) <= count:
if var in self.inventory:
self.inventory[var]["Count"] += int(response) # increase item count
print(f'{var.name} x {response} has been added to your existing stack.')
room.available_items[object1][var] = \
room.available_items[object1][var] - int(response)
elif var not in self.inventory: # if objects not in inventory
self.inventory[var] = {"Count": response, # add it in
"object": var.type,
"equipped": False}
print(f'{var.name} x {response} has been added to your rucksack.')
room.available_items[object1][var] = \
room.available_items[object1][var]-int(response)
else:
print("You can't take more than exist.")
del room.available_items[object1] # remove item from available list
break break
elif object1 not in list_key: else:
print("You don't see any lying around..") print("You don't see any lying around..")
break break
@@ -404,6 +438,8 @@ def process_command(command, object1):
output = None output = None
if command == "help": if command == "help":
output = get_instructions() output = get_instructions()
# if command == "scene":
# output = read_room()
elif command == "inventory": elif command == "inventory":
user.current_inventory() user.current_inventory()
elif command == "equipment": elif command == "equipment":
@@ -424,10 +460,24 @@ def process_command(command, object1):
user.loot_object(object1) user.loot_object(object1)
elif command == "error": elif command == "error":
output = error_message() output = error_message()
elif command == "drop":
user.update_inventory(user.drop_item(object1))
return output return output
def read_room():
print("Glancing around the room you see:")
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
for var, count in list_value.items(): # variable/object, integer
available_items = f'{room.available_items[list_key][var]}x {list_key}.'
print(available_items)
if room.available_items[list_key][var] == 0:
del room.available_items[list_key]
# Different types of coins # Different types of coins
GP1 = Money("Gold", 1, False) GP1 = Money("Gold", 1, False)
SP1 = Money("Silver", 1, False) SP1 = Money("Silver", 1, False)
@@ -437,7 +487,7 @@ CP1 = Money("Copper", 1, False)
rock = Weapon( rock = Weapon(
name="Rock", name="Rock",
description="A fist-sized rock, suitable for bludgeoning.", description="A fist-sized rock, suitable for bludgeoning.",
value="No value", value=None,
damage1H=randint(1, 6), damage1H=randint(1, 6),
damage2H=0, damage2H=0,
dmgType=DamageType.CRUSHING, dmgType=DamageType.CRUSHING,
@@ -450,7 +500,7 @@ 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="No Value", value=None,
grade="Light", grade="Light",
ac=0, ac=0,
disadvantage=True, disadvantage=True,
@@ -460,7 +510,7 @@ tornRags = Armor(
paper = Item( paper = Item(
name="Paper", name="Paper",
description="A blank piece of paper", description="A blank piece of paper",
value=0, value=None,
magical=False magical=False
) )
@@ -473,20 +523,19 @@ 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: 12}, "paper": {paper: 3},
"paper": {paper: 3} "rock": {rock: 12}
} }
lootable_items = { lootable_items = {
"chest": {GP1: 5, rock: 1}, "chest": {GP1: 5, rock: 1},
"corpse": {GP1: 100} "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"
@@ -502,15 +551,16 @@ class Tutorial(Scene):
self.has_visited = True self.has_visited = True
action = input(">> ").lower() action = input(">> ").lower()
while action not in ("continue", "scene"): # move scene to parser while action != "continue": # move scene to parser
if action == "scene":
read_room()
action = input(">> ").lower()
else:
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":
print(self.available_items)
return self.current_seed
def action(self): def action(self):
pass pass