Last active
August 29, 2015 14:03
-
-
Save Torxed/259dc0a2765264fefd00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
class Game(object): | |
def __init__(self): | |
self.experience = 0 | |
self.health = 0 | |
self.loadedFromDisk = False | |
def give_xp(self, given_xp): | |
self.experience += given_xp | |
def save_variables(self): | |
with open('game.dump', 'wb') as fh: | |
pickle.dump({'xp' : self.experience, 'hp' : self.health}, fh) | |
def load_variables(self): | |
if not self.loadedFromDisk: | |
with open('game.dump', 'rb') as fh: | |
data = pickle.load(fh) | |
self.experience = data['xp'] | |
self.hp = data['hp'] | |
self.loadedFromDisk = True | |
gamehandle = Game() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment