Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 18th, 2007, 6:14 PM   #31
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 843
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: I'm a Beginner

There was recently a fairly detailed discussion about text-based game design in Python in this forum.
titaniumdecoy is offline   Reply With Quote
Old Dec 18th, 2007, 6:21 PM   #32
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: I'm a Beginner

Quote:
Originally Posted by Sane View Post
It will get messy really quick. But I think you'll learn something. You will need to do some really basic stuff to get comfortable with Python.
Wow. that helped... alot. I suddenly think I am really getting it. I was reading your example and it just hit me. So I get how to pretty much run any text based adventure now. Thank you. The two thing I don't get is the tripple quotes and the 'elif' command. I thought it was just 'if' then the rest were 'else'

ok now let me run this again.

print 'you are at the beginning of a yellow brick road: you see one exit, east'

choice = input ("""enter a command""")

print

if choice == east:

    print 'you are in the middle of the yellow brick road: you see two exits, east and west'

    choice = input ("""enter a command""")
    
    print

    if choice == east:
         print 'you are at the end of the yellow brick road, you loose your balance and fall off the face of the earth'  
    elif choice == west:
         print 'you try going back and are killed by the wicked witch of the west'

print 'Thank you for playing my first game'
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.

Last edited by Chuckiferd; Dec 18th, 2007 at 6:39 PM.
Chuckiferd is offline   Reply With Quote
Old Dec 18th, 2007, 6:42 PM   #33
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: I'm a Beginner

Quote:
Originally Posted by Chuckiferd View Post
Wow. that helped... alot. I suddenly think I am really getting it. I was reading your example and it just hit me. So I get how to pretty much run any text based adventure now. Thank you. The only thing I don't get is the 'elif' command. I thought it was just 'if' then the rest were 'else'
I'm glad. You're welcome.

Good question. The only difference between an 'if' command and an 'elif' command, is the 'elif' expression can not be satisifed if the 'if' expression was already satisfied.

Here's an example:

if 1 == 1:
    print "We are at the first block"
elif 1 == 1:
    print "We are at the second block"

This will output:
Quote:
We are at the first block
But why? 1==1 for the "elif" block, so why can't we see the second print statement?

The answer is because the first "if" block already executed. Any "elif" or "else" that proceeds the executed "if" will not be executed.

Further demonstrating this fact:

if 1 == 1:
    print "We are at the 0th block"
if 1 == 1:
    print "We are at the 1st block"

if 9 == 0:
    print "We are at the 2nd block"
elif 1 == 1:
    print "We are at the 3rd block"
elif 1 == 1:
    print "We are at block 3 and a half"
else:
    print "We are at the 4th block"

if 9 == 0:
    print "We are at the 5th block"
elif 9 == 0:
    print "We are at the 6th block"
else:
    print "We are at the 7th block"

This will output:
Quote:
We are at the 0th block
We are at the 1st block
We are at the 3rd block
We are at the 7th block
Do you understand why that's the output that occurs?

Last edited by Sane; Dec 18th, 2007 at 6:58 PM.
Sane is offline   Reply With Quote
Old Dec 18th, 2007, 6:47 PM   #34
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: I'm a Beginner

Your code's very close to working. There's just a couple small problems:

If you want the user to enter text, as opposed to a number, you use "raw_input".

raw_input("Enter Command: ") is for text.
input("Enter Number: ") is for numbers.

Then to compare a variable to text, the text has to be wrapped in quotation marks. This is because otherwise it thinks you are trying to refer to a variable name.

Variable names do not use quotes. Numbers do not use quotes. Text does use quotes.

if choice == "east" compares the variable choice to the text east.
if choice == east compares the variable choice to the variable east.
if choice == "1" compares the variable choice to the text 1.
if choice == 1 compares the variable choice to the number 1.

So that gives you now:
print 'you are at the beginning of a yellow brick road: you see one exit, east'

choice = raw_input ("""enter a command""")

print

if choice == "east":

    print 'you are in the middle of the yellow brick road: you see two exits, east and west'

    choice = raw_input ("""enter a command""")
    
    print

    if choice == "east":
         print 'you are at the end of the yellow brick road, you loose your balance and fall off the face of the earth'  
    elif choice == "west":
         print 'you try going back and are killed by the wicked witch of the west'

print 'Thank you for playing my first game'
Sane is offline   Reply With Quote
Old Dec 18th, 2007, 7:37 PM   #35
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: I'm a Beginner

I meant the tripple quotes in
Quote:
Originally Posted by in my first game it is written
("""enter a command""")
anyways (chuckferd rubs his hands together) it is time for me to seek how to write a combat system. Once I can write something like that I can probally write anything, right? Thank you again for helping me out
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.
Chuckiferd is offline   Reply With Quote
Old Dec 18th, 2007, 7:55 PM   #36
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 843
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: I'm a Beginner

Triple quotes can contain strings that span multiple lines. Although I am not sure why Sane is using them for strings that do not do so.
titaniumdecoy is offline   Reply With Quote
Old Dec 18th, 2007, 9:13 PM   #37
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: I'm a Beginner

@Chuck:

Well you'll soon find out that you need to learn a bit more. When you run into trouble, do some reading up on "Functions" in Python. They can be used to create subroutines, which will be necessary for making anything larger or more complicated.

@titaniumdecoy:

I used them because he used them.

Read my post that used triple quotes on a multiline string. Then his post that used it on a single line string. Then mine that copy pasted his.
Sane is offline   Reply With Quote
Old Dec 19th, 2007, 1:09 PM   #38
Namingishard
Newbie
 
Join Date: Feb 2006
Location: TX
Posts: 23
Rep Power: 0 Namingishard is on a distinguished road
Send a message via AIM to Namingishard Send a message via MSN to Namingishard
Re: I'm a Beginner

As for the Pong game try http://freshmeat.net/projects/tompong/ simple pong game should help you out.

P.S sorry if this was already posted I admit I didn't read all four pages of post.
Namingishard is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner Problem proudnerd C++ 16 May 18th, 2006 6:48 PM
call of a beginner web_master HTML / XHTML / CSS 34 Dec 6th, 2005 12:08 AM
function help for a beginner melee28 C 6 Sep 5th, 2005 9:45 AM
what open source code is good to read for a beginner? linuxpimp20 Other Programming Languages 22 Aug 30th, 2005 3:01 PM
Beginner program problem (else if) Hadrurus Java 13 Aug 14th, 2005 7:07 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC