Skip to content

The possiblity to save and load #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 84 additions & 24 deletions adventure.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ def castle():
print (" + ||: . ||: , +++++++ . . ||: | +")
print (" ||: . ||: , +++++++ . . ||: | *")
print (" ||: . ||: , +++++++ . . ||: |")
def end():
print "This is where this template ends, this is now YOUR world, build your adventure and share it with the world"

print (" _ _ _")
print (" /_\ __| |_ _____ _ __ | |_ _ _ _ __ ___")
print (" //_\\ / _` \ \ / / _ \ '_ \| __| | | | '__/ _ \ ")
print( "/ _ \ (_| |\ V / __/ | | | |_| |_| | | | __/")
print ("\_/ \_/\__,_| \_/ \___|_| |_|\__|\__,_|_| \___|")

print (" _ _")
print (" __ ___ ____ _(_) |_ ___")
print (" / _` \ \ /\ / / _` | | __/ __|")
print ("| (_| |\ V V / (_| | | |_\__ \ ")
print (" \__,_| \_/\_/ \__,_|_|\__|___/")

print (" _ _ ___ _ _")
print ("| | | |/ _ \| | | |")
print ("| |_| | (_) | |_| |")
print (" \__, |\___/ \__,_|")
print ( " |___/")


def north():
print "To go north press n then enter"
Expand All @@ -56,8 +77,11 @@ def setup():
#Our variable "name" is used to store our name, captured by keyboard input.
name = raw_input("What is your name warrior? ")
#randint is a great way of adding some variety to your players statistics.
HP = randint(5,20)
MP = randint(5,20)
if raw_input("Do you want to start with a saved game? (y|n)") == "y":
load()
else:
HP = randint(5,20)
MP = randint(5,20)

def villager():
#This will create a randomly named Villager to interact with
Expand Down Expand Up @@ -128,7 +152,31 @@ def ranger():
shuffle(response)
message = response[0]
print message

def save():
global HP
global MP
global name
ts=strftime("%Y%b%d-%H%M%S")
fname="adventure-" +name
fobj=open(fname, "w")
if (fobj):
fobj.write(str(HP)+";"+str(MP))
fobj.close()
print "Spielstand gespeichert\n"
else:
print "konnte Datei nicht anlegen\n"
def load():
global HP
global MP
global name
fname = "adventure-" + name
fobj = open(fname, "r")
HP = int(fobj.read(2))
fobj.seek(3)
MP = int(fobj.read(2))
print ("\nDaten gelesen")
fobj.close()

#We now use our functions in the game code, we call the title, the castle picture and then ask the game to run the setup for our character.
clear_screen()
title()
Expand Down Expand Up @@ -222,7 +270,19 @@ def ranger():
heal()
else:
print "\nYou run away from the " + enemyname + "."
sys.exit(0)
print"\nDo you want to save your progress?"
if raw_input()=="yes":
save()
end()
sys.exit(0)
else:
save()
end()
sys.exit(0)
if raw_input("\nDo you want to save the game") == "yes":
save()
end()

if move != 's':
fight = raw_input("\nDo you wish to fight?" )

Expand All @@ -239,6 +299,14 @@ def ranger():
print "Gratulation! You won and got" +" "+ str(mp)+" "+"Magic Points. Your Helthpoints: " + str(HP)
MP = MP +mp
print "\nyour Magicpoints: " + str(MP) +"\n"
print "\nDo you want to save the progress?"
if raw_input=="yes":
save()
else:
sys.exit(0)



else:
enemyhit = randint(0,5)
print "The ogre swings a club at you and causes " + str(enemyhit) + " of damage"
Expand All @@ -249,24 +317,16 @@ def ranger():

else:
print "You turn and run away from the ogre"
print "/nDo you want to save your progress?"
if raw_input() == "yes":
save()
end()
sys.exit(0)
else:
print "Do you want to save the game?"
if raw_input() == "yes":


print "This is where this template ends, this is now YOUR world, build your adventure and share it with the world"

print " _ _ _"
print " /_\ __| |_ _____ _ __ | |_ _ _ _ __ ___"
print " //_\\ / _` \ \ / / _ \ '_ \| __| | | | '__/ _ \ "
print "/ _ \ (_| |\ V / __/ | | | |_| |_| | | | __/"
print "\_/ \_/\__,_| \_/ \___|_| |_|\__|\__,_|_| \___|"

print " _ _"
print " __ ___ ____ _(_) |_ ___"
print " / _` \ \ /\ / / _` | | __/ __|"
print "| (_| |\ V V / (_| | | |_\__ \ "
print " \__,_| \_/\_/ \__,_|_|\__|___/"

print " _ _ ___ _ _"
print "| | | |/ _ \| | | |"
print "| |_| | (_) | |_| |"
print " \__, |\___/ \__,_|"
print " |___/"
save()
end()
else:
end()
92 changes: 70 additions & 22 deletions adventure_python3.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ def castle():
print (" ||: . ||: , +++++++ . . ||: | *")
print (" ||: . ||: , +++++++ . . ||: |")

def end():
print("This is where this template ends, this is now YOUR world, build your adventure and share it with the world")

print(" _ _ _")
print(" /_\ __| |_ _____ _ __ | |_ _ _ _ __ ___")
print(" //_\\ / _` \ \ / / _ \ '_ \| __| | | | '__/ _ \ ")
print("/ _ \ (_| |\ V / __/ | | | |_| |_| | | | __/")
print("\_/ \_/\__,_| \_/ \___|_| |_|\__|\__,_|_| \___|")

print(" _ _")
print(" __ ___ ____ _(_) |_ ___")
print(" / _` \ \ /\ / / _` | | __/ __|")
print("| (_| |\ V V / (_| | | |_\__ \ ")
print(" \__,_| \_/\_/ \__,_|_|\__|___/")

print(" _ _ ___ _ _")
print("| | | |/ _ \| | | |")
print("| |_| | (_) | |_| |")
print(" \__, |\___/ \__,_|")
print(" |___/")


def north():

print("To go north press n")
Expand All @@ -65,8 +87,11 @@ def setup():
#Our variable "name" is used to store our name, captured by keyboard input.
name = input("What is your name warrior? ")
#randint is a great way of adding some variety to your players statistics.
HP = randint(5,20)
MP = randint(5,20)
if input("\nDo you want to load a game(y|n)\n") == "y":
load()
else:
HP = randint(5,20)
MP = randint(5,20)

def villager():
#This will create a randomly named Villager to interact with
Expand Down Expand Up @@ -138,6 +163,32 @@ def ranger():
message = response[0]
print(message)

def save():
global HP
global MP
global name
ts=strftime("%Y%b%d-%H%M%S")
fname="adventure-" +name
fobj=open(fname, "w")
if (fobj):
fobj.write(str(HP)+";"+str(MP))
fobj.close()
print ("Spielstand gespeichert\n")
else:
print ("konnte Datei nicht anlegen\n")
def load():
global HP
global MP
global name
fname = "adventure-" + name
fobj = open(fname, "r")
HP = int(fobj.read(2))
fobj.seek(3)
MP = int(fobj.read(2))
print ("\nDaten gelesen")
fobj.close()


#We now use our functions in the game code, we call the title, the castle picture and then ask the game to run the setup for our character.
clear_screen()
title()
Expand Down Expand Up @@ -231,7 +282,15 @@ def ranger():
heal()
else:
print("\nYou run away from the " + enemyname + ".")
sys.exit(0)
if input("\n Do you want to save your progress?(y|n)") == "y":
save()
end()
else:
end()
if input("Do you want to save?(y|n)") == "y":
save()
end()

if move != 's':
fight = input("\nDo you wish to fight?" )

Expand All @@ -258,24 +317,13 @@ def ranger():

else:
print("You turn and run away from the ogre")
if input("Do you want to save the progress?(y|n)") == "y":
save()
end()
else:
print("ok, you didn't want to save your progress!!")
end()




print("This is where this template ends, this is now YOUR world, build your adventure and share it with the world")

print(" _ _ _")
print(" /_\ __| |_ _____ _ __ | |_ _ _ _ __ ___")
print(" //_\\ / _` \ \ / / _ \ '_ \| __| | | | '__/ _ \ ")
print("/ _ \ (_| |\ V / __/ | | | |_| |_| | | | __/")
print("\_/ \_/\__,_| \_/ \___|_| |_|\__|\__,_|_| \___|")

print(" _ _")
print(" __ ___ ____ _(_) |_ ___")
print(" / _` \ \ /\ / / _` | | __/ __|")
print("| (_| |\ V V / (_| | | |_\__ \ ")
print(" \__,_| \_/\_/ \__,_|_|\__|___/")

print(" _ _ ___ _ _")
print("| | | |/ _ \| | | |")
print("| |_| | (_) | |_| |")
print(" \__, |\___/ \__,_|")
print(" |___/")