https://github.com/joreilly/WordMasterKMP
  
  
    Kotlin Multiplatform sample with SwiftUI and Compose (Desktop and Android) clients. Heavily inspired by Wordle game. 
    https://github.com/joreilly/WordMasterKMP
  
android compose compose-desktop ios jetpac jetpack-compose kotlin kotlin-multiplatform kotlin-native swift swiftui
        Last synced: 6 months ago 
        JSON representation
    
Kotlin Multiplatform sample with SwiftUI and Compose (Desktop and Android) clients. Heavily inspired by Wordle game.
- Host: GitHub
 - URL: https://github.com/joreilly/WordMasterKMP
 - Owner: joreilly
 - License: apache-2.0
 - Created: 2022-01-08T19:31:54.000Z (almost 4 years ago)
 - Default Branch: main
 - Last Pushed: 2024-09-22T17:00:40.000Z (about 1 year ago)
 - Last Synced: 2025-04-19T22:20:40.888Z (7 months ago)
 - Topics: android, compose, compose-desktop, ios, jetpac, jetpack-compose, kotlin, kotlin-multiplatform, kotlin-native, swift, swiftui
 - Language: Kotlin
 - Homepage:
 - Size: 326 KB
 - Stars: 66
 - Watchers: 3
 - Forks: 9
 - Open Issues: 1
 - 
            Metadata Files:
            
- Readme: README.md
 - License: LICENSE
 
 
Awesome Lists containing this project
- fucking-open-source-ios-apps - WordMasterKMP - solver (Misc / SwiftUI)
 
README
          # WordMasterKMP

Kotlin Multiplatform sample heavily inspired by [Wordle](https://www.powerlanguage.co.uk/wordle/) game and also [Word Master](https://github.com/octokatherine/word-master) and [wordle-solver](https://github.com/dlew/wordle-solver) samples.  The main game logic/state is included in shared KMP code with basic UI then in following clients
- iOS (SwiftUI)
- Android (Jetpack Compose)
- Desktop (Compose for Desktop)
### Shared KMP game logic/state
The shared `WordMasterService` class includes following `StateFlow`s representing the current set of guesses and updated status info for each letter.
```
val boardGuesses = MutableStateFlow>>(arrayListOf())
val boardStatus = MutableStateFlow>>(arrayListOf())
```
The various clients call `WordService.setGuess()` when a user enters a letter and then `WordService.checkGuess()` after row of letters
are entered...UI then reflects any resulting updates to above `StateFlow`'s.  The Compose clients for example do that using following (with any updates to those `StateFlow's` triggering recomposition)
```
val boardGuesses by wordMasterService.boardGuesses.collectAsState()
val boardStatus by wordMasterService.boardStatus.collectAsState()
```
On iOS we're using [KMP-NativeCoroutines](https://github.com/rickclephas/KMP-NativeCoroutines) library to map the `StateFlow`s to Swift `AsyncStream`s.  So, for example, our Swift view model includes
```
@Published public var boardStatus: [[LetterStatus]] = []
@Published public var boardGuesses: [[String]] = []
```
which are then updated using for example
```
let stream = asyncStream(for: wordMasterService.boardStatusNative)
for try await data in stream {
  self.boardStatus = data as! [[LetterStatus]]
}
let stream = asyncStream(for: wordMasterService.boardGuessesNative)
for try await data in stream {
    self.boardGuesses = data as! [[String]]
}
```
Any updates to `boardStatus` or `boardGuesses` will trigger our SwiftUI UI to be recomposed again.
### Remaining work includes
- check if overall word is valid and show indication in UI if not (ideally with animations!)
- better keyboard navigation
- share Compose code between Android and Desktop
- indicator in UI that correct guess entered (other than all letters being green)
### Screenshots



## Full set of Kotlin Multiplatform/Compose/SwiftUI samples
*  PeopleInSpace (https://github.com/joreilly/PeopleInSpace)
*  GalwayBus (https://github.com/joreilly/GalwayBus)
*  Confetti (https://github.com/joreilly/Confetti)
*  BikeShare (https://github.com/joreilly/BikeShare)
*  FantasyPremierLeague (https://github.com/joreilly/FantasyPremierLeague)
*  ClimateTrace (https://github.com/joreilly/ClimateTraceKMP)
*  GeminiKMP (https://github.com/joreilly/GeminiKMP)
*  MortyComposeKMM (https://github.com/joreilly/MortyComposeKMM)
*  StarWars (https://github.com/joreilly/StarWars)
*  WordMasterKMP (https://github.com/joreilly/WordMasterKMP)
*  Chip-8 (https://github.com/joreilly/chip-8)