Add high score list support for arogue5.
This commit is contained in:
parent
30bdbebf0b
commit
44d2b92159
1 changed files with 38 additions and 2 deletions
|
|
@ -44,7 +44,7 @@ pend = "</body></html>\n"
|
||||||
|
|
||||||
# This would be more useful if we had to do translation
|
# This would be more useful if we had to do translation
|
||||||
headerbook = {"endt":"End time", "score":"Score", "name":"Name", "xl":"XL",
|
headerbook = {"endt":"End time", "score":"Score", "name":"Name", "xl":"XL",
|
||||||
"fate":"Fate", "rank":"Rank", "game":"Game"}
|
"fate":"Fate", "rank":"Rank", "game":"Game", "class": "Class"}
|
||||||
# Queries for the games table
|
# Queries for the games table
|
||||||
offselstr = "SELECT offbytes FROM games WHERE gname = %s;"
|
offselstr = "SELECT offbytes FROM games WHERE gname = %s;"
|
||||||
newoffstr = "UPDATE games SET offbytes = %s WHERE gname = %s;"
|
newoffstr = "UPDATE games SET offbytes = %s WHERE gname = %s;"
|
||||||
|
|
@ -397,7 +397,42 @@ class ARogueGame(Game):
|
||||||
rankfields = ["rank", "score", "name", "class", "xl", "fate", "endt"]
|
rankfields = ["rank", "score", "name", "class", "xl", "fate", "endt"]
|
||||||
pfields = ["score", "class", "xl", "fate", "endt"]
|
pfields = ["score", "class", "xl", "fate", "endt"]
|
||||||
def getHigh(self, n=10, offset=0):
|
def getHigh(self, n=10, offset=0):
|
||||||
|
"Gets the n highest scores (starting at offset) from the database, \
|
||||||
|
returning a list of dicts."
|
||||||
|
qstr = "SELECT endt, score, name, xl, class, fate FROM {0} ORDER BY score DESC ".format(self.uname)
|
||||||
|
qvals = []
|
||||||
|
try:
|
||||||
|
n = int(n)
|
||||||
|
except (ValueError, TypeError):
|
||||||
return []
|
return []
|
||||||
|
if n <= 0:
|
||||||
|
return []
|
||||||
|
qstr += " LIMIT %s"
|
||||||
|
qvals.append(n)
|
||||||
|
try:
|
||||||
|
offset = int(offset)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return []
|
||||||
|
if n > 0:
|
||||||
|
qstr += " OFFSET %s"
|
||||||
|
qvals.append(offset)
|
||||||
|
qstr += ";"
|
||||||
|
conn = psycopg2.connect("dbname=rlg")
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute(qstr, qvals)
|
||||||
|
dictlist = []
|
||||||
|
for record in cur:
|
||||||
|
ndict = {"game": self}
|
||||||
|
ndict["endt"] = record[0]
|
||||||
|
ndict["score"] = record[1]
|
||||||
|
ndict["name"] = record[2]
|
||||||
|
ndict["xl"] = record[3]
|
||||||
|
ndict["class"] = record[4]
|
||||||
|
ndict["fate"] = record[5]
|
||||||
|
dictlist.append(ndict)
|
||||||
|
cur.close()
|
||||||
|
conn.close()
|
||||||
|
return dictlist
|
||||||
def getRecent(self, n=20):
|
def getRecent(self, n=20):
|
||||||
return []
|
return []
|
||||||
def getPlayer(self, player):
|
def getPlayer(self, player):
|
||||||
|
|
@ -426,6 +461,7 @@ def playerpage(pname):
|
||||||
ppagefi.write("<div>" + pname + " has not yet completed an expedition\
|
ppagefi.write("<div>" + pname + " has not yet completed an expedition\
|
||||||
in this dungeon.</div>\n")
|
in this dungeon.</div>\n")
|
||||||
else:
|
else:
|
||||||
|
entries.sort(key=lambda e: e["endt"])
|
||||||
printTable(entries, RogueGame.pfields, ppagefi)
|
printTable(entries, RogueGame.pfields, ppagefi)
|
||||||
scoresum = 0
|
scoresum = 0
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue