
你现在的位置 4 83
functions
函数
向
Game.kt
中添加
getUserChoice
函数
下面是更改过的本应用代码,包括完整的getUserChoice
函数。请更新你的
Game.kt
,使其匹配我们的版本(我们更
改的部分以粗体标出):
fun main(args: Array<String>) {
val options = arrayOf("Rock", "Paper", "Scissors")
val gameChoice = getGameChoice(options)
val userChoice = getUserChoice(options)
}
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 of the following:")
for (item in ...