You are on page 1of 1

fun main(){

val game_op = getGameChoice()


val user_choise = getUserChoice()
print (printResult(game_op, user_choise))
}
fun getGameChoice() : Int {
var options = arrayOf("Rock", "Paper", "Scissors")
var rand_num = (Math.random()*options.size).toInt()
return rand_num

}
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

You might also like