summaryrefslogtreecommitdiff
path: root/app/src/main/java/space/jakob/mines/GameView.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/space/jakob/mines/GameView.kt')
-rw-r--r--app/src/main/java/space/jakob/mines/GameView.kt18
1 files changed, 17 insertions, 1 deletions
diff --git a/app/src/main/java/space/jakob/mines/GameView.kt b/app/src/main/java/space/jakob/mines/GameView.kt
index 118cb45..d0a7ae0 100644
--- a/app/src/main/java/space/jakob/mines/GameView.kt
+++ b/app/src/main/java/space/jakob/mines/GameView.kt
@@ -97,6 +97,19 @@ class GameView(context: Context, attrs: AttributeSet) : View(context, attrs) {
}
}
+ /**
+ * Flag and @return the tile at (@param x, @param y).
+ */
+ fun flagAt(x: Int, y: Int): Tile? = grid?.let {
+ val (x, y) = toGridCoordinates(x.toInt(), y.toInt())
+ if (it.valid(x, y)) {
+ it.flag(x, y)
+ return it[x, y]
+ } else {
+ return null
+ }
+ }
+
private fun atlasRect(entry: AtlasEntry): Rect {
val atlasWidth = 3
@@ -111,7 +124,6 @@ class GameView(context: Context, attrs: AttributeSet) : View(context, attrs) {
val xSpacing = (scaledTileWidth * tileSpacing).toInt()
val ySpacing = (scaledTileWidth * tileSpacing).toInt()
- // TODO: Opportunity for more ASCII art explanations :)
val dst = Rect(
x + xSpacing,
y + ySpacing,
@@ -121,6 +133,10 @@ class GameView(context: Context, attrs: AttributeSet) : View(context, attrs) {
if (tile.masked) {
canvas.drawBitmap(atlas, atlasRect(AtlasEntry.MASKED), dst, null)
+
+ if (tile.flagged) {
+ canvas.drawBitmap(atlas, atlasRect(AtlasEntry.FLAG), dst, null)
+ }
} else {
canvas.drawBitmap(atlas, atlasRect(AtlasEntry.UNMASKED), dst, null)