-
-
Save mukeshsolanki/ecbf1ee38543602ef0a6e276da8b00b3 to your computer and use it in GitHub Desktop.
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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
SnakeTheme { | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colorScheme.background | |
) { SnakeGame() } | |
} | |
} | |
} | |
@Composable | |
override fun SnakeGame() { | |
scope = rememberCoroutineScope() | |
val state = gameEngine.state.collectAsState(initial = null) | |
Column { | |
state.value?.let { Board(it) } | |
Controller { | |
when (it) { | |
SnakeDirection.Up -> gameEngine.move = Pair(0, -1) | |
SnakeDirection.Left -> gameEngine.move = Pair(-1, 0) | |
SnakeDirection.Right -> gameEngine.move = Pair(1, 0) | |
SnakeDirection.Down -> gameEngine.move = Pair(0, 1) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment