•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 425,929 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,691 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 5900 | Replies: 31
![]() |
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.
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
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.
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
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,468
Reputation:
Rep Power: 10
Solved Threads: 176
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.
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 5:57 pm.
May 'the Google' be with you!
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?
Can you see the problem?
#Text Adventure.py
#By Chris O'Leary
global gold
gold=0
def start():
print '''You find yourself in the foyer of a large house. You
have no idea how you got there. You look around, and see the front door.
It is locked and barred, and the bar is nailed down. There is
no way to open it. There are three other doors in the area. A voice says '50 gold is what you need,
to escape my grasp, of this take heed!'''
print
def foyer():
print "Current Gold = ",gold
print '''You are in the Foyer. The walls are lined with trophy cabinets
and suits of armour. The exits are (N)orth, (E)ast and (W)est.
Type 'Help' for a full list of commands.'''
print
prompt_foy()
def prompt_foy():
prompt_f = raw_input("Type a command: ")
if prompt_f == "W":
reading_room()
elif prompt_f == "Help":
print "Look, Examine (Object), N, W, E, S, Take (Item)"
prompt_foy()
elif prompt_f == "Examine Armour":
print "The armour is rusted, and not of any use."
prompt_foy()
elif prompt_f == "Examine Cabinet":
print '''The cabinet is lined with trophies, dating back to the 1800s.
Seems this was a talented family.'''
prompt_foy()
elif prompt_f == "S":
if gold < 50:
print "You can't get out untill you have 50 gold."
prompt_foy()
def reading_room():
print "Current Gold = ",gold
print '''You are in an large reading room. The room is stuffed with novels
and poetry books on every shelf. There is a large table in the middle
of the room. It has a reading lamp, and a cluster of books scattered about
on top. The exits are (N)orth and (E)ast. Type 'Help' for a full list of
commands.'''
print
prompt_rea()
def prompt_rea():
prompt_r = raw_input("Type a command: ")
if prompt_r == "E":
foyer()
elif prompt_r == "Help":
print "Look, Examine (Object), N, W, E, S, Take (Item)"
prompt_rea()
elif prompt_r == "Look":
"You see 30 gold pieces on the table."
prompt_rea()
elif prompt_r == "Take Gold":
print "You get 30 gold!"
gold = gold+30
reading_room()
start()
foyer()Can you see the problem?
•
•
Join Date: Apr 2006
Posts: 140
Reputation:
Rep Power: 3
Solved Threads: 26
•
•
•
•
Can you see the problem?def prompt_rea(): global gold .... ....
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 5:42 am.
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.
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 12:45 pm.
drink her pretty
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
Other Threads in the Python Forum
- Previous Thread: Python ISU
- Next Thread: MySQL + Python



Linear Mode