Professional Documents
Culture Documents
Piatra Hartie Foarfeca (Problema in Kotlin)
Piatra Hartie Foarfeca (Problema in Kotlin)
}
fun getUserChoice(): String {
var options = arrayOf("Rock", "Paper", "Scissors")
var isvalid = false
var userchoise = " "
while(!isvalid) {
print ("Please enter one of the following: ")
for(i in 0 until options.size)
print("${options[i]} ")
print (".")
val userInput = readLine()
if(userInput != null && userInput in options) {
isvalid = true
userchoise = userInput
}
if(!isvalid) print ("Choose something else")
}
return userchoise
}
fun printResult(op: Int,user_choise: String ): String{
var options = arrayOf("Rock", "Paper", "Scissors")
val result: String
val game_op = options[op]
if(user_choise==game_op) result = "Tie!"
else if((user_choise == "Rock" && game_op == "Scissors")||(user_choise ==
"Paper" && game_op == "Rock")||(user_choise == "Scissors" && game_op == "Paper"))
result = "Win!"
else result = "Lose"
return result