Берем меня, который в кт никогда не заглядывал. Максимум ебучий жс и луа тыкаю.
ПОЧЕМУ
МНЕ
ВСЁ
ПОНЯТНО
В
КУСКАХ
КОДА
ИЗ
КТ
ХОТЯ
Я
ЕГО
НЕ
ИЗУЧАЛ
import java.awt.Choice
fun main() {
val options = arrayOf("Rock", "Paper", "Scissors")
val gameChoice = getGameChoice(options)
var 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 = ""
while (!isValidChoice) {
println("Enter one of following - ")
for (item in optionsParam) print("$item, ")
println(".")
val userInput = readLine()
if (userInput != null && userInput in optionsParam) {
isValidChoice = true
userChoice = userInput
}
// если недопустимо, то сообщить
if (!isValidChoice) println("You must enter a valid choice")
}
return userChoice
}
fun printResult(userChoice: String, gameChoice: String) {
val result: String = ""
if (userChoice == gameChoice) result == "Tie!"
else if ((userChoice == "Rock" && gameChoice == "Scissors") ||
(userChoice == "Paper" && gameChoice == "Rock") ||
(userChoice == "Scissors" && gameChoice == "Paper")
) result == "You win!"
else result == "You lose!"
println("You chose $userChoice. I chose $gameChoice. $result.")
}