Skip to content Skip to sidebar Skip to footer

Creating A Leaderboard For Offline Game In Python

For a school project, I'm creating a game that has a score system, and I would like to create some sort of leaderboard. Once finished, the teachers will upload it to a shared serve

Solution 1:

The easiest is probably to just use MongoDB or something (MongoDB is a NoSQL type database that allows you to save dictionary data easily...)

You can use the free account at https://mongolab.com (that should give you plenty of space).

You will need pymongo as well pip install pymongo.

Then you can simply save records there:

from pymongo import MongoClient, DESCENDING

uri = "mongodb://test1:test1@ds051990.mongolab.com:51990/joran1"
my_db_cli = MongoClient(uri)
db = my_db_cli.joran1  # select the database ... 

my_scores = db.scores  # this will be created if it doesn't exist!
# add a new score
my_scores.insert({"user_name": "Leeeeroy Jenkins", "score": 124, "time": "11/24/2014 13:43:22"})
my_scores.insert({"user_name": "bob smith", "score": 88, "time": "11/24/2014 13:43:22"})

# get a list of high scores (from best to worst)
print(list(my_scores.find().sort("score", DESCENDING)))

Those credentials will actually work if you want to test the system (keep in mind I added leeroy a few times).


Post a Comment for "Creating A Leaderboard For Offline Game In Python"