English 中文(简体)
在杰特包罗丝网中,简单三到三网
原标题:Simple three by three grid in Jetpack Compose
  • 时间:2023-12-09 09:16:23
  •  标签:
  • kotlin

Trying to make a simple tic tac toe board in Jetpack Compose:

enum class SquareStateValues {
  None,
  Cross,
  Nought
}

data class SquareState(val value: SquareStateValues = SquareStateValues.None)

var gameState =
    mutableMapOf<Number, Triple<SquareState, SquareState, SquareState>>(
        1 to Triple(first = SquareState(), second = SquareState(), third = SquareState()),
        2 to Triple(first = SquareState(), second = SquareState(), third = SquareState()),
        3 to Triple(first = SquareState(), second = SquareState(), third = SquareState()))

@Composable
fun GameBoard() {
  Surface(modifier = Modifier.fillMaxSize()) {
    gameState.forEach {
      var col = it.key
      Row {
        it.value.toList().forEachIndexed { i, item ->
          Column {
            Button(
                onClick = {},
                modifier =
                    Modifier.align(Alignment.CenterHorizontally)
                        .padding(8.dp)
                        .background(Color.Red)) {
                  Text("$col:$i")
                }
          }
        }
      }
    }
  }
}

但在预审中,我只看到最后一行。

“entergraph

问题回答

You can wrap your row in LazyColumn Like the below code. Try it out. It will work.

LazyColumn {
       items(gameState.value){item ->
           Row {
               item.toList().forEachIndexed { i, item ->
                   Column {
                       Button(
                           onClick = {},
                           modifier =
                           Modifier.align(Alignment.CenterHorizontally)
                               .padding(8.dp)
                               .background(Color.Red)
                       ) {
                           Text("$col:$i")
                       }
                   }
               }
           }
       }
   }




相关问题
Exposed runs query on all HikariCP open connections

I m running a Ktor server with a PostgreSQL database and just set up the JetBrains Exposed ORM framework with HikariCP for connection pooling (per the recommendation in the Ktor documentation). My ...

SQLite Kotlin issue - no database

I am trying to create boardgamegeek APIs based app in AndroidStudio, however from unknown reason I m getting my database created with no columns. Here s Logical log: (1) no such table: games in "...

Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

热门标签