# 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<ArrayList<ArrayList<String>>>(arrayListOf())
val boardStatus = MutableStateFlow<ArrayList<ArrayList<LetterStatus>>>(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()
```
<br>
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
<img width="462" alt="Screenshot 2022-01-08 at 22 40 36" src="https://user-images.githubusercontent.com/6302/148663058-a725d403-b956-4c84-8635-fbb388fa63a8.png">
![Simulator Screen Shot - iPhone 13 Pro - 2022-01-08 at 22 38 11](https://user-images.githubusercontent.com/6302/148663064-3ed57b1f-c1a3-4e39-b2c2-2ddb3fb09ed9.png)
![Screenshot_1641682073](https://user-images.githubusercontent.com/6302/148663060-c1047266-425c-4b14-bdaf-b7177a1fa332.png)
没有合适的资源?快使用搜索试试~ 我知道了~
带有 SwiftUI 和 Compose(桌面和 Android)客户端的 Kotlin 多平台示例_Swift_代码_下载
共46个文件
kt:10个
kts:6个
json:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 77 浏览量
2022-06-23
17:36:10
上传
评论
收藏 294KB ZIP 举报
温馨提示
Kotlin Multiplatform 示例深受Wordle游戏以及Word Master和wordle-solver示例的启发。主要游戏逻辑/状态包含在具有基本 UI 的共享 KMP 代码中,然后包含在以下客户端中 iOS (SwiftUI) Android(Jetpack 组合) 桌面(为桌面撰写) 效果展示: https://user-images.githubusercontent.com/6302/148663058-a725d403-b956-4c84-8635-fbb388fa63a8.png 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
WordMasterKMP-main.zip (46个子文件)
WordMasterKMP-main
gradlew.bat 2KB
gradlew 5KB
art
screenshot1.png 205KB
gradle.properties 138B
shared
src
androidMain
AndroidManifest.xml 153B
commonTest
kotlin
dev
johnoreilly
wordmaster
shared
WordMasterServiceTest.kt 2KB
commonMain
kotlin
dev
johnoreilly
wordmaster
shared
WordMasterService.kt 4KB
build.gradle.kts 2KB
iosApp
iosApp
Assets.xcassets
AppIcon.appiconset
Contents.json 2KB
Contents.json 62B
AccentColor.colorset
Contents.json 122B
ViewModel.swift 3KB
Preview Content
Preview Assets.xcassets
Contents.json 62B
iOSApp.swift 132B
Info.plist 1KB
ContentView.swift 2KB
words.txt 14KB
iosApp.xcodeproj
project.xcworkspace
xcshareddata
swiftpm
Package.resolved 617B
IDEWorkspaceChecks.plist 238B
project.pbxproj 16KB
.github
workflows
android.yml 534B
buildSrc
src
main
java
Dependencies.kt 2KB
.gitignore 6B
build.gradle.kts 66B
LICENSE 11KB
gradle
wrapper
gradle-wrapper.jar 53KB
gradle-wrapper.properties 230B
compose-desktop
src
main
kotlin
main.kt 6KB
.gitignore 13B
build.gradle.kts 583B
.gitignore 612B
settings.gradle.kts 277B
build.gradle.kts 557B
androidApp
src
main
res
values
colors.xml 207B
styles.xml 214B
assets
words.txt 14KB
java
dev
johnoreilly
wordmaster
androidApp
WordMasterApplication.kt 432B
MainActivity.kt 6KB
theme
Theme.kt 1KB
Shape.kt 325B
Type.kt 811B
Color.kt 229B
AndroidManifest.xml 968B
build.gradle.kts 2KB
README.md 3KB
words.txt 14KB
共 46 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功