class ViewController: UIViewController {
@IBOutlet weak var inputField: UITextField!
@IBOutlet weak var output: UITextView!
var guesses : UInt = 0
var number : UInt32 = 0
var gameOver = false
let MAX_GUESSES : UInt = 8
@IBAction func guess(sender: UIButton) {
var possibleGuess : Int? = inputField.text.toInt()
if let guess = possibleGuess {
// possibleGuess exists!
} else {
consoleOut("Please input a valid number!\n")
clearInput()
}
if UInt32(guess) > Int(number) {
consoleOut("\(guess): You guessed too high!\n")
++guesses
} else if UInt32(guess) < number {
consoleOut("\(guess): You guessed too low!\n")
++guesses
} else {
consoleOut("\n\(guess): You win!\n")
consoleOut("Go again? (Y)")
guesses = 0
gameOver = true
}
clearInput()
if (guesses == MAX_GUESSES) {
consoleOut("\nYou lose :(\n")
consoleOut("Go again? (Y)")
guesses = 0
gameOver = true
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
number = generateNewNumber()
consoleOut("Gondolkodom egy számot...\n")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func consoleOut(text : String) {
output.text = output.text + text
}
func generateNewNumber() -> UInt32 {
return arc4random_uniform(100)
}
func clearInput() {
inputField.text = ""
}
}
이것은 내가 사용하는 코드 내가 if UInt32(guess) > Int(number) {
에 오류 메시지가 표시됩니다. 나는 이것을 정말로 통과 할 수 없다.(SWIFT) 오류 : '(UINT32 @lvalue, UINT32)'형식의 인수 목록 '>'호출 할 수는
(swift) Error: can not invoke '>' with an argument list of type '(UInt32, @lvalue UInt32)'
더 많은 코드를 표시 하시겠습니까? 적어도 컴파일하고 실행할 수 있어야합니다. – Kaydell