存储前3个分数

时间:2017-08-31 05:59:31

标签: actionscript-3

因此,我有一个3x3网格的文本字段,旨在显示3个最佳分数以及自游戏启动以来已经实现的单圈时间和carHealths,如果获得更好的分数,那么其中一个当前的排行榜是新的得分,单圈时间和carHealth取代旧的,并将其下方的所有内容向下移动一个。

问题是,如果只是让其他2个点不受影响,它只会取代最高分。我只是错过了一些非常明显的事情,还是我认为这一切都错了?

from scipy import misc
arr = misc.imread(im) # 640x480x3 array
arr[20, 30] # all 3 vectors of a pixel
arr[20, 30, 1] # only green value for a pixel

1 个答案:

答案 0 :(得分:1)

哦天啊:)如果你突然想要显示前十名的分数,你会怎么做?

这种方法怎么样:将汽车的所有信息存储在一个对象(或类)中,然后按分数对数组进行排序。这样你就不必混淆三个独立的阵列了(也许你以后想要为你的汽车添加更多属性):

var car1:Object = {name:"Car 1", score:100, lapTimer:100, carhealth:50};
var car2:Object = {name:"Car 2", score:1050, lapTimer:100, carhealth:50};
var car3:Object = {name:"Car 3", score:700, lapTimer:100, carhealth:50};

var myCars:Array = [car1, car2, car3];

// Then you probably want to pass your car objects to your cars and modify them from there: car3.score = 400 etc. The car objects can be created dynamically based on how many cars you want

// In the end
function displayScores():void
{
    myCars.sortOn("score"); // sort cars on score property

    // display top 3
    for(i:int = 0, i < 3; i++)
    {
        trace("Place " + (i+1) + " - " + myCars[i].name + ", Score " + myCars[i].score);
    }
}