Render puzzle (WIP)
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
package domain
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import kotlin.math.abs
|
||||
|
||||
sealed class Clue {
|
||||
abstract fun isRuleViolated(grid: Grid): Boolean
|
||||
var isActive: Boolean by mutableStateOf(true)
|
||||
}
|
||||
|
||||
sealed class HorizontalClue : Clue()
|
||||
|
||||
class NeighbourClue<C:ItemClass<C>>(val a: Item<C>, val b: Item<C>) : HorizontalClue() {
|
||||
class NeighbourClue<C : ItemClass<C>>(val a: Item<C>, val b: Item<C>) : HorizontalClue() {
|
||||
private val aType = a.itemType
|
||||
private val bType = b.itemType
|
||||
|
||||
@@ -22,7 +26,7 @@ class NeighbourClue<C:ItemClass<C>>(val a: Item<C>, val b: Item<C>) : Horizontal
|
||||
}
|
||||
}
|
||||
|
||||
class OrderClue<C:ItemClass<C>>(val left: Item<C>, val right: Item<C>) : HorizontalClue() {
|
||||
class OrderClue<C : ItemClass<C>>(val left: Item<C>, val right: Item<C>) : HorizontalClue() {
|
||||
private val leftType = left.itemType
|
||||
private val rightType = right.itemType
|
||||
|
||||
@@ -36,7 +40,8 @@ class OrderClue<C:ItemClass<C>>(val left: Item<C>, val right: Item<C>) : Horizon
|
||||
}
|
||||
}
|
||||
|
||||
class TripletClue<C:ItemClass<C>>(val a: Item<C>, val b: Item<C>, val c: Item<C>) : HorizontalClue() {
|
||||
class TripletClue<C : ItemClass<C>>(val a: Item<C>, val b: Item<C>, val c: Item<C>) :
|
||||
HorizontalClue() {
|
||||
private val aType = a.itemType
|
||||
private val bType = b.itemType
|
||||
private val cType = c.itemType
|
||||
@@ -67,7 +72,7 @@ class TripletClue<C:ItemClass<C>>(val a: Item<C>, val b: Item<C>, val c: Item<C>
|
||||
}
|
||||
}
|
||||
|
||||
class SameRowClue<C:ItemClass<C>>(val a: Item<C>, val b: Item<C>) : Clue() {
|
||||
class SameRowClue<C : ItemClass<C>>(val a: Item<C>, val b: Item<C>) : Clue() {
|
||||
private val aType = a.itemType
|
||||
private val bType = b.itemType
|
||||
|
||||
@@ -81,7 +86,7 @@ class SameRowClue<C:ItemClass<C>>(val a: Item<C>, val b: Item<C>) : Clue() {
|
||||
}
|
||||
}
|
||||
|
||||
class PositionClue<C:ItemClass<C>>(val item: Item<C>, val index: Int) : Clue() {
|
||||
class PositionClue<C : ItemClass<C>>(val item: Item<C>, val index: Int) : Clue() {
|
||||
private val aType = item.itemType
|
||||
|
||||
override fun isRuleViolated(grid: Grid): Boolean {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package domain
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.toMutableStateList
|
||||
|
||||
class GameRow<C : ItemClass<C>>(
|
||||
val category: ItemClassCompanion<C>,
|
||||
val options: List<Item<C>>,
|
||||
@@ -10,12 +15,12 @@ class Grid(
|
||||
val rows: List<GameRow<ItemClass<*>>>
|
||||
) : List<GameRow<ItemClass<*>>> by rows {
|
||||
|
||||
fun <C: ItemClass<C>> indexOf(element: C): Int {
|
||||
fun <C : ItemClass<C>> indexOf(element: C): Int {
|
||||
return this[element.companion]
|
||||
.indexOfFirst { it.selection?.itemType == element }
|
||||
}
|
||||
|
||||
operator fun <C: ItemClass<C>> get(itemType: ItemClassCompanion<C>): GameRow<C> {
|
||||
operator fun <C : ItemClass<C>> get(itemType: ItemClassCompanion<C>): GameRow<C> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return rows.first { it.category == itemType } as GameRow<C>
|
||||
}
|
||||
@@ -33,10 +38,13 @@ fun List<List<Item<ItemClass<*>>>>.toGrid() = Grid(
|
||||
)
|
||||
|
||||
class GameCell<C : ItemClass<C>>(
|
||||
var selection: Item<C>?,
|
||||
selection: Item<C>?,
|
||||
val solution: Item<C>,
|
||||
val options: MutableList<Item<C>>
|
||||
)
|
||||
options: List<Item<C>>
|
||||
) {
|
||||
val options = options.toMutableStateList()
|
||||
var selection by mutableStateOf(selection)
|
||||
}
|
||||
|
||||
class Item<C : ItemClass<C>>(
|
||||
val itemType: C,
|
||||
|
||||
@@ -89,7 +89,7 @@ enum class Fruit(symbol: String) : ItemClass<Fruit> {
|
||||
PEAR("🍐"),
|
||||
MANGO("🥭");
|
||||
|
||||
override val symbols: Array<String> = idic(symbol)
|
||||
override val symbols: Array<String> = arrayOf(symbol)
|
||||
|
||||
override val companion
|
||||
get() = Fruit
|
||||
@@ -110,7 +110,7 @@ enum class Dessert(symbol: String) : ItemClass<Dessert> {
|
||||
LOLLIPOP("🍭"),
|
||||
CUSTARD("🍮");
|
||||
|
||||
override val symbols: Array<String> = idic(symbol)
|
||||
override val symbols: Array<String> = arrayOf(symbol)
|
||||
|
||||
override val companion
|
||||
get() = Dessert
|
||||
@@ -129,7 +129,7 @@ enum class Transportation(symbol: String) : ItemClass<Transportation> {
|
||||
TRAM_CAR("🚋"),
|
||||
BUS("🚌");
|
||||
|
||||
override val symbols: Array<String> = idic(symbol)
|
||||
override val symbols: Array<String> = arrayOf(symbol)
|
||||
|
||||
override val companion
|
||||
get() = Transportation
|
||||
|
||||
Reference in New Issue
Block a user