0
因此,我有一個3x3的文本字段網格,旨在顯示3個最佳分數以及自從遊戲啓動以來獲得的單圈時間和carHealths,並且如果獲得更好的分數,現在的排行榜中的成績就是新的成績,圈速和carHealth取代了原來的成績,並將其下的所有成績都降低了一分。存儲排名前3的分數
問題是它只是取代最高分,即使它是一個更糟糕的分數,如果只剩下其他2個點不變。我是否錯過了一些非常明顯的東西,或者我是否會發現這一切都是錯的?
function leaderBoard(): void
{
if (score < scoreArray[2])
{
return
}
if (score > scoreArray[0])
{
scoreArray.unshift(score);
lapTimerArray.unshift(lapTimer.currentCount);
carHealthArray.unshift(carHealth);
scoreArray.pop()
lapTimerArray.pop()
carHealthArray.pop()
}
else if (score > scoreArray[1])
{
scoreArray.splice(1, 0, score);
lapTimerArray.splice(1, 0, lapTimer.currentCount);
carHealthArray.splice(1, 0, carHealth);
scoreArray.pop();
lapTimerArray.pop();
carHealthArray.pop();
}
else if (score > scoreArray[2])
{
scoreArray.pop();
lapTimerArray.pop();
carHealthArray.pop();
scoreArray.append(score);
lapTimerArray.append(lapTimer.currentCount);
carHealthArray.append(carHealth);
}
}
如果我正確理解你的問題,也許問題從你的使用率莖'else if',而不是單獨做'if'。目前,如果您的'scorearray'中的第一項小於'score',則您執行代碼。其他條款只有在條件失敗時才能被觸發,所以只有在score scoreArray [1]。 –
DodgerThud
所以我試圖讓他們所有如果陳述,但隨後所有三行顯示相同的分數,並在同一時間被取代。我也嘗試在每個if語句的底部添加回車,但是隻有第一個是替換,其他的不管分數如何都不會改變。 – Jester