我有一个名为shuffledDeck的数组,其中包含52个被调整的Int数字我希望单独处理每个玩家
func dealCards1(){
for i in 0...25{
comp1PlayDeck += shuffledDeck[i]
}
}
不太确定我应该返回什么我这样做是为了学习不重要的东西 只是想知道我应该为exmp
的函数声明做些什么func dealCards1(Int: Array) -> Int: Array{}
我不知道如何返回阵列任何帮助将不胜感激谢谢! :d 这是到目前为止的完整代码
import Foundation
let comp1 = 1
let comp2 = 2
var dealDeck = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52]
var shuffledDeck: [Int]
var comp1PlayDeck = [Int]()
var comp2PlayDeck: [Int]
var comp1WinDeck: [Int]
var comp2WinDeck: [Int]
var comp1CurrCard: Int
var comp2CurrCard: Int
//functions
//shuffles cards from dealDeck returns to shuffledDeck
func shuffle<T>(var list: Array<T>) -> Array<T> {
for i in 0..<list.count {
let j = Int(arc4random_uniform(UInt32(list.count - i))) + i
list.insert(list.removeAtIndex(j), atIndex: i)
}
return list
}
//shuffle deck
shuffledDeck = shuffle(dealDeck)
for num in shuffledDeck {
println(num)
}
//deals to player one
func dealCards1() -> [Int] {
for i in 0...25{
comp1PlayDeck += shuffledDeck[i]
}
return comp1PlayDeck
}
//deals to player two
func dealCards2(){
}
comp1PlayDeck = dealCards1()
答案 0 :(得分:2)
您是否在询问如何从函数中返回处理过的comp1PlayDeck?如果是这样,只需让函数返回一个Int数组,并在函数末尾返回comp1PlayDeck。
var comp1PlayDeck = [Int]()
func dealCards1() -> [Int] {
for i in 0...25{
comp1PlayDeck += shuffledDeck[i]
}
return comp1PlayDeck
}