0

抱歉这个愚蠢的问题,我正在尝试编写一个 SwiftUI 游戏,当用户在轮到他们时点击屏幕时显示“X”,如果不是轮到用户则显示“O”。这是我的代码中给我带来问题的部分(我已经声明了我在代码的另一部分中使用的所有变量,我不会在这里发送,因为它非常没用):

ZStack(content: {
                    RoundedRectangle(cornerRadius: 12.0, style: .continuous)
                        .aspectRatio(contentMode: .fit)
                        .foregroundColor(Color(UIColor.systemGroupedBackground))
                        .onTapGesture {
                            if mark == nil {
                                nextPlayerTwoMarkPosition = Int.random(in: 1...10)
                                if whoseTurnIsIt == "user" {
                                    mark = "xmark"
                                    whoseTurnIsIt = "device"
                                } else {
                                    if nextDeviceMarkPosition == 1 {
                                        mark = "circle"
                                        whoseTurnIsIt = "user"
                                    }
                                }
                            }
                        }
                    Image(systemName: mark ?? "")
                })

它似乎只是在玩家点击后才让设备标记方格,即使不是轮到他们。我正在尝试找到一种解决方案,让设备在轮到它时标记一个随机正方形(总共有 9 个)。

4

0 回答 0