我正在尝试制作 TicTacToe 游戏。我正在尝试使用此checkForWinner
函数,但不断收到错误。非常感谢任何帮助。
这是我的代码
class ViewController: UIViewController {
@IBOutlet weak var CurrentLetterLabel: UILabel!
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var label3: UILabel!
@IBOutlet weak var label4: UILabel!
@IBOutlet weak var label5: UILabel!
@IBOutlet weak var label6: UILabel!
@IBOutlet weak var label7: UILabel!
@IBOutlet weak var label8: UILabel!
@IBOutlet weak var label9: UILabel!
@IBOutlet weak var label10: UILabel!
@IBOutlet weak var label11: UILabel!
let letter = "XOXOXOXOXO"
var moveCounter = 0
var currentLetter:Character!
var labelArray = [UILabel]()
override func viewDidLoad() {
super.viewDidLoad()
labelArray.append(label1)
labelArray.append(label2)
labelArray.append(label3)
labelArray.append(label4)
labelArray.append(label5)
labelArray.append(label6)
labelArray.append(label7)
labelArray.append(label8)
labelArray.append(label9)
labelArray.append(label10)
labelArray.append(label11)
getCharacter()
}
func getCharacter(){
let myRange = Range<String.Index>(start: letter.startIndex.advancedBy(moveCounter), end: letter.startIndex.advancedBy(moveCounter + 1))
CurrentLetterLabel.text = letter.substringWithRange(myRange)
currentLetter = Character(letter.substringWithRange(myRange))
}
func clearLabels(Action:UIAlertAction){
label1.text = ""
label2.text = ""
label3.text = ""
label4.text = ""
label5.text = ""
label6.text = ""
label7.text = ""
label9.text = ""
label10.text = ""
label11.text = ""
}
func presentWinningAlert(){
moveCounter = 0
let alert = UIAlertController(title: "", message: "byr", preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: clearLabels)
alert.addAction(okAction)
presentViewController(alert, animated: true, completion: nil)
}
@IBAction func onTapped(sender: UITapGestureRecognizer) {
print("Here")
let selectedPoint = sender.locationInView(self.view)
print(selectedPoint)
for label in labelArray{
if CGRectContainsPoint(label1.frame, selectedPoint){
label1.text = String(currentLetter)
}
if CGRectContainsPoint(label2.frame, selectedPoint){
label2.text = String(currentLetter)
}
if CGRectContainsPoint(label3.frame, selectedPoint){
label3.text = String(currentLetter)
}
if CGRectContainsPoint(label4.frame, selectedPoint){
label4.text = String(currentLetter)
}
if CGRectContainsPoint(label5.frame, selectedPoint){
label5.text = String(currentLetter)
}
if CGRectContainsPoint(label6.frame, selectedPoint){
label6.text = String(currentLetter)
}
if CGRectContainsPoint(label7.frame, selectedPoint){
label7.text = String(currentLetter)
}
if CGRectContainsPoint(label8.frame, selectedPoint){
label8.text = String(currentLetter)
}
if CGRectContainsPoint(label9.frame, selectedPoint){
label9.text = String(currentLetter)
}
if CGRectContainsPoint(label10.frame, selectedPoint){
label10.text = String(currentLetter)
}
}
moveCounter++
if moveCounter == 9{
presentWinningAlert()
}
getCharacter()
}
func checkForWinner(){
if label1.text == label2.text && label2.text == label3.text && label3.text != "" {
presentWinningAlert("\(label3.text!)")
}
else if label4.text == label5.text && label5.text == label6.text && label6.text != "" {
presentWinningAlert("\(label6.text!)")
}
else if label7.text == label8.text && label8.text == label9.text && label9.text != "" {
presentWinningAlert("\(label9.text!)")
}
else if label1.text == label4.text && label4.text == label7.text && label7.text != "" {
presentWinningAlert("\(label7.text!)")
}
else if label2.text == label5.text && label5.text == label8.text && label8.text != "" {
presentWinningAlert("\(label8.text!)")
}
else if label3.text == label6.text && label6.text == label9.text && label9.text != "" {
presentWinningAlert("\(label9.text!)")
}
else if label1.text == label5.text && label5.text == label9.text && label9.text != "" {
presentWinningAlert("\(label9.text!)")
}
else if label3.text == label5.text && label5.text == label7.text && label7.text != "" {
presentWinningAlert("\(label7.text!)")
}
if moveCounter == 9
{
presentWinningAlert("No One")
}
}
}
答案 0 :(得分:3)
您正在使用字符串参数调用该函数,但该函数不接受字符串参数。 电话应该是
/usr/local/bin
不传递任何参数或该函数应修改为
presentWinningAlert()