Hello Again,
Sorry, I took a break for a week.
I am trying to get my head around how I make the playerclass and have the players level cross-over to each stage.
Here is all the code (the engine I import has not changed):
from fundamentals import engine
from sys import exit
import random
from random import randint
from sys import argv
script, name = argv
player = {
'name': name,
'lvl' : 1,
'xp' : 0,
'lvlnext' : 25,
'secretcode' : False,
'stats' : {'charisma' : 1}}
def level(char, stats):
nchar = 0
while player['xp'] >= player['lvlnext']:
player['lvl'] += 1
player['xp'] = player['xp'] - ['lvlnext']
player['lvlnext'] = round(player['lvlnext'] * 1.5)
stats['charisma'] += 1
class stage(object):
def __init__(self):
pass
def enter(self):
pass
class failure(stage):
wrong = [
"Sorry. That just won't cut it.",
"Nice try..."
"No. Just no."]
def enter(self):
print(failure.wrong[randint(0, len(self.wrong)-1)])
exit()
class entrance(stage):
def enter(self):
print(f"""Hi there {name}. There is not a lot of time so i'll make it quick.
You are entering the building of a top criminal who is throwing a party at his house.
It is your job to find and escape with the intel and to do so unnoticed.
There are 2 Guards at the door. What do you do?
1. Wait for distraction.
2. Talk your way in.
3. Attack them.
""")
action = input("> ")
if action == "1":
print("You wait untill two hysteric lady's distract the guards and sneek by the guards.")
return'ballroom'
elif action == "2":
print("""
Ha. You still got it. You fooled the guards into thinking you are managing the diner.
That's a nice confidence booster.""")
player['xp'] += round(25 * 1.5 * (player['stats']['charisma'] - 1))
return'ballroom'
elif action == "3":
print("""You managed to knock both of them out roadhouse style.
However, this made to big of a scene. You cannot continue the mission.""")
return'failure'
class ballroom(stage):
def enter(self):
print("""
Great. You are in the ballroom. It is pretty crowded in here.
You need to use the staircase, which is closed off for visitors.
Find a way to get upstairs without bringing any attention to yourself.
What do you do?
1. Just go.
2. Improvise an excuse to go upstairs.
3. Find another way up.
""")
action = input("> ")
if action == "1":
print("Exactly. Sometimes it is best to not overthink things.")
return'privateroom'
elif action == "2":
banter = random.randint(0,3)
if player['stats']['charisma'] >= 2 and banter >= 1:
print("You are too slick.")
player['xp'] += round(25 * 1.5 * (player['stats']['charisma'] - 1))
return'privateroom'
elif player['stats']['charisma'] < 2 and banter >= 2:
print("You are too slick.")
player['xp'] += round(25 * 1.5 * (player['stats']['charisma'] - 1))
return'privateroom'
else:
print("You get slapped across the face because you were being rude.")
return'failure'
elif action == "3":
print("""
You get noticed while snooping around by a drunk partygoer.
What do you do?
1. Go back.
2. Take away suspision.
""")
decision = input("> ")
if decision == "1":
player['stats']['charisma'] -= 1
return'ballroom'
elif decision == "2":
delude = random.randint(0,3)
if player['stats']['charisma'] >= 2 and delude >= 1:
print(f"""
You are too slick.
As you find another way up you find a note with 3 numbers on it.
""")
player['xp'] += round(25 * 1.5 * (player['stats']['charisma'] - 1))
player['secretcode'] == True
return'privateroom'
elif player['stats']['charisma'] < 2 and delude >= 2:
print("You are too slick.")
player['xp'] += round(25 * 1.5 * (player['stats']['charisma'] - 1))
return'privateroom'
else:
print("""
Whatever you said, the wanderer didn't like it and
is starting to gain the attention from some guards""")
return'failure'
class privateroom(stage):
def enter(self):
print("""
You entered the privateroom but there is no sign of any intel.
On the wall to your right, there is a device that requires a code.
""")
print("repr player", repr(player['stats']))
if player['secretcode'] == True:
print("You enter the 3 digits that were on the note that you found. Bingo!")
return'secretdoorway'
elif player['secretcode'] == False:
guess = input("> ")
guesses = 0
code = f"{random.randint(0,9)}{random.randint(0,9)}{random.randint(0,9)}"
while guesses != 9 and guess != code:
guesses += 1
print(f"Wrong, you've got {10 - guesses} left.")
guess = input("> ")
if guess == code:
print("cracked the code!")
return'secretdoorway'
else:
print("The alarm goes off. You're screwed")
return'failure'
class secretdoorway(stage):
def enter(self):
print("""
While you walk to the secretdoorway to pick up the intel,
The daughter of the criminal boss walks in on you.
Girl: I already suspected something was wrong. You were looking very suspicious
What do you do?
1. Find an excuse?
2. Try to take her out without hurting her?
3. Charm the girl.
""")
action = input("> ")
if action == 1:
print("""
You give up the intel and convince the girl you are lost/
However, by doing so you lost the intel.""")
return'failure'
elif action == 2:
print("""
Little did you know that the girl has a black belt in brazilian jiu jitsu.
You get slapped around and then captured.""")
return'failure'
elif action == 3:
print("Very bold move.")
if player['stats']['charisma'] == 1:
print("""
It seems like you've lost your former charm with the lady's.
After some failed attempts to impress her you get a drink in your face
And the guards are called.""")
return'failure'
elif player['stats']['charisma'] == 2:
print("""
By talking to the girl you find out that she does not like her dad at all.
You persuade her to let you go for the greater good.
""")
return'carraige'
elif player['stats']['charisma'] == 3:
print("""
Damn. Your game is on fleek. You seduced the girl into coming with you.
""")
class carriage(stage):
def enter(self):
print("""
You made it out with the intel.
Great job! Surely the boss will promote you now""")
class carriage_and_girl(stage):
def enter(self):
print("""
You made it out with the intel and the lovely lady.
Great job! That 'll make for a great story""")
class world(object):
stages = {
'entrance': entrance(),
'ballroom': ballroom(),
'privateroom': privateroom(),
'secretdoorway': privateroom(),
'failure' : failure(),
'carriage': carriage()
}
def __init__ (self, start_stage):
self.start_stage = start_stage
def next_stage(self, stage_name):
next = world.stages.get(stage_name)
return next
def opening_stage(self):
return self.next_stage(self.start_stage)
a_world = world('entrance')
a_game = engine(a_world)
a_game.play()
When I run this and I get to the privateroom stage, where I have my debugging line:
class privateroom(stage):
def enter(self):
print("""
You entered the privateroom but there is no sign of any intel.
On the wall to your right, there is a device that requires a code.
""")
print("repr player", repr(player['stats']))
It gives me the following output:
repr player {âcharismaâ: 1}
This means that the xp gains are not carried over from scene to scene. How do I go about this? And would the way I go about this, change, if I were to make a class out of the player?
Thanks in advance.
PS: I read the pytest link, but am not sure how to implement it if I were to rebuild the code.