我正在 swift 2.0 中初始化一组骰子。我已经声明了一个带有名称(:String),状态列表(:[String])和面(状态数组的索引)(:[Int])的类Die
根据GameplayKit Framework Reference和Erica Sadun 的这篇短文中的建议,我想删除 GKARC4RandomSource 的前 1024 个值以确保“真正的”随机性。
在我的 UIViewController 中,我设置了一个 init? 初始化我的骰子的函数
class IceDiceViewController: UIViewController {
var Dice: [Die]
var source : GKRandomSource
...
required init?(coder aDecoder: NSCoder){
Dice = [Die]()
source = GKARC4RandomSource()
// call the init function to instantiate all variables
super.init(coder: aDecoder)
// now initialize two dice with states ["red","yellow","blue","black","green","multiple"]
Dice.append(Die(name:"iceDie", states: ["red","yellow","blue","black","green","multiple"]))
Dice.append(Die(name:"iceDie", states: ["big","med","small","bigmed","bigsmall","medsmall"]))
// and drop the first values of the ARC4 random source to ensure "true" randomness
source.dropValuesWithCount(1024)
...
}
这甚至不会编译:最后一行返回错误:
Value of type GKRandomSource has no member dropValuesWithCount
我的代码在没有这一行的情况下工作,但我不确定我在这里做错了什么,除了上面引用的链接之外,我几乎找不到在网络上使用 Gameplay Kit 实现 Dice 的任何参考。