Skip to content

Commit

Permalink
✨ (GameEngineKit): Add ColorQuest gameplay
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Sep 25, 2023
1 parent 4a0317e commit 2d5a1fa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
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
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum GameplayType {
case selectTheRightAnswer
case selectAllRightAnswers
case selectSomeRightAnswers(Int)
case colorQuest
}

public enum InterfaceType {
Expand Down
2 changes: 2 additions & 0 deletions Modules/GameEngineKit/Sources/StepManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class StepManager: ObservableObject {
case .selectSomeRightAnswers(let answersNumber):
return GameplaySelectSomeRightAnswers(
choices: stepModel.choices, rightAnswersToFind: answersNumber)
case .colorQuest:
return ColorQuestGameplay(choices: stepModel.choices)
}
}

Expand Down

0 comments on commit 2d5a1fa

Please sign in to comment.