mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
A little cleaner implementation
This commit is contained in:
@@ -13,23 +13,25 @@
|
|||||||
fun main() {
|
fun main() {
|
||||||
println(introText)
|
println(introText)
|
||||||
synonyms.forEach {
|
synonyms.forEach {
|
||||||
// Inside with, "this" is the current synonym
|
it.testUser()
|
||||||
with(it) {
|
|
||||||
do {
|
|
||||||
val answer = ask(" WHAT IS A SYNONYM OF $word ? ")
|
|
||||||
when {
|
|
||||||
answer == "HELP" ->
|
|
||||||
println("""**** A SYNONYM OF $word IS ${synonyms.random()}.""")
|
|
||||||
synonyms.contains(answer) ->
|
|
||||||
println(RANDOM_ANSWERS.random())
|
|
||||||
else ->
|
|
||||||
println("TRY AGAIN.")
|
|
||||||
}
|
|
||||||
} while (!synonyms.contains(answer))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
println("SYNONYM DRILL COMPLETED.")
|
println("SYNONYM DRILL COMPLETED.")
|
||||||
}
|
}
|
||||||
|
// We could put this inside of SynonymList, but this keeps the core implementation
|
||||||
|
// right here at the top
|
||||||
|
private fun SynonymList.testUser() {
|
||||||
|
do {
|
||||||
|
val answer = ask(" WHAT IS A SYNONYM OF $word ? ")
|
||||||
|
when {
|
||||||
|
answer == "HELP" ->
|
||||||
|
println("""**** A SYNONYM OF $word IS ${synonyms.random()}.""")
|
||||||
|
synonyms.contains(answer) ->
|
||||||
|
println(RANDOM_ANSWERS.random())
|
||||||
|
else ->
|
||||||
|
println("TRY AGAIN.")
|
||||||
|
}
|
||||||
|
} while (!synonyms.contains(answer))
|
||||||
|
}
|
||||||
|
|
||||||
val introText = """
|
val introText = """
|
||||||
${tab(33)}SYNONYM
|
${tab(33)}SYNONYM
|
||||||
|
|||||||
Reference in New Issue
Block a user