Exemplo n.º 1
0
def load_players():
    global players, winners
    allplayers = []
    players = []
    winners = []
    try:
        filename = game.make_dataname('players')
        allplayers = pickle.load(open(filename, 'rb'))
        for p in allplayers:
            if p.winner:
                winners.append(p)
                if not hasattr(p, "lives"):
                    p.lives = 0
                if not hasattr(p, "skips"):
                    p.skips = 0
                if not hasattr(p, "cheater"):
                    p.cheater = 0
            else:
                players.append(p)
                if not hasattr(p, "help"):
                    p.help = {}
                if not hasattr(p, "lives"):
                    p.lives = p.score * 2
                if not hasattr(p, "skips"):
                    p.skips = 0
                if not hasattr(p, "cheater"):
                    p.cheater = 0
    except (IOError, OSError, KeyError, IndexError):
        players = []
Exemplo n.º 2
0
def load_prefs():
    try:
        filename = game.make_dataname("prefs")
        for line in open(filename).readlines():
            name, val = [s.strip() for s in line.split("=")]
            setattr(game, name, int(val))
    except (IOError, OSError, KeyError):
        # print 'ERROR OPENING PREFS FILE'
        pass
Exemplo n.º 3
0
def save_prefs():
    try:
        filename = game.make_dataname("prefs")
        f = open(filename, "w")
        for p in Prefs.keys():
            val = getattr(game, p)
            f.write("%s = %d\n" % (p, int(val)))
        f.close()
    except (IOError, OSError):
        # print 'ERROR SAVING PREFS FILE'
        pass
Exemplo n.º 4
0
def save_players():
    allplayers = players + winners
    try:
        filename = game.make_dataname('players')
        f = open(filename, 'wb')
        p = pickle.Pickler(f, 1)
        p.dump(allplayers)
        f.close()
    except (IOError, OSError), msg:
        import messagebox
        messagebox.error("Error Saving Player Data",
"There was an error saving the player data.\nCurrent player data has been lost.\n\n%s"%msg)
Exemplo n.º 5
0
def save_prefs():
    """
    Salva as preferencias do jogador.
    """
    try:
        filename = game.make_dataname('prefs')
        f = open(filename, 'w')
        for p in Prefs.keys():
            val = getattr(game, p)
            f.write("%s = %d\n" % (p, int(val)))
        f.close()
    except (IOError, OSError), msg:
        pass
Exemplo n.º 6
0
def load_prefs():
    """
    Carrega as preferencias antigas do jogador
    (salvas no arquivo prefs)
    """
    prefs = {}
    try:
        filename = game.make_dataname('prefs')
        for line in open(filename).readlines():
            name, val = [s.strip() for s in line.split('=')]
            setattr(game, name, int(val))
    except (IOError, OSError, KeyError):
        pass
Exemplo n.º 7
0
    def loadnews(self):
        self.cleartext()
        self.imgs = []
        self.boxes = []
        newsfilename = game.make_dataname('news')
        if not os.path.isfile(newsfilename):
            newsfilename = game.get_resource('news')
        if os.path.isfile(newsfilename):
            news = open(newsfilename).readlines()
            if not news:
                self.makebadnews(' ', 'Invalid News File')
                return
            self.newsversion = news[0].split()[-1]
            newsitems = []
            title = date = None
            body = []
            for line in news[2:]:
                line = line.rstrip()
                if not line:
                    if title: newsitems.append((title, date, body))
                    title = date = None
                    body = []
                elif not title: title = line
                elif not date: date = line
                else: body.append(line)
	
            if title and date and body:
                newsitems.append((title, date, body))

            top = 150
            for t, d, body in newsitems:
                self.boxes.append(objbox.Box((28, top+3), 1))
                self.boxes[-1].rotspeed = 2.0
                self.boxes[-1].rotate = 0.0
                text, r = self.rendertext(0, t)
                trect = r.move(60, top)
                self.imgs.append((text, trect))
                text, r = self.rendertext(1, d)
                r = r.move(trect.right + 25, top+10)
                self.imgs.append((text, r))
                top = trect.bottom
                for b in body:
                    text, r = self.rendertext(2, b)
                    r = r.move((100, top))
                    top = r.bottom
                    self.imgs.append((text, r))
                top += 24
        else:
            self.makebadnews(' ', 'Cannot Download News')
Exemplo n.º 8
0
def downloadfunc(gamenews):
    global news_downloaded
    try:
        news = urllib.urlopen(game.news_url).readlines()
    except:
        gamenews.downcur = 3
        return
    gamenews.downcur = 0
    try:
        newsfilename = game.make_dataname('news')
        f = open(newsfilename, 'w')
        for l in news:
            if l:
                f.write(l.rstrip() + os.linesep)
        f.close()
        gamenews.success = 1
        news_downloaded = 1
    except (IOError, OSError):
        gamenews.downcur = 3