这是为该类中的当前分数。
private var score: Int = 0
def initialiseTest2(): Game = {
return new Game(List((3,3),(3,4),(3,5),(5,3),(5,4),(5,5)), List((4,4,(x: Int) => x+1), (6,3, if(score == 0){ (x: Int) => x+1 }else { (x: Int) => x+3 })), 3,2)
}
def initialiseTest2
是在对象中的部分,在那里有 if(score == 0)
那部分我需要调用私有的var score,我怎么做,当我只是输入 score时,它给出了一个错误说 not found: value score
创建一个getter函数来返回分数的副本。然后,你可以从测试中访问当前的分数。
object Score {
private var score: Int = 0
def currentScore(): Int = score
}