Quote:
Originally Posted by titaniumdecoy
Actually you can, although the result might not be what you would expect:
>>> print '%s' % ([1,2] * 2)
[1, 2, 1, 2]
>>> print '%s' % [1,2] * 2
[1, 2][1, 2]
|
Deters from my point. But yes...
@Chuckiferd:
As far as a "proper" implementation of this idea can go, it would take some familiarity with Python.
For a personal learning exercise, I'd say just go with if, print, and input statements. Those three things in conjunction could make your game.
If you want to actually do visible movement, you won't be able to do it this way...
A print statement outputs something to the user:
print "You Are At The Beginning Of A Yellow Brick Road"
The input function gets something from the user:
choice = input("""What do you want to do?
1) Walk In To The House
2) Pick Up A Penny Off The Ground
3) Twiddle Thumbs
Enter A Number: """)
That will output to the screen:
Quote:
What do you want to do?
1) Walk In To The House
2) Pick Up A Penny Off The Ground
3) Twiddle Thumbs
Enter A Number: <space for typing>
|
And prompt the user to type a number where I wrote <space for typing>. After this line executes, the variable "choice" will equal the number the user selected.
An if statement can branch your program in an alternate direction, according to the value of a variable. So if we wanted to do one thing if the user selected "1", and another if the user selected "2", it's as simple as:
if choice == 1:
# The user selected 1. Do something here.
elif choice == 2:
# The user selected 2. Do something different here.
else:
# The user did not select 1 or 2. Make it default to option #3. And do something else!
These three things, "if", "print", and "input" could be combined to make your text adventure:
print "You Are At The Beginning Of A Yellow Brick Road"
choice = input("""What do you want to do?
1) Walk In To The House
2) Pick Up A Penny Off The Ground
3) Twiddle Thumbs
Enter A Number: """)
print
if choice == 1:
print "The house feels warm and welcoming, but a strange man (most likely the owner) is sitting on the couch looking very frightened of your presence."
choice = input("""What do you want to do?
1) Quickly Apologize And Leave
2) Ask Him Who's House This Is
3) Enter Battle Mode!
Enter A Number: """)
print
if choice == 1:
print "etc"
elif choice == 2:
print "etc etc"
else:
print "etc etc etc"
elif choice == 2:
print "The penny was actually a piece of radioactive material. You sit there shocked and confused, and die 30 years later."
print "Game Over"
else:
print "While you're twiddling your thumbs, you notice there's a penny on the ground! But before you can pick it up an old man comes out of a house and snatches it from you, then heads back inside."
choice = input("""What do you want to do?
1) Follow The Man Into His House
2) Continue Walking Down The Road
3) Continue To Twiddle Thumbs
Enter A Number: """)
print
if choice == 1:
print "etc"
elif choice == 2:
print "etc etc"
else:
print "etc etc etc"
Get it?
Here's an example of me running the programming, and playing the adventure:
Quote:
You Are At The Beginning Of A Yellow Brick Road
What do you want to do?
1) Walk In To The House
2) Pick Up A Penny Off The Ground
3) Twiddle Thumbs
Enter A Number: 1
The house feels warm and welcoming, but a strange man (most likely the owner) is sitting on the couch looking very frightened of your presence.
What do you want to do?
1) Quickly Apologize And Leave
2) Ask Him Who's House This Is
3) Enter Battle Mode!
Enter A Number: 3
etc etc etc
|
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.