Creating a leaderboard for offline game in Python

前端 未结 1 528
情深已故
情深已故 2021-01-22 02:34

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 s

相关标签:
1条回答
  • 2021-01-22 02:43

    The easiest is probably to just use mongodb or something (mongo DB is a nosql type database that allows you to save dictionary data easily...)

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

    (You will need pymongo as well easy_install pymongo ).

    then you can simply save records there

    from pymongo import MongoClient
    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 doesnt 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"})
    from pymongo import DESCENDING
    #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).

    0 讨论(0)
提交回复
热议问题