[Tutor] help, complete beginner please!
aug dawg
augdawg09 at gmail.com
Sat Aug 28 04:34:19 CEST 2010
Now, I'm no pro at programming in Python, but here's what I recommend you
do. I would have a class at the beginning to define all of the rooms, and
then have the rest of the code below that. Then, it makes it easier to
follow. In addition, I would also have a function that stores the name of
the room in a variable which can then call the "Look around" type function.
I would also have a variable that has the number of all of the gold and then
another one that has the amount of gold that the player has. I would place
the entire program in a loop so that every time the loop runs and checks if
the player has found all of the gold, and if the player has, it acts
accordingly. For example:
class rooms:
(code for the various rooms goes here)
if all_gold != player_gold:
do this
(program goes here)
else:
do this
Regarding the compass part (N, S, E, W) I would also do a bunch of if's
for each possible answer, and then an if on top of those. For example:
if value != None:
if value == whatever_value:
do this
if value == other_value:
do other thing
If you need extra help, just let me know.
On Fri, Aug 27, 2010 at 9:42 PM, kevin hayes <kevinosky at gmail.com> wrote:
> Hi all! I'm trying to write a basic text adventure game to start learning
> python (just for fun). I've gone through the first four chapters of a "learn
> python game programming book" and I'm having trouble with the exercise on
> writing a text adventure. I've been piecing together what is in the book
> with some examples I found online. My goal with this question is not to
> necessarily make the code I've written work, but to gain a fundamental
> understanding of the concepts.
> Can someone show me how to organize a text-based game with these
> things kept in mind: 1)Each room will be a function 2)Direction(N,S,E,W)
> 3)"Look at" 4)Pick Up 5)Quit 6)Accumulated Gold Coins 7) Find all the Gold
> 8)Win/Lose
> I'm looking for the simplest version of this as possible, because
> I'm having trouble with the concepts. I'm only showing my code to give you
> an idea where I'm at. However, I would really like someone to lay out a
> little code structure for me.
>
> I'm using Python 2.6.5 on a Mac Version 10.4.11 and don't consider myself
> computer literate, so bear with my ignorance please.
> Also, don't feel like you have to correct my code...please just
> create your own example of code structure to get me on the right track.
>
> Here is the start of my game:
>
> """FirstGame.py
> First try at creating a text-based adventure game. Trying to learn the
> basics
> of creating functions and using if and loops.
> kevin: 8/27/10"""
>
> keepGoing = True
> while keepGoing == True:
>
> global gold
> gold = 0
>
> def RoomOne():
> print "You find yourself in a large room. Above you is a massive
> crystal"
> print "chandelier. In front of you is round stone fountain, spewing
> water"
> print "from it's center. On the walls hang green satin drapery.
> The ceiling"
> print "is comprised of three ornate arches. There is an arch in
> front of you"
> print "and to your right and left. A staircase leads up from under
> the arch"
> print "in front of you. Under the arches to your left and right are
> large wooden"
> print "doors, each with an iron handle. Enter 'Help' for a full
> list of commands."
> RoomOne()
> Command = raw_input("Please enter a command. ")
> Command = Command.upper()
> if Command == "N":
> RoomFour()
> elif Command == "S":
> print "You ditched the creepy castle and headed for the road."
> keepGoing == False
> elif Command == "E":
> RoomTwo()
> elif Command == "HELP":
> print "List of Commands: 'Help',then enter for this list."
> print "'N', then enter = Door to the North."
> print "'S', then enter = Door to the South."
> print "'E', then enter = Door to the East."
> print "'W', then enter = Door to the West."
> print "'Look at', then 'objects name', then enter
> = Looks at an object."
> print "'Pick Up', then 'objects name', then enter
> = Picks up an object."
> print "'Q', then enter = Quit Game."
>
> elif Command == "W":
> RoomSix()
> elif Command == "LOOK AT FOUNTAIN":
> print "There appears to be 4 gold coins in it."
> elif Command == "PICK UP 4 GOLD COINS":
> gold = gold + 4
> print "Current Gold = ", gold
> elif Command == "Q":
> keepGoing = False
>
> else:
> print "That doesn't work."
>
> def RoomTwo():
> print "Current Gold = ", gold
> print "In the middle of the room is a large Gargoyle with fiery red
> eyes."
> print "He's holding a cup. In the southeast corner of the room you
> see a broom"
> print "with dust and cob-webs on it. Next to the broom is a dead
> rat."
> print "To the north is another door. In front of the door is an
> overturned basket."
>
> promptTwo = raw_input("What are you going to do? ")
> promptTwo = promptTwo.upper()
>
> if promptTwo == "N":
> RoomThree()
> elif promptTwo == "S":
> print "There is no door there."
> elif promptTwo == "W":
> RoomOne()
> elif promptTwo == "E":
> print "There is only a wall there."
> elif promptTwo == "Q":
> keepGoing = False
> elif promptTwo == "PICK UP BASKET":
> print "You pick up the basket, revealing 2 gold pieces."
> RoomTwo()
> elif promptTwo == "PICK UP 2 GOLD COINS":
> gold = gold + 2
> print "Current Gold = ", gold
> RoomTwo()
> elif promptTwo == "LOOK AT GARGOYLE":
> print "Looking at the Gargoyle you notice he's really mean, and
> really still."
> RoomTwo()
> elif promptTwo == "LOOK AT BROOM":
> print "Looking at the broom, you notice it's unnecessarity dirty."
> elif promptTwo == "PICK UP BROOM":
> print " You pick up the broom. But you don't notice anything
> special, so you"
> print "set it back down where it was."
> elif promptTwo == "LOOK AT CUP":
> print "You look at the cup, and find nothing of interest."
> elif promptTwo == "LOOK AT DEAD RAT":
> print "You look at the dead rat and find it utterly disgusting."
> elif promptTwo == "HELP":
> print "List of Commands: 'Help',then enter for this list."
> print "'N', then enter = Door to the North."
> print "'S', then enter = Door to the South."
> print "'E', then enter = Door to the East."
> print "'W', then enter = Door to the West."
> print "'Look at', then 'objects name', then enter
> = Looks at an object."
> print "'Pick Up', then 'objects name', then enter
> = Picks up an object."
> print "'Q', then enter = Quit Game."
> else:
> print "That didn't work."
>
>
> def RoomThree():
> print "Current Gold = ", gold
> print "To the north is a giant replica of a wooley mamoth. His
> tusks are made"
> print "of gold. To the east is a painting of Mother Theresa. Under
> the painting"
> print "is a baby's crib. The only doors you see are to the south
> and west."
>
> promptThree = raw_input("What would you like to do? ")
> promptThree = promptThree.upper()
>
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100827/6ed59b9f/attachment.html>
More information about the Tutor
mailing list