Kotlin 53
Now I’ll try adding something to my actions collection, first in regular code, then tomorrow I’ll try to add the capability to the DSL.
I remove the definition of “shout” from the Action initial setup, and then add this to the initial creation of a world via the world command:
fun world(details: World.()->Unit): World{
val world = World()
world.addShout() // <---
world.details()
return world
}
And in World and Actions:
// class World ...
fun addShout() {
lexicon.actions.put("shout" to { imp: Imperative -> imp.say(
"Your shout of ${imp.noun.uppercase()} echoes through the area.")},)
}
// class Actions
fun put(action: Pair<String, (Imperative) -> Unit>) {
verbMap.put(action.first, action.second)
}
This is sufficient to make the tests pass and the shout command work in the game.
That tells us that we can surely implement a new DSL “verb”, probably action
that will allow the game designer to add an action to the table. We may find that we need the ability to add synonyms and verbs as well, but if we can do actions, we can surely do the others.
I’ll try that tomorrow. This’ll do for today! See you next time!