
你现在的位置 4 87
functions
函数
向
Game.kt
中添加
printResult
函数
我们需要向
Game.kt
中添加printResult函数,并且在main函数中调
用它。请按照下面的代码更新你的版本(更新的代码以粗体表示):
fun main(args: Array<String>) {
val options = arrayOf("Rock", "Paper", "Scissors")
val gameChoice = getGameChoice(options)
val userChoice = getUserChoice(options)
printResult(userChoice, gameChoice)
}
fun getGameChoice(optionsParam: Array<String>) =
optionsParam[(Math.random() * optionsParam.size).toInt()]
fun getUserChoice(optionsParam: Array<String>): String {
var isValidChoice = false
var userChoice = ""
//Loop until the user enters a valid choice
while (!isValidChoice) {
//Ask the user for their choice
print("Please enter one ...