Je travaille actuellement sur Apprenez Python à la dure par Zed Shaw. Je me bats avec l'exercice 43, ce qui m'a instruit de créer un jeu de texte avec les propriétés suivantes:Apprenez Python à la dure, exercice 43
- Utilise plus de 1 fichier
- une classe par « chambre »
Jusqu'à présent, j'ai a commencé deux fichiers, l'un pour le coureur et l'autre avec les chambres:
game_runner.py
from game_map import *
class Runner(object):
def __init__(self, start):
self.start = start
def play(self):
next_room = self.start
while True:
print '\n'
print '-' * 7
print next_room.__doc__
next_room.proceed()
firstroom = Chillin()
my_game = Runner(firstroom)
my_game.play()
game_map.py
from sys import exit
class Chillin(object):
"""It's 8pm on a Friday night in Madison. You're lounging on the couch with your
roommates watching Dazed and Confused. What is your first drink?
1. beer
2. whiskey
3. vodka
4. bowl
"""
def __init__(self):
self.prompt = '> '
def proceed(self):
drink = raw_input(self.prompt)
if drink == '1' or drink == 'beer':
print '\n Anytime is the right time.'
print 'You crack open the first beer and sip it down.'
room = Pregame()
return room
#rest of drinks will be written the same way
class Pregame(object):
"""It's time to really step up your pregame.
How many drinks do you take?
"""
def proceed(self):
drinks = raw_input('> ')
#and so on
Mon problème est que je ne peux pas obtenir le game_runner de passer à la pièce suivante. Quand je l'exécute, il joue une boucle infinie de la première pièce: imprime la docstring pour Chillin(), demande une entrée, puis répète.
Comment puis-je modifier mon coureur et/ou ma carte pour renvoyer la classe suivante, c'est-à-dire le nom de règle(), après avoir entré une réponse correcte dans la première classe?
homme, ce code ressemble à une publicité de bière avec un message subliminal – juliomalegria