[Tutor] Hands-on beginner's project?

nathan virgil sdragon1984 at gmail.com
Fri Oct 3 16:24:19 CEST 2008


On Fri, Oct 3, 2008 at 10:02 AM, Luke Paireepinart
<rabidpoobear at gmail.com>wrote:

> On Fri, Oct 3, 2008 at 8:50 AM, nathan virgil <sdragon1984 at gmail.com>
> wrote:
> >
> >
> > On Fri, Oct 3, 2008 at 9:19 AM, David <david at abbottdavid.com> wrote:
> >>
> >> > Okay, I'm resurrecting this project.
> >> Where is this project code?
> > It seems like good code,
> It's not.
>
>
> > # Content
> > # retrieve data for current room
> > room = 1
> > if room == 1:
> this is always true because you just set room to 1 right before you
> checked the variable.
> >     desc = "Ahead of you, you see a chasm."
> >     ques = "Do you wish to try jumping over it? Y/N"
> >     destYes = 2
> >     destNo = 3
> > elif room == 2:
> this will never be true, which is why you can't get into the second room.
> This whole thing needs to be in a loop.
> But this is definitely not the best way to implement this either.
>
> >     desc = "Ahead of you, you see a warty green ogre."
> >     ques = "Do you wish to eat it? Y/N"
> >     destYes = 4
> >     destNo = 5
> > # etc for the rest of the rooms
> He's wiring these rooms together with numbers.  The way I'd do it is
> to create a Room object with a bunch of different methods, such as
> room.print(), room.printDescription(), room.makeChoice(), and such,
> and then the rooms would be connected together using data members.
> It would be a lot more elegant and less confusing that way.
>
> >
> > # Engine
> > # ask current question and move to next room
> > print desc
> > ans = raw_input(ques).upper() # allow for lower case input
> > if ans == "Y":
> >     room = destYes
> > elif ans == "N":
> >     room = destNo
> > elif ans == "north":
> >     room = destN
> > elif ans == "south":
> >     room = destS
> > elif ans == "east":
> >     room = destE
> > elif ans == "west":
> >     room = destW
> > elif ans == "Q": # give us a way out.
> >     Break
> > else:
> >     print "I don't understand. Can you give a clearer answer?"
>
> You prompted the user, then retrieved the next room value.
> Now we're here, and there's no code left.  So it stops here.
>
> >
> but for some reason, it's not letting me go into
> > Room 2 (the ogre).
> Is it clearer why this isn't working now?
>


Erm, no, not really. Are you saying I need to take out those last two lines?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/ba7a7459/attachment.htm>


More information about the Tutor mailing list