|
|
|
@ -7,14 +7,71 @@
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import SpriteKit
|
|
|
|
|
import DouShouQiModel
|
|
|
|
|
|
|
|
|
|
struct GameView: View {
|
|
|
|
|
|
|
|
|
|
var game:GameScene = GameScene(size: CGSize(width: 940, height: 740))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
SpriteView(scene: game)
|
|
|
|
|
//Text("Msg à modifié !")
|
|
|
|
|
SpriteView(scene: game).task {
|
|
|
|
|
|
|
|
|
|
game.game.addGameStartedListener { board in startGame()}
|
|
|
|
|
game.game.addGameOverListener { board, result, player in gameOver() }
|
|
|
|
|
game.game.addGameChangedListener { game in gameChange() }
|
|
|
|
|
game.game.addBoardChangedListener { board in boardChange() }
|
|
|
|
|
|
|
|
|
|
game.game.addMoveChosenCallbacksListener { board, move, player in moveChose(board: board, move: move, player: player) }
|
|
|
|
|
game.game.addInvalidMoveCallbacksListener { board,move,player,bool in invalidMove(board: board, move: move, player:player, bool:bool)}
|
|
|
|
|
|
|
|
|
|
game.game.addPlayerNotifiedListener { board, player in
|
|
|
|
|
print("Player notif : \(player.id)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try await player.chooseMove(in: board, with: game.game.rules)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("------------")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try! await game.game.start()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------ Listener -------- //
|
|
|
|
|
|
|
|
|
|
func startGame() { print("Start game !") }
|
|
|
|
|
func gameOver() { print("Game over !") }
|
|
|
|
|
func gameChange() { print("Game change !") }
|
|
|
|
|
func boardChange() {
|
|
|
|
|
print("Board change !")
|
|
|
|
|
game.displayBoard(board: game.game.board)
|
|
|
|
|
print("Last : \(String(describing: GameScene.lastMove?.description))")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func moveChose(board:Board,move:Move,player:Player) {
|
|
|
|
|
print("Move choisi !")
|
|
|
|
|
print("joué par \(player.id)")
|
|
|
|
|
print("Move : \(move.description)")
|
|
|
|
|
print("------------")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func invalidMove(board:Board,move:Move,player:Player,bool:Bool) {
|
|
|
|
|
print("Move invalid ! (\(bool))")
|
|
|
|
|
print("Player : \(player.id)")
|
|
|
|
|
print("Move : \(move.description)")
|
|
|
|
|
print("------------")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------- //
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct GameView_Previews: PreviewProvider {
|
|
|
|
|