|
|
|
@ -38,6 +38,21 @@ class PlayingGameVM: ObservableObject {
|
|
|
|
|
return game.rules.getNextPlayer() == .player1 ? Colors.MeepleP1! : Colors.MeepleP2!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public var winner: String {
|
|
|
|
|
guard self.game.isOver else {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guard let lastMove: Move = self.game.rules.historic.last else {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guard let winner: DouShouQiModel.Player = game.players[lastMove.owner] else {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
return winner.name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Inits
|
|
|
|
|
init(withGame game: Game) {
|
|
|
|
|
self.game = game
|
|
|
|
@ -57,6 +72,34 @@ class PlayingGameVM: ObservableObject {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.game.addGameOverListener { board, result, player in
|
|
|
|
|
switch(result){
|
|
|
|
|
case .notFinished:
|
|
|
|
|
print("⏳ Game is not over yet!")
|
|
|
|
|
case .winner(winner: let o, reason: let r):
|
|
|
|
|
print(board)
|
|
|
|
|
print("**************************************")
|
|
|
|
|
print("Game Over!!!")
|
|
|
|
|
print("🥇🏆 and the winner is... \(o == .player1 ? "🟡" : "🔴") \(player?.name ?? "")!")
|
|
|
|
|
switch(r){
|
|
|
|
|
case .denReached:
|
|
|
|
|
print("🪺 the opponent's den has been reached.")
|
|
|
|
|
case .noMorePieces:
|
|
|
|
|
print("🐭🐱🐯🦁🐘 all the opponent's animals have been eaten...")
|
|
|
|
|
case .noMovesLeft:
|
|
|
|
|
print("⛔️ the opponent can not move any piece!")
|
|
|
|
|
case .tooManyOccurences:
|
|
|
|
|
print("🔄 the opponent seem to like this situation... but enough is enough. Sorry...")
|
|
|
|
|
default:
|
|
|
|
|
print("Reason unknown...")
|
|
|
|
|
}
|
|
|
|
|
print("**************************************")
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
print("Error")
|
|
|
|
|
return nil
|
|
|
|
@ -79,6 +122,7 @@ class PlayingGameVM: ObservableObject {
|
|
|
|
|
self.objectWillChange.send()
|
|
|
|
|
} else {
|
|
|
|
|
sender.cellPosition = start
|
|
|
|
|
sender.cellPosition = start
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|