-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (GameEngineKit): Add ColorQuest gameplay
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
Modules/GameEngineKit/Sources/Gameplay/Specific/ColorQuestGameplay.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import Combine | ||
import Foundation | ||
|
||
public class ColorQuestGameplay: GameplayProtocol { | ||
public var choices = CurrentValueSubject<[ChoiceViewModel], Never>([]) | ||
public var state = CurrentValueSubject<GameplayState, Never>(.idle) | ||
|
||
public init(choices: [ChoiceViewModel]) { | ||
self.choices.send(choices) | ||
self.state.send(.playing) | ||
|
||
// TODO(@ladislas): Show the right answer color on Leka's belt | ||
let index = self.choices.value.firstIndex(where: { $0.rightAnswer })! | ||
let color = self.choices.value[index].item | ||
print("Leka is \(color)") | ||
} | ||
|
||
public func process(choice: ChoiceViewModel) { | ||
if choice.rightAnswer { | ||
if let index = choices.value.firstIndex(where: { $0.id == choice.id }) { | ||
self.choices.value[index].status = .playingRightAnimation | ||
|
||
// TO DO (@hugo) asyncAwait | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { | ||
self.choices.value[index].status = .notSelected | ||
} | ||
self.state.send(.finished) | ||
// TODO(@ladislas): Run reinforcers and lottie animation | ||
} | ||
} else { | ||
if let index = choices.value.firstIndex(where: { $0.id == choice.id }) { | ||
self.choices.value[index].status = .playingWrongAnimation | ||
|
||
// TO DO (@hugo) asyncAwait | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) { | ||
self.choices.value[index].status = .notSelected | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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