あなたはSQLを知らないので(とにかく多くのデータを保持しているわけではないので)、おそらくJSONファイルで処理できます。この回答は、サーバーを持っていることを前提としています(Node.jsを使用する予定の場合は必要です)。また、私はスコアと名前でold-school high score tableを作りたがっています。
これは一般的なガイダンスになります。あなたが選んだ言語で説明していることをする方法を見つける必要があります。
次のようになりますあなたが(例えばscores.json)ファイルを持っていますサーバーで
、:
{
"data": [
{
"name": "Destroyer",
"score": 23
},
{
"name": "yo momma",
"score": 5
},
{
"name": "Joe",
"score": 1
},
// And so on...
]
}
また、サーバーには、特定のリスニングの何かを持っている必要がありますport(Node.js、PHP、Ruby、Pythonなど)を使用してリクエストを行います。何このスクリプトは行いますが(JavaScriptで)です:あなたは新しいスコアを保存したり、高を取得したいときにクライアント側のJavaScriptファイル上
handleRequest(request) {
// Fetch your file and populate the array
var scoresTable = ...
// On request, decide which type of request it is
if (request.type === "getHighScoresTable") {
// If it wants the scores, return the json as a string
return scoresJson;
} else if (request.type === "submitScore"
&& request.score > scoresTable[scoresTable.length - 1].score) {
// Otherwise, check if the submitted score makes it into the table.
// If it does, search its position and replace.
scoresTable.forEach(function(value, index) {
if (value.score < request.score) {
scoresTable.splice(index, 0, {"name": request.name, "score": request.score});
}
});
// Trim the last element and return
scoresTable = scoresTable.slice(0, -1)
// You probably want to update your file here
}
}
今
、、あなたのサーバーにAJAX requestをしなければなりませんスコア表。 jQueryはnicer syntaxを提供しています。
$.ajax({
url: 'urlToYourServer',
type: 'GET',
data: '{
"type": "submitScore",
"name": "I beat Joe",
"score": 2
}'
});
送信する前にスコアがクライアントで十分に高いかどうかを確認することをお勧めします。また、ユーザーはクライアントからのリクエストを騙すことができるため、セキュリティ対策を考慮する必要があります。