Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

Can't randomize list with classes inside of it Python 2.7.4

I am new to coding and I need some help. I'm trying to randomize these rooms or 'scenes' in a text adventure but whenever I try to randomize it they don't even show up when I run it! Here is the script:

from sys import exit
import time
import random
#import another file here to use in this

class Scene(object):
    def enter(self):
        print "Not yet configured."



class Start():

    def start(self):
        print "Hello. How are you? You are about to play a game that is set in a crazy world."
        print "We are creating your profile right now."
        epic = raw_input("Enter your name here: ")
        print "Hello, %s." % epic
        print "You are being transported to a randomly generated world. Try to survive as long as possible."
        print "Here's some advice, %s: Don't die. Make the right choice. Be careful." % epic
        print "The rules will be shown to you soon."
        print "LOADING..."
        time.sleep(1)
        return Rules().rules()

class Rules(Scene):

    def rules(self):
        print ""
        print "-------------"
        print ""
        print "These are the rules:"
        print "1: Be a good sport. This game takes skill and memory to be able to win, so try your best to succeed."
        print "2: Every time you die, you do not get to respawn, so you will be prompted to either just not play anymore"
        print "or play again. If you decide to play again, you will most likely be on a new world with a new puzzles."
        print "3: Finally, have fun. Hopefully this game brings you joy, so have a great time playing it."
        return random.choice(the_shuffler)

class BoilerRoom(Scene):

    def boiler_room(self):
        print "You are in the boiler room."

class Kitchen(Scene):

    def kitchen(self):
        print "You are in the kitchen."

class Pool(Scene):

    def pool(self):
        print "You are in the pool."

class TennisCourts():

    def tennis_courts(self):
        print "You are in the tennis courts."

class SoccerField():

    def soccer_field(self):
        print "You are on the soccer field."

class Map(object):

    scenes = {
        Rules(): 'rules',
        BoilerRoom(): 'boiler_room',
        Kitchen(): 'kitchen',
        Pool(): 'pool',
        TennisCourts(): 'tennis_courts',
        SoccerField(): 'soccer_field'
    }

the_shuffler = (BoilerRoom, Kitchen, Pool, TennisCourts, SoccerField)

Start().start()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to call the method on the class returned by random.choice(the_shuffler).

It would help if each class had the description printing method named the same.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...