import random
dialog = ["hi", "hello", "hey"]
print(random.choice(dialog))
# ...
if a.lower() == "hello":
# ...
x = raw_input("Shall we go?")
if x in ["yes", "yeah", "okay"]:
print("Nice!")
# ...
if a.lower() == "hello":
# ...
flag = True
while flag:
ans = raw_input ("What's the password?")
if (int(ans) == 123456):
flag = False
# you can also use break
print ("You just opened the door!")
1. Make a simple text game that has at least 3 interactions (questions)
# This is not a complete code
def room1():
print('room 1')
loc = raw_input('which room do you want to go?')
return int(loc) # goto room 2
def room2():
print('room 2')
return 1 # goto room 1
location = 1
life = 1
while life:
if location == 1:
location = room1()
if location == 2:
location = room2()
2. Make a game that allows us to take some items (ex: a key for a secret room, treasures)
has_a_key = False
3. Make a game that can show some pictures (or text graphics)
fid = open('c:/temp/1.txt')
data = fid.readlines()
for a in data:
print a,
data from http://www.asciiworld.com/
.
/\ /l
((.Y(!
\ |/
/ 6~6,
\ _ +-.
\`-=--^-'
\ \
_/ \
( . Y
/"\ `--^--v--.
/ _ `--"T~\/~\/
/ " ~\. !
_ Y Y./'
Y^| | |~~7
| l | / ./'
| `L | Y .^/~T
| l ! | |/| | -Row
| .`\/' | Y | !
l "~ j l j_L______
\,____{ __"~ __ ,\_,\_
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4. (advance) Make a game that can save the current status
5. (advance) Discuss how to make a good text game