943,935 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 19518
  • Python RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 15th, 2006
0

How would I make a text adventure?

Expand Post »
Just wondering how the game would be put together, maybe even a step by step tutorial. I could use this to practice with the commands used without Tkinter or Pygame. This could be a good learning experience.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
chris99 is offline Offline
118 posts
since Sep 2006
Sep 15th, 2006
0

Re: How would I make a text adventure?

The easiest game would be with a number of rooms. Draw yourself a map of 9 rooms (maybe a 3x3 pattern). Make notes on the map about details of the room, number of doors, contents, pictures, furniture and so on.

Let's say you come into the first room from the south. Now this room has a total of 4 doors, one to the south (S) where you came in, one to the east (E), north (N) and west (W). Ask the player which door he/she wants to enter. Like: "You want to go E, N or W?"

Rooms may have 2, 3 or 4 doors. Now the adventure begins. Some rooms contain a strength potion, or weapon, or some treasure, or cryptic instructions to read, or monsters to fight. When you fight a monster you lose strength. Some monsters are stronger than others. The player starts with a certain amount of strength points and gains more strength by picking up strength potions. Also loses less strength by picking up a better weapons. Each weapon has hit points, the more the better!

Describe the new room as the player enters. Like: "You entered a room that is painted green. There is a picture on the wall of an elderly gentleman. There are 5 gold pieces on the table for you. There are doors to the E and W. Do you want to go E or W?"

The rest is up to your imagination. When the player finds enough treasure (say 50 gold pieces total), he/she will have to get back to the exit alive to win the game. The room descriptions will aid. To make things more difficult, add a basement (stairs/doors to go down or D) or an upstairs (U) floor.

Show the player's present strength, weapon, gold pieces collected, and so on somehere on the screen.
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005
Sep 16th, 2006
0

Re: How would I make a text adventure?

I meant, should I def a room class, and make room objects with specific instructions?
Reputation Points: 10
Solved Threads: 0
Junior Poster
chris99 is offline Offline
118 posts
since Sep 2006
Sep 16th, 2006
0

Re: How would I make a text adventure?

Could someone please help me by telling me what code structure I should use, and an example? I'm trying, but I have no idea how to make it work. I've tried making a Room class, and making each room a sub-class am I on the right track? I just need pointing in the right direction.
Reputation Points: 10
Solved Threads: 0
Junior Poster
chris99 is offline Offline
118 posts
since Sep 2006
Sep 16th, 2006
0

Re: How would I make a text adventure?

It depends what you want to do. If you just want to make a simple fun game, there is no need for class objects. If you want to to do this to learn OOP, then by all means go for it. Your progress will be initially slow, because there is quite a learning curve.

Your approach making a class Room with the basics that all rooms can share, and then a class for each individual room that inherits the class Room makes the most sense. However, a lot of thought has to be put into this approach before any of the fun starts.

Just let us know what you have come up with, and how you would test each class to make sure it does what you want it to do.
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005
Sep 16th, 2006
0

Re: How would I make a text adventure?

Text based role playing games (RPG) used to be plentiful in the early days of personal computing. Usually written in Basic, C or Pascal, but I have not seen just a text based RPG in a modern language like Python.

I would most likely define a function for each room and handle all the descriptions, actions, and connections to other rooms from there. Looks like an interesting project and a good way to learn Python skills! Later, as the project grows, you can use classes to group the functions together.

You could start with a 3 by 3 cluster of connected rooms and ask the player to explore all the rooms with the least amount of moves. Hide a few gold pieces and maybe add a secret door or two that can be opend by solving a riddle. As you get the hang of it, you can add weapons, monsters, spells and potions.

There are some GUI based RPGs on the PyGame website, but that gets to be pretty large and complex for beginners.
Last edited by vegaseat; Sep 16th, 2006 at 6:57 pm.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 17th, 2006
0

Re: How would I make a text adventure?

Doing one command at a time, teting each one. Need help, I tried defining gold as a global variable, as it wasn't working when I just created it out of the loop, but the Reading Room won't add 30 gold Where am I going wrong?

Python Syntax (Toggle Plain Text)
  1. #Text Adventure.py
  2. #By Chris O'Leary
  3.  
  4. global gold
  5. gold=0
  6.  
  7. def start():
  8. print '''You find yourself in the foyer of a large house. You
  9. have no idea how you got there. You look around, and see the front door.
  10. It is locked and barred, and the bar is nailed down. There is
  11. no way to open it. There are three other doors in the area. A voice says '50 gold is what you need,
  12. to escape my grasp, of this take heed!'''
  13. print
  14.  
  15. def foyer():
  16. print "Current Gold = ",gold
  17. print '''You are in the Foyer. The walls are lined with trophy cabinets
  18. and suits of armour. The exits are (N)orth, (E)ast and (W)est.
  19. Type 'Help' for a full list of commands.'''
  20. print
  21. prompt_foy()
  22.  
  23. def prompt_foy():
  24. prompt_f = raw_input("Type a command: ")
  25. if prompt_f == "W":
  26. reading_room()
  27. elif prompt_f == "Help":
  28. print "Look, Examine (Object), N, W, E, S, Take (Item)"
  29. prompt_foy()
  30. elif prompt_f == "Examine Armour":
  31. print "The armour is rusted, and not of any use."
  32. prompt_foy()
  33. elif prompt_f == "Examine Cabinet":
  34. print '''The cabinet is lined with trophies, dating back to the 1800s.
  35. Seems this was a talented family.'''
  36. prompt_foy()
  37. elif prompt_f == "S":
  38. if gold < 50:
  39. print "You can't get out untill you have 50 gold."
  40. prompt_foy()
  41.  
  42. def reading_room():
  43. print "Current Gold = ",gold
  44. print '''You are in an large reading room. The room is stuffed with novels
  45. and poetry books on every shelf. There is a large table in the middle
  46. of the room. It has a reading lamp, and a cluster of books scattered about
  47. on top. The exits are (N)orth and (E)ast. Type 'Help' for a full list of
  48. commands.'''
  49. print
  50. prompt_rea()
  51.  
  52. def prompt_rea():
  53. prompt_r = raw_input("Type a command: ")
  54. if prompt_r == "E":
  55. foyer()
  56. elif prompt_r == "Help":
  57. print "Look, Examine (Object), N, W, E, S, Take (Item)"
  58. prompt_rea()
  59. elif prompt_r == "Look":
  60. "You see 30 gold pieces on the table."
  61. prompt_rea()
  62. elif prompt_r == "Take Gold":
  63. print "You get 30 gold!"
  64. gold = gold+30
  65. reading_room()
  66. start()
  67. foyer()
  68.  

Can you see the problem?
Reputation Points: 10
Solved Threads: 0
Junior Poster
chris99 is offline Offline
118 posts
since Sep 2006
Sep 17th, 2006
0

Re: How would I make a text adventure?

Click to Expand / Collapse  Quote originally posted by chris99 ...

Python Syntax (Toggle Plain Text)
  1.  
  2. def prompt_rea():
  3. global gold
  4. ....
  5. ....
Can you see the problem?
if you want to use gold as global, u might like to put "global gold" inside prompt_rea()
Last edited by ghostdog74; Sep 17th, 2006 at 6:42 am.
Reputation Points: 75
Solved Threads: 44
Junior Poster
ghostdog74 is offline Offline
156 posts
since Apr 2006
Sep 17th, 2006
0

Re: How would I make a text adventure?

Thanks, it works now!
Reputation Points: 10
Solved Threads: 0
Junior Poster
chris99 is offline Offline
118 posts
since Sep 2006
Sep 17th, 2006
0

Re: How would I make a text adventure?

You are off to an interesting start! Nice foyer, hehe, almost like mine at home!

Declare the variable gold global in each function that uses this global variable. This would also apply to strength, weapons, or any monster-kill flags. If a monster has been killed in a room you can set the flag so that this monster does not attack again. Of course you could revive the monster and make things much more difficult.

Sorry, I just realized that in your first version you might not go with monsters yet. Just explore, find enough gold, and get out! It will be interesting to read all your room descriptions.
Last edited by Ene Uran; Sep 17th, 2006 at 1:45 pm.
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: SQLite and Placeholder
Next Thread in Python Forum Timeline: How to sort files by name and delete in Python...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC