Jetris is a classic Tetris game clone built for Android using modern Android development tools and practices. This project showcases the use of Jetpack Compose for the UI, Kotlin for the programming language, and follows MVVM architecture principles.
- Classic Tetris Gameplay: Move, rotate, and drop falling tetrominoes to clear lines.
- Responsive UI: Game interface adapts to different screen sizes.
- Score Keeping: Track your score as you clear lines.
- Line Count: See how many lines you've successfully cleared.
- Next Piece Preview: Plan your moves by seeing the upcoming tetromino.
- Game Over Detection: The game ends when pieces stack to the top.
- Restart Functionality: Easily start a new game.
- (Planned/Possible Features - Add or remove as needed)
- Level progression with increasing speed.
- Sound effects.
- Persistent high scores.
- Piece hold functionality.
- Ghost piece.
- UI: Jetpack Compose - Android's modern toolkit for building native UI.
- Language: Kotlin - First-party support, concise, and expressive.
- Architecture: MVVM (Model-View-ViewModel)
- ViewModel:
GameViewModelmanages the game state, logic, and event handling using Kotlin Coroutines and StateFlow. - View: Composable functions observe
StateFlowfrom the ViewModel to reactively update the UI. - Model: Data classes representing game state (e.g.,
GameState,GamePiece,BlockColor), game grid, and piece shapes.
- ViewModel:
- Asynchronous Programming: Kotlin Coroutines for managing the game loop and background tasks.
- State Management: StateFlow for observable, lifecycle-aware state.
- Dependency Injection :
- Build System: Gradle
- Game Grid: 2D array representing the playfield.
- Tetrominoes: Standard Tetris pieces, each defined as a 2D array of
BlockColor. - Piece Movement: Left, right, and downward (soft drop).
- Piece Rotation: Clockwise rotation of pieces.
- Collision Detection: Checks for collisions with grid boundaries and other locked pieces.
- Line Clearing: Detects and clears completed horizontal lines, shifting blocks above them down.
- Spawning: New pieces spawn at the top of the grid.
- Game Loop: Managed by Kotlin Coroutines in the
GameViewModelto control game ticks and piece descent. - Random Piece Generation: Uses
BlockColor.randomPlayable()to select the next piece.
- Clone the repository:
- Open in Android Studio:
- Open Android Studio (Recommended: Latest stable version - e.g., Hedgehog, Iguana).
- Select "Open an Existing Project".
- Navigate to the cloned
Jetrisdirectory and select it.
- Build the project:
- Android Studio should automatically sync and build the project using Gradle.
- Run the app:
- Select an emulator or connect an Android device.
- Click the "Run" button in Android Studio.
Prerequisites:
- Android Studio (latest stable version recommended - e.g., Iguana | 2023.2.1 or newer)
- Android SDK
- Min SDK 28 (Android 9)
Font: Planet Benson - Typodermic Fonts
This project is licensed under the MIT License - see the LICENSE file for details.
Donald McCaskey - forteanjo@sky.com
