Kotlin 89 - More on the D and R
Just a bit more play with the Direction and Room enumerations and related code. Should I work out why ‘e’ doesn’t work, or just make it impossible?
I think we will see about making it impossible, by changing which of these calls which:
fun go(direction: D, roomName: R, allowed: (World)->Boolean = { _:World -> true}){
go(direction.name, roomName, allowed)
}
fun go(direction: String, roomName: R, allowed: (World)->Boolean = { _:World -> true}){
go(direction, roomName.name, allowed)
}
fun go(direction: String, roomName: String, allowed: (World)->Boolean = { _:World -> true}) {
moves += D.valueOf(direction) to Pair(roomName, allowed)
}
Let’s make the top one do the right thing (so far):
fun go(direction: D, roomName: R, allowed: (World)->Boolean = { _:World -> true}){
moves += direction to Pair(roomName.name, allowed)
}
That’s the preferred one, for now. We’ll want one that expects a room, not a room name, soon.
I’ll bite the bullet and convert all the others. The middle one is no longer used. Safe delete it.
There are 19 uses of the bottom one. I think this calls for a multi-cursor edit. Yes, nearly good. Mangled a few of them, readily fixed.
Commit: All go commands use D,R format. Other go functions removed.
I notice that I’ve failed to push some versions. Sorry about that, but I suppose if anyone were looking at them, they’d have let me know.
So. A small but useful improvement, I think. Right now, there are more room names in the enum than we need in the game, but that is nearly harmless, I think. It might be best to rename test rooms in some standard way, however.
One drawback to the enum trick … unless we do something with an interface over an enum, if that’s even possible … is that tests and game code share the same namespace.
For now, we can live with that. We’re just learning here. No one has stepped up to help me actually deploy a game.
See you next time!