Reina
October 12th, 2012, 04:49 AM
Warning: programmer thread.
I've been playing around with file relationships and Python 2.7, and as a little project decided to make a text-based game through Command Prompt that allows you to save your progress at certain checkpoints and pick up where you left off.
I've been doing that by writing in random keyphrases into a .txt file, then making my program read specific lines and check for matches. Does anyone here have a better method?
Here's a small snippet from my code for you guys to get a better feel for it: (Oh dear, there's no support for indentation here... my apologies for the jumbled up format.)
print "What would you like to do?"
print "[NewGame/Continue]"
action = raw_input("> ")
if action == "NewGame":
NewAccount(" ")
elif action == "Continue":
Continue(" ")
yn = raw_input("> ")
if yn == "Y":
f = open('C:/Users/Me/Desktop/filewrite.txt', 'r')
for count in range(1,4):
f.readline()
time.sleep(1)
print "..."
time.sleep(1)
print "File loaded. Please type",
print f.readline(),
print "to load save."
savefile = raw_input("> ")
if savefile == "asdf123":
room1(" ")
elif savefile == "13412341":
room2(" ")
elif savefile == "okjlflwoi":
room3(" ")
elif yn == "N":
print "Would you like to make a new account?"
print "[Y/N]"
yn2 = raw_input("> ")
if yn2 == "Y":
NewAccount(" ")
elif yn2 == "N":
Continue(" ")
I know, I'm sort of a noob to Python, and I probably did a lot wrong. I'd love some feedback nonetheless! ^.^
I've been playing around with file relationships and Python 2.7, and as a little project decided to make a text-based game through Command Prompt that allows you to save your progress at certain checkpoints and pick up where you left off.
I've been doing that by writing in random keyphrases into a .txt file, then making my program read specific lines and check for matches. Does anyone here have a better method?
Here's a small snippet from my code for you guys to get a better feel for it: (Oh dear, there's no support for indentation here... my apologies for the jumbled up format.)
print "What would you like to do?"
print "[NewGame/Continue]"
action = raw_input("> ")
if action == "NewGame":
NewAccount(" ")
elif action == "Continue":
Continue(" ")
yn = raw_input("> ")
if yn == "Y":
f = open('C:/Users/Me/Desktop/filewrite.txt', 'r')
for count in range(1,4):
f.readline()
time.sleep(1)
print "..."
time.sleep(1)
print "File loaded. Please type",
print f.readline(),
print "to load save."
savefile = raw_input("> ")
if savefile == "asdf123":
room1(" ")
elif savefile == "13412341":
room2(" ")
elif savefile == "okjlflwoi":
room3(" ")
elif yn == "N":
print "Would you like to make a new account?"
print "[Y/N]"
yn2 = raw_input("> ")
if yn2 == "Y":
NewAccount(" ")
elif yn2 == "N":
Continue(" ")
I know, I'm sort of a noob to Python, and I probably did a lot wrong. I'd love some feedback nonetheless! ^.^