Reverend Jim commented: It's not polite to shout. Please do not post in ALL CAPS. -3

Dani AI

Generated

A compact, practical approach for : treat the high score as data saved to a small local file (JSON is simple and human-readable). For a typical "guess the number" game the metric is usually "fewer attempts is better". Below are minimal helper functions and a short usage example that can be dropped into the end-of-game logic.

import json
import os

HS_FILE = 'highscore.json'

def load_highscore(path=HS_FILE):
    if not os.path.exists(path):
        return None
    try:
        with open(path, 'r') as f:
            return json.load(f)
    except (IOError, ValueError):
        return None

def save_highscore(name, attempts, path=HS_FILE):
    current = load_highscore(path)
    if current is None or attempts < current.get('attempts', float('inf')):
        new = {'name': name, 'attempts': attempts}
        with open(path, 'w') as f:
            json.dump(new, f)
        return True
    return False

Usage example (call after the player finishes guessing):

player = 'player_name'
attempts = number_of_attempts  # integer counted by the game
if save_highscore(player, attempts):
    print('New high score!')
else:
    print('Current best:', load_highscore())

Troubleshooting and extension notes: run this on a local filesystem (some online REPLs have ephemeral storage). Handle the first-run case (file missing) and corrupted JSON as shown. If a leaderboard of top N is wanted, store a list of score objects and sort by attempts. For concurrency or multi-user deployments use SQLite or a proper backend. As pointed out, include the actual end-of-game snippet and any traceback when requesting help; that makes it much easier to spot mistakes like comparing the wrong value, writing to an unexpected path, or swallowing exceptions.

Recommended Answers

All 5 Replies

This question or need appears well done. As in there are priors to read such as https://www.daniweb.com/programming/software-development/threads/98387/guessing-game-in-c-help-high-score

It's your choice how to create such a system but it continues to be pretty much like what you find in prior discussions on high score systems.

Unless I totally misread what you needed and you wanted others to write the code for you.

and yes i need someone to make the code
accoring to my game

https://www.daniweb.com/welcome/rules notes you have to show your efforts. I see no code there as if you begin to implement any high score system.

This means you are shopping this work as a "for hire" task. Here it's all about you learning about possible solutions as well as you writing the code. If you are stuck with say, how do I declare a variable then you ask that and the response could be a terse tutorial or references to tutorials. Again, if you are asking for others to write your app, then be sure to lay out pay, time to when it needs to get done, deliverables and all the missing details.

i have tried to do if you scroll down through my project close to the end

Since you didn't post the code in the forum I gave it a cursory look and missed your effort as it's over 100 lines of code. That does not matter as you wrote "i need someone to make the code".

Why do you think what you have has failed?
Was there an assignment where this feature was detailed out? Such as must it save locally or to say some social media high score web page?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.