Exemplo n.º 1
0
def add_high_score(game):
    """Adds this game to the list of high scoring games and bumps the lowest
    game from the high score list."""
    # add the new high score
    newhs = HighScore()
    newhs.name = str(game.player)
    newhs.score = game.score
    put_safe(newhs)

    # remove the lowest score
    q = db.GqlQuery(GQL_HIGH_SCORES)
    hscores = q.fetch(1, NUM_HIGH_SCORES)
    if len(hscores) > 0:
        db.delete(hscores)
Exemplo n.º 2
0
def get_high_scores():
    """Returns an array of the top NUM_HIGH_SCORES high scores."""
    # make sure this is the user' first time playing
    q = db.GqlQuery(GQL_HIGH_SCORES)
    hscores = q.fetch(NUM_HIGH_SCORES)

    # pad out the list with junk if we don't have the min # of high scores yet
    num_missing = NUM_HIGH_SCORES - len(hscores)
    if num_missing > 0:
        junk_entry = HighScore()
        junk_entry.name = '???'
        junk_entry.date = None
        junk_entry.score = 0
        hscores += (num_missing * [junk_entry])

    return hscores