Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift方法那一章的level调整为关卡是否会更好? #1400

Open
WekyJay opened this issue Oct 23, 2024 · 0 comments
Open

Swift方法那一章的level调整为关卡是否会更好? #1400

WekyJay opened this issue Oct 23, 2024 · 0 comments

Comments

@WekyJay
Copy link

WekyJay commented Oct 23, 2024

只是自己本人的一点拙见,仅供参考:
在看这个章节的时候带着“等级”的理解,多少有点问题,例如下面这段代码:

    @discardableResult
    mutating func advance(to level: Int) -> Bool {
        if LevelTracker.isUnlocked(level) {
            currentLevel = level // 等级回调??
            return true
        } else {
            return false
        }
    }

其中的currentLevel = level告诉我们调整当前的等级,如果我尝试使用更低的等级来使用该方法,currentLevel是否会跟着回调,因此百思不得其解。
如果调整为关卡,可以以存档的方式来理解。当玩家解锁的最高的关卡等级highestUnlockedLevel为5,那么advance填入参数6则无法进入第六关,而小于等于5的关卡可以进入,那么则调整当前进入的存档关卡 **currentLevel(当前关卡)**为小于等于5的关卡。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant