ゲームの作成に問題があります。ハイスコアリストをソートしようとしていますが、それが意図したとおりに機能していません。スコアを保存するときに私はゲームに出ます。ハイスコアのリストを見て、そのスコアがリストのスコアより高いかどうかをチェックし、そうであれば新しいハイスコアをリストに入れ、リスト内の他のスコアを下に移動します。xmlファイルを正しく並べ替えるには?
public void SaveHighScore(int score)
{
// Create the data that needs to be saved
HighScore data = LoadHighScores(HighScoresFilename);
int scoreIndex = 0;
for (int i = 4; i >= 0; i--)
{
if (score >= data.Score[i])
{
scoreIndex = i;
break;
}
}
if (scoreIndex >= 0)
{
int[] tempScore = new int[5];
for (int i = 4; i >= scoreIndex; i--)
{
tempScore[i] = data.Score[i];
}
tempScore[scoreIndex] = score;
for (int i = scoreIndex; i > 0; i--)
{
tempScore[i - 1] = data.Score[i];
}
for(int i = 0; i < data.Score.Length; i++)
data.Score[i] = tempScore[i];
SaveHighScores(data, HighScoresFilename);
}
}
そして、私のクラスには、次のようになります: コードは次のようになりますhttps://github.com/PalmerVincent/Game/projects
問題は、新しいハイスコアを配列に入れている場合はハイスコアリストが正しくソートされないということです。