Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 1, 2010, 08:21 AM   #1
Nsutton
macrumors member
 
Join Date: Dec 2009
Location: 6 Feet Under
Text Based Adventure? (Python)

How would you go about making a text based adventure in python?

Nothing too fancy. I was thinking I would have a door to escape but you have to gather a certian amount of keys. So an inventory type thing would be need..

Any step by step tutorial that can help me?
__________________
An Apple a day keeps viruses away!
Nsutton is offline   0 Reply With Quote
Old Apr 1, 2010, 09:46 AM   #2
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Quote:
Originally Posted by Nsutton View Post
How would you go about making a text based adventure in python?

Nothing too fancy. I was thinking I would have a door to escape but you have to gather a certian amount of keys. So an inventory type thing would be need..

Any step by step tutorial that can help me?
Don't take this the wrong way, but the number one skill that is essential to programming is problem solving. I think you would probably get more out of the exercise if you actually try and work this out yourself.

Obviously if you have a specific question for a certain part then lots of people would be glad to help, but working out the flow of data for instance and how to interact with the user is vital stuff and you'll learn more doing it yourself than following someone else's written tutorial on the subject.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Apr 1, 2010, 10:12 AM   #3
Nsutton
Thread Starter
macrumors member
 
Join Date: Dec 2009
Location: 6 Feet Under
I understand. It's probably better to learn on my own.

But i just need an starting point because i have no idea what to even start with/
__________________
An Apple a day keeps viruses away!
Nsutton is offline   0 Reply With Quote
Old Apr 1, 2010, 11:53 AM   #4
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
Here's an example thought process:

What is an inventory? Hm, it's a list of items.
OK, how do I make a list in Python? <googles python list> The first hit is http://docs.python.org/tutorial/datastructures.html
Scrolling down to the examples it looks like I can make a list with this syntax:
Code:
nameOfList = [item1, item2, item3];
and add items to a list like so:
Code:
nameOfList.append(item4);
So, if the player's inventory starts out empty, I'll need
Code:
inventory = [];
Catfish_Man is offline   0 Reply With Quote
Old Apr 1, 2010, 11:56 AM   #5
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Okay, think about the flow of the program. What happens when the user first executes the program? How does the user then proceed through the program? Do you use a menu based approach? Or some other method?

How are you going to store information about the character that the user is playing as? What information should you store?

You should probably look into the object orientated features that Python offers. One of the major advantages that object orientated programming offers is the ability to think about discreet things rather than data structures. So you have a character rather than a linked list or a struct that represents a character. You can also perform actions on that object that change its properties. This helps immensely when thinking about to implement a program.

Just don't get carried away and try and implement everything all at once as that will just get you down in the end. Stick to one feature at a time.

Edit:

Semi-colons are evil .
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Apr 1, 2010, 12:58 PM   #6
notjustjay
macrumors 603
 
notjustjay's Avatar
 
Join Date: Sep 2003
Location: Canada, eh?
When talking about making higher-level applications like games and business applications, what's more important than the programming language is some concept of how you're going to organize and arrange your data, and more specifically how you're going to model the "world" in which your program will work.

For example, if you're writing PowerPoint, your "world" consists of slides, and the objects that appear on each slide. If you're writing iTunes, your world is a list of media files. If you're writing an e-commerce system, your world consists of lists of products and customer accounts.

In the case of an adventure game, we really mean "world" in the literal sense!

So let's start by looking at some of the basic requirements of a text adventure game like the old Zork games or MUD/MOO type games that used to occupy so much of my time. Well, at its heart, the world consists of rooms. You start in one room, and you can move in the cardinal compass directions, north, east, south, west, up, down. Each move, if one is possible, leads you to another room.

Your game, once complete, will consist of hundreds or thousands of possible rooms, each interconnecting with other rooms. Each room will have its own name and description.

Before you even think about what programming language you're going to use (be it Python, Java, C++, whatever) you need to think about how your data is going to be stored.

You might recognize that "items of data connected to other items of data" sounds like a tree structure or a multiply-linked list. Each room (and its description) could be a node in the tree or list, and the links between nodes represents the available pathways between the rooms.

So now you have a starting point. You can decide to model your world like this, with each node (a room) having the following information:

- The room ID number (as you give this some thought, you realize that every room is going to have to have one)
- The room title ("A Dark Cave")
- The room description ("You step into a dark cave. Boy, it's sure dark!")
- The ID number of the room to the north (if any)
- The ID number of the room to the south (if any)
- The ID number of the room to the east (if any)
- The ID number of the room to the west (if any)

So now you start to design the data structures. Next you will want to ask, what do I DO with those data structures? This will be the game "engine", which is essentially:

Print the description of the current room.
Get instructions from the user.
Process those instructions.
If the instructions are movement, go to the room the user requested (if possible).
If the instructions can't be followed, print an error message.
Repeat these steps until the game is over!


You will eventually add more, such as fighting characters, processing items in inventory, and so on. But this is the starting point.
__________________
.

Last edited by notjustjay; Apr 1, 2010 at 10:06 PM.
notjustjay is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
OS-neutral: Telnet/Text adventure games Astroboy907 Mac and PC Games 8 Feb 23, 2014 12:27 PM
Ads based on text messages agffth iPhone and iPod touch Apps 7 Feb 3, 2014 11:07 AM
[Free] Adventure Game - Jet Adventure jasonnthk iPhone and iPod touch Apps 0 Dec 10, 2013 09:10 AM
Python IDE or text editor that can recognize API specific syntax thekev Mac Programming 2 Sep 4, 2012 05:49 AM

Forum Jump

All times are GMT -5. The time now is 05:19 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC