For my console game I created a 'ConsoleGameInstan...
# codereview
t
For my console game I created a 'ConsoleGameInstance' class which basically brings the game to life - you can teleport to biomes, find items in biomes, etc:
Copy code
import mobs.passive.Player

class ConsoleGameInstance(private val player: Player) {
    private val keysAction = mutableMapOf<String, (String) -> Unit>()

    init {
        initMap()
    }
    
    fun initMap() {
        keysAction["walk"] = {
            player.walk(); printSummary(player)
        }
        keysAction["tp"] = {
            println("To where?")
            val num = readLine()?.filter { it.isDigit() }
            num?.toInt()?.let { player.tpTo(it) }
            printSummary(player)
        }
        keysAction["goto"] = {
            println("To which biome?")
            val console = readLine()
            for ((range, biome) in player.currentWorld.biomes) {
                if (biome.biomeName == console) {
                    player.tpTo(range.first + 1)
                    printSummary(player)
                    break
                }
            }
        }
    }

    fun start() {
        while (true) {
            val input = readLine()?.toLowerCase()?.let {
                keysAction.forEach { (str, action) ->
                    if (it == str) action.invoke(str)
                }
            }
        }
    }