As the player moves they can collect bounties. I am trying to use the below functions to collect the bounties and also check for bounties in a rectangle between the current position and the save position (if the player has covered 9 spaces in this rectangle then all of the bounties in the rectangle are collected and added to the score.
def checkBounty() {
if(bounties (playerX)(playerY) != null) {
val bounty: Int => Int = bounties(playerX)(playerY)
score += bounty(score)
bounties(playerX)(playerY) == null
}
}
The checkBounty() function is supposed to check if the current position is a bounty (a bounty exists if the cell is not
set to null). If a bounty does exist, it increases the score, and then erases the bounty (sets it back to null).
def checkBounties() {
if ((((playerX - saveX) + 1).abs * ((playerY - saveY) + 1).abs) >= 9) {
for (x <- saveX to playerX; y <- saveY to playerY) {
checkBounty();
}
saveX = -1
saveY = -1
}
}
The checkBounties () function checks if the rectangle defined by the current position and saved position covers nine or more positions. If yes, it collects bounties in it, increases the
score, and erases the bounties.
However, when called they don't seem to be working correctly.
I don't think checkBounties() correctly checks the cells which I iterate through using the loop, however I'm not quite sure how to fix this. Any help would be appreciated.
EDIT - My issue is that the tests expect a checkBounty() with no parameters and using playerX and playerY as the coorindates I sm checking. I need to find a way to leave checkBounty() as it is and be able to call something similar, but with parameters for x and y, from checkBounties().
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…