Advertisement
loloof64

Simple Jetpack Compose project : game screen

Dec 22nd, 2022
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.42 KB | Gaming | 0 0
  1. package com.loloof64.compose_chess_experiment.ui.screens.game
  2.  
  3. import androidx.compose.foundation.layout.Arrangement
  4. import androidx.compose.foundation.layout.Column
  5. import androidx.compose.foundation.layout.padding
  6. import androidx.compose.material3.*
  7. import androidx.compose.runtime.Composable
  8. import androidx.compose.runtime.collectAsState
  9. import androidx.compose.ui.Alignment
  10. import androidx.compose.ui.Modifier
  11. import androidx.compose.ui.res.stringResource
  12. import androidx.lifecycle.viewmodel.compose.viewModel
  13. import com.loloof64.compose_chess_experiment.R
  14. import com.loloof64.compose_chess_experiment.ui.components.chess_board.ChessBoard
  15.  
  16. @OptIn(ExperimentalMaterial3Api::class)
  17. @Composable
  18. fun GameScreen(
  19.     viewModel: ChessGameViewModel = viewModel()
  20. ) {
  21.     val state = viewModel.uiState.collectAsState()
  22.     Scaffold(
  23.         topBar = {
  24.             TopAppBar(
  25.                 title = { Text(stringResource(id = R.string.game_page)) }
  26.             )
  27.         }
  28.     ) {
  29.         Column(
  30.             modifier = Modifier.padding(it),
  31.             horizontalAlignment = Alignment.CenterHorizontally,
  32.             verticalArrangement = Arrangement.Center
  33.         ) {
  34.             Button(onClick = {
  35.                 viewModel.newGame()
  36.             }) {
  37.                 Text(text = "New game")
  38.             }
  39.             ChessBoard(
  40.                 position = state.value.currentPosition
  41.             )
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement