High score

edited April 2017 in How To...

Hi there

We're (Me and my team) building a game which consists on simply running from a light and the more you survive the higher is the score.

I'm trying to create a high score board where it saves the highest scores in a .txt file , even after the program is closed.Plus , I would like it to sort the scores if a new score is on the 10 firsts. Like if the score is between 4th-400 and 3rd-500, it erases the last one and it takes the place of the 4th one.

I want it to be able to save the user's initials ( like in old arcade machine).

Problem is, I have no single Idea how to do it. I tried to search out on the Internet but I don't understand nothing...

Could I please get some help to start?

Tagged:

Answers

  • Answer ✓

    OK here you can let the user input text:

    the user's initials ( like in old arcade machine).

    https://github.com/Kango/Processing-snippets/tree/master/InputBox

    here you can sort :

    int[] numbers = new int[20];
    
    void setup() {
      size(1000, 1000);
    
      int num =0;
      for (int x =0; x< 20; x++) {
        num =int(random(10, 50));
        numbers [x] = num ;
      }
    
      println(numbers);
      numbers = sort(numbers);
    
      println("\nsorted");
      println(numbers);
    }
    
    void draw() {
    
      background(255);
    }
    //
    

    Now.

    You got an name CB and a score

    try toSort = score+"#"+name;

    now sort it

    say

        for-loop
    
            String[] result = split(toSort, '#'); 
    

    etc.

    NOW II

    use saveStrings and

    use loadString

    see reference

  • I see... Let me see if I can do it all by myself I'll ask something if it does not work or there's a simple bug. Anyway, thanks for your help. Very much

  • show your attempt as code

  • I appreciate the Help you gave for the username, but I prefer to use ReadBox. It will be kind of simplistic but well...

    Now, I don't know where to fit your toSort = score+"#"+name; , I just tried to do my way ( a messy way by the way).

    And my problem is that SaveStrings doesn't actually.. Save my strings.. I mean , I transformed my int table for a String Table to be able to give a string next to my score. Now it shows the score + the username. However , when I try to do this again by changing drastically the score and the name to see if I can still see my previous score.. It has already forgot it...

    Have you a solution ? And, do you know how to show a table in the drawing window, starting from the highest value on the top and the lowest on the bottom, vertically?

    If you desire you can change the code or enhance it.


    import readBox.*;

    int[] numbers = new int[100]; String toSort; int score = 90; String[] result ;

    void setup() {

    result = loadStrings("noteblack.txt"); int num =0; String nam = new Dialog().readString("ton nom plis");

    for (int x =0; x< 100; x++) { num =int(random(0, 100)); numbers [x] = num ;

    }

    println(numbers); numbers = sort(numbers);

    println("\nsorté"); println(numbers); result = str(numbers); result[score] = score + "#" + nam;

    println(result); saveStrings("noteblack.txt",result); }

    void draw() {

    background(255); }

    // void insert new score(){ int j; for(j = 100; j > 0 && numbers[j-1] > score; score--){ numbers[j] = numbers[j-1];

    numbers[j] = score;
    

    } }

Sign In or Register to comment.