This component can be used to take care of the scoreboard in javascript games. This component handles all the code necessary for adding user data to a scoreboard in the form of a javascript object. This component also handles the filtering of this data which can be necessary once the leaderboard begins to grow. With this component the user can also make use of a timer which is often added to game scoreboards. With this the user can order the scoreboard in terms of time, score, name or even score per minute. Lastly the component will handle the display of the scoreboard allowing the user to pick from a number of scoreboard templates.
When add to to scoreboard is called an input box will be prompted asking for users name. When the username is entered an object will be added to the leaderboard array with the players name, score and a player id. In the form of {name: “Aaron”, score: 100, playerID: 1} Demo: In this example the user adds the scoreboard manager to their project, creates an instance of the scoreboard manager and adds their score to it.
<script src="ScoreboardManager.js"></script>this.scoreboard = new ScoreboardManager();
this.scoreboard.addToBoard(this.score);
console.log(this.scoreboard.getBoard());
When the scoreboard manager is initialized the user has the option to save the scoreboard to session storage or local storage. If session storage is enabled the data will only be stored for one session. This means when the tab is closed the data will be deleted ( good for quick 1v1 type games). If local storage is enabled the scores will be stored with no expiration date. The data will not be deleted when the browser is closed and all data will be available to retrieve at a later time.
this.scoreboard = new ScoreboardManager();
this.scoreboard.initBoard("Local");
this.scoreboard.addToBoard(this.score);
console.log(this.scoreboard.getBoard());
this.scoreboard = new ScoreboardManager();
this.scoreboard.clearLocalStorage();
this.scoreboard.initBoard("Local");
this.scoreboard.addToBoard(this.score);
console.log(this.scoreboard.getBoard());
The scoreboard can get quite big over time so this will allow the user to sort through the scoreboard and retrieve only the information they want. E.g sort by Player name, score(lowest/ highest), score per minute(lowest or highest) , by time (lowest or highest) , playerID.
this.scoreboard.filterTime(-1);
this.scoreboard.filterTime(1);
this.scoreboard.filterScore(-1);
this.scoreboard.filterScore(1);
this.scoreboard.filterSPM(-1);
this.scoreboard.filterSPM(1);
When add to to scoreboard is called an input box will be prompted asking for users name. When the username is entered it will be added to the scoreboard along with the time from the display timer. Time in seconds (used for sorting in terms of time, the display timer will be displayed in the scoreboard ) along with a score per minute which is calculated and gives the user another interesting statistic and another way to sort the board. Again the manager needs to check if in local or session storage mode. If in session storage this data is simply added to the scores list. If in session storage the data will be added to the scores list and then saved back to local storage by overwriting).
this.scoreboard = new ScoreboardManager();
this.scoreboard.clearLocalStorage();
this.scoreboard.initBoard("Local");
Display the scores to the screen using a table created in css and html that will be scrollable and scalable (done in css)
this.scoreboard.generateTable()