-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 14 additions & 32 deletions
46
core/src/commonMain/kotlin/de/haukesomm/sokoban/core/CharacterMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,25 @@ | ||
package de.haukesomm.sokoban.core | ||
|
||
import de.haukesomm.sokoban.core.CharacterMap.Companion.default | ||
import kotlin.jvm.JvmInline | ||
import kotlin.jvm.JvmStatic | ||
|
||
/** | ||
* This class represents a character map. | ||
* Convenience Type alias for Character maps | ||
* | ||
* A character map is a map that maps [Char]s to [TileProperties], which in turn contain the [TileType] and the | ||
* [EntityType] of the resulting [TileType] on the game board. | ||
* | ||
* All [CharacterMap]s should orient themselves on the default character map, which is defined in the companion object's | ||
* [default] property. | ||
* All [CharacterMap]s should orient themselves on the default character map, which is defined in the globally | ||
* available [DefaultCharacterMap]. | ||
*/ | ||
class CharacterMap(map: BiMap<Char, TileProperties>) : BiMap<Char, TileProperties> by map { | ||
|
||
companion object { | ||
|
||
/** | ||
* Default character map based on the original Sokoban game. | ||
*/ | ||
val default: CharacterMap = characterMapOf( | ||
'_' to TileProperties(TileType.Empty), | ||
'.' to TileProperties(TileType.Target), | ||
'#' to TileProperties(TileType.Wall), | ||
'$' to TileProperties(TileType.Empty, EntityType.Box), | ||
'@' to TileProperties(TileType.Empty, EntityType.Player), | ||
'*' to TileProperties(TileType.Target, EntityType.Box), | ||
'+' to TileProperties(TileType.Target, EntityType.Player) | ||
) | ||
} | ||
} | ||
typealias CharacterMap = BiMap<Char, TileProperties> | ||
|
||
/** | ||
* Creates a [CharacterMap] from the given [entries]. | ||
* Default [CharacterMap] as used in the original Sokoban game. | ||
*/ | ||
fun characterMapOf(vararg entries: Pair<Char, TileProperties>): CharacterMap = | ||
CharacterMap( | ||
BiMapImpl( | ||
mapOf(*entries) | ||
) | ||
) | ||
val DefaultCharacterMap: CharacterMap = biMapOf( | ||
'_' to TileProperties(TileType.Empty), | ||
'.' to TileProperties(TileType.Target), | ||
'#' to TileProperties(TileType.Wall), | ||
'$' to TileProperties(TileType.Empty, EntityType.Box), | ||
'@' to TileProperties(TileType.Empty, EntityType.Player), | ||
'*' to TileProperties(TileType.Target, EntityType.Box), | ||
'+' to TileProperties(TileType.Target, EntityType.Player) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.