I'm trying to create a text game that presents scenarios in a random order. Based upon a user's answer, certain pre-defined statistics should increase. I took a stab at it, but my loop function will not work (among other things). I attempted to incorporate information from this thread: call list of function using list comprehension
Here is my code:
import random
# A class for the user character. Each character has four stats, which start at zero.
class Character(object):
def __init__(self, sass, intuition, despotism, panache):
self.sass = sass
self.intuition = intuition
self.despotism = despotism
self.panache = panache
sass = 0
intuition = 0
despotism = 0
panache = 0
# a function to check the current stat level of the character.
def all_check(self):
print "Your level of sass is %s." % self.sass
print "Your level of intuition is %s." % self.intuition
print "Your level of despotism is %s." % self.despotism
print "Your level of panache is %s." % self.panache
# I assume that these four "Event" functions should be instances of a class due to each Event's commonalities, but I can't understand how to implement.
def Event1():
print """An attractive woman smiles at you and your friend
from across the bar. Your friend confesses that his passions are arouse, but that he is too shy to do anything. What do you do?"""
print "1. Convince the woman to talk to your friend." #intuition
print "2. Tell the woman to talk to your friend... or else." #despotism
print "3. Inform the woman that your friend has herpes, but that you'd love to take her out." #sass
print "4. Why fight? Let's all go back to her place and get weird." #panache, intuition
inp = raw_input(">>> ")
if inp == '1':
Character.intuition += randint(2,4)
elif inp == '2':
Character.despotism += randint(2,4)
elif inp == '3':
Character.sass += randint(2,4)
elif inp == '4':
Character.panache += randint(1,3)
Character.intuition += randint(1,3)
else:
print "You fail."
# To save space, I'm leaving out Events2~4. They have the same structure as Event1
# Put all the Event functions into a list.
events = [
Event1,
Event2,
Event3,
Event4,
]
# A function to cycle through all the Events in random order.
def play(self):
list = shuffle(events)
for x in list:
x()
# Call a class function to create a unique user.
userName = raw_input("What's your name? ")
# Call function to begin the game.
play()
Character.all_check()
I also realize that the Events are more appropriate as instances of a class, but I'm having trouble understanding Zed's (LPTHW) explanation of classes. Any thoughts are welcome.