随机化函数,记录字符统计信息

时间:2015-04-20 02:56:44

标签: python class python-2.7 for-loop

我正在尝试创建一个以随机顺序显示方案的文字游戏。根据用户的答案,某些预定义的统计信息应该增加。我抓了它,但我的循环功能不起作用(除此之外)。我试图合并来自这个帖子的信息:call list of function using list comprehension

这是我的代码:

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()

我也意识到事件更适合作为课程的实例,但我无法理解Zed(LPTHW)对课程的解释。欢迎任何想法。

0 个答案:

没有答案