我有一个拥有9个不同等级的游戏,这些游戏对于收集的硬币和收集的特殊硬币都有自己的高分值。我想创建一个“银行”,可以存储这些值并添加它们以便能够“购买”某些级别的解锁。我不确定我是否以不允许这样做的方式实现了我的评分系统,或者我是否遗漏了一些简单的东西。非常感谢任何见解!
var s3 = new AWS.S3();
var params = {
Body: buffer,
Bucket: <bucket>,
Key: <key>,
ContentType: 'image/jpeg'
};
s3.putObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
console.log(data);
}
})
在完成关卡后,在GameScene中调用它。
import Foundation
struct ScoreManager {
static func getCurrentScore(for levelKey: String) -> [String:Int] {
if let existingData = UserDefaults.standard.dictionary(forKey: levelKey) as? [String:Int] {
return existingData
} else {
return [GameConstants.StringConstants.scoreScoreKey:0, GameConstants.StringConstants.scoreStarsKey:0, GameConstants.StringConstants.scoreCoinsKey:0]
}
}
static func updateScore(for levelKey: String, and score: [String:Int]) {
UserDefaults.standard.set(score, forKey: levelKey)
UserDefaults.standard.synchronize()
}
static func compare(scores: [[String:Int]], in levelKey: String) {
var newHighscore = false
let currentScore = getCurrentScore(for: levelKey)
var maxScore = currentScore[GameConstants.StringConstants.scoreScoreKey]!
var maxStars = currentScore[GameConstants.StringConstants.scoreStarsKey]!
var maxCoins = currentScore[GameConstants.StringConstants.scoreCoinsKey]!
for score in scores {
if score[GameConstants.StringConstants.scoreScoreKey]! > maxScore {
maxScore = score[GameConstants.StringConstants.scoreScoreKey]!
newHighscore = true
}
if score[GameConstants.StringConstants.scoreStarsKey]! > maxStars {
maxStars = score[GameConstants.StringConstants.scoreStarsKey]!
newHighscore = true
}
if score[GameConstants.StringConstants.scoreCoinsKey]! > maxCoins {
maxCoins = score[GameConstants.StringConstants.scoreCoinsKey]!
newHighscore = true
}
}
if newHighscore {
let newScore = [GameConstants.StringConstants.scoreScoreKey: maxScore, GameConstants.StringConstants.scoreStarsKey: maxStars, GameConstants.StringConstants.scoreCoinsKey: maxCoins]
updateScore(for: levelKey, and: newScore)
}
}
忽略星星,我用它们来显示你在关卡上的表现。如果需要,我很乐意提供更多代码片段。再次感谢大家!