How would I make a text adventure?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2006
Posts: 109
Reputation: chris99 is an unknown quantity at this point 
Solved Threads: 0
chris99's Avatar
chris99 chris99 is offline Offline
Junior Poster

How would I make a text adventure?

 
0
  #1
Sep 15th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: How would I make a text adventure?

 
0
  #2
Sep 15th, 2006
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.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 109
Reputation: chris99 is an unknown quantity at this point 
Solved Threads: 0
chris99's Avatar
chris99 chris99 is offline Offline
Junior Poster

Re: How would I make a text adventure?

 
0
  #3
Sep 16th, 2006
I meant, should I def a room class, and make room objects with specific instructions?
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 109
Reputation: chris99 is an unknown quantity at this point 
Solved Threads: 0
chris99's Avatar
chris99 chris99 is offline Offline
Junior Poster

Re: How would I make a text adventure?

 
0
  #4
Sep 16th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: How would I make a text adventure?

 
0
  #5
Sep 16th, 2006
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.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,145
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 949
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: How would I make a text adventure?

 
0
  #6
Sep 16th, 2006
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.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 109
Reputation: chris99 is an unknown quantity at this point 
Solved Threads: 0
chris99's Avatar
chris99 chris99 is offline Offline
Junior Poster

Re: How would I make a text adventure?

 
0
  #7
Sep 17th, 2006
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?

  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?
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 153
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 40
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: How would I make a text adventure?

 
0
  #8
Sep 17th, 2006
Originally Posted by chris99 View Post

  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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 109
Reputation: chris99 is an unknown quantity at this point 
Solved Threads: 0
chris99's Avatar
chris99 chris99 is offline Offline
Junior Poster

Re: How would I make a text adventure?

 
0
  #9
Sep 17th, 2006
Thanks, it works now!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: How would I make a text adventure?

 
0
  #10
Sep 17th, 2006
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.
drink her pretty
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 10557 | Replies: 32
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC