我坚持重设此功能

时间:2019-10-16 17:54:24

标签: swift

我具有以下功能。我被困住了是因为我的功能没有重置,所以我的纸牌从未重置,游戏也一直在不断增加分数。我对Swift的了解还不是很熟练,因此不胜感激。

func chooseCard(at index: Int) {
    assert(Round.Dealt.indices.contains(index), "SetRound.chooseCard(at: \(index)): chosen index not in the dealt cards array")
    Round.Dealt[index].selected = true

    var setItemCount: Int = 0
    var First: Card = Card()
    var Second: Card = Card()
    var Third: Card = Card()

    for Candidate in Round.Dealt {
        if Candidate.selected {                 // If the candidate is part of a match
            setItemCount += 1                   // Count cards found
            if (setItemCount == 1) {            // First one found?
                First = Candidate           // Capture it
            }
            if (setItemCount == 2) {             // Second one found?
                Second = Candidate           // Capture it
            }
            if (setItemCount == 3) {             // Third one found?
                Third = Candidate            // Capture it
            }
           // assert(setItemCount < 4, "SetRound.chooseCard(at: \(index)): caused more then three cards to be selected")
        }
    }
    if (setItemCount == 3) {                        // If picked three, see if a match
        if (Round.SetMatch(FirstCard: &First, SecondCard: &Second, ThirdCard: &Third)) {
           // assert(Round.RemoveMatchSet(),"SetRound.chooseCard could not remove a matched set")
            //assert(Round.Deal(NumberOfCards: setItemCount),"Set.chooseCard ran out of cards")

        } else { // Not a match, deselect all of them
            First.selected = false
            Second.selected = false
            Third.selected = false
        }
        setItemCount = 0
    }
   // reset.chooseCard
}

0 个答案:

没有答案