|
|
@ -13,13 +13,13 @@ struct GameView: View {
|
|
|
|
|
|
|
|
|
|
|
|
var gameScene:GameScene = GameScene(size: CGSize(width: 940, height: 740))
|
|
|
|
var gameScene:GameScene = GameScene(size: CGSize(width: 940, height: 740))
|
|
|
|
|
|
|
|
|
|
|
|
@State var msg:Text = Text("Msg")
|
|
|
|
@State var msg:String = "Msg"
|
|
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
var body: some View {
|
|
|
|
|
|
|
|
|
|
|
|
VStack(){
|
|
|
|
VStack(){
|
|
|
|
Text($msg)
|
|
|
|
Text(msg)
|
|
|
|
SpriteView(scene: game).task {
|
|
|
|
SpriteView(scene: gameScene).task {
|
|
|
|
|
|
|
|
|
|
|
|
gameScene.game.addGameStartedListener { board in startGame()}
|
|
|
|
gameScene.game.addGameStartedListener { board in startGame()}
|
|
|
|
gameScene.game.addGameOverListener { board, result, player in gameOver() }
|
|
|
|
gameScene.game.addGameOverListener { board, result, player in gameOver() }
|
|
|
@ -28,9 +28,16 @@ struct GameView: View {
|
|
|
|
|
|
|
|
|
|
|
|
gameScene.game.addMoveChosenCallbacksListener { board, move, player in moveChose(board: board, move: move, player: player) }
|
|
|
|
gameScene.game.addMoveChosenCallbacksListener { board, move, player in moveChose(board: board, move: move, player: player) }
|
|
|
|
gameScene.game.addInvalidMoveCallbacksListener { board,move,player,bool in invalidMove(board: board, move: move, player:player, bool:bool)}
|
|
|
|
gameScene.game.addInvalidMoveCallbacksListener { board,move,player,bool in invalidMove(board: board, move: move, player:player, bool:bool)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gameScene.game.addPieceRemovedListener { _,_,piece in removePiece(piece: piece) }
|
|
|
|
|
|
|
|
|
|
|
|
gameScene.game.addPlayerNotifiedListener { board, player in
|
|
|
|
gameScene.game.addPlayerNotifiedListener { board, player in
|
|
|
|
print("Player notif : \(player.id) à toi de jouer ")
|
|
|
|
print("Player notif : \(player.id) à toi de jouer ")
|
|
|
|
|
|
|
|
msg = "Player notif : \(player.id) à toi de jouer !"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (player is IAPlayer ){
|
|
|
|
|
|
|
|
try! await player.chooseMove(in: board, with: gameScene.game.rules)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try! await gameScene.game.start()
|
|
|
|
try! await gameScene.game.start()
|
|
|
@ -40,10 +47,12 @@ struct GameView: View {
|
|
|
|
|
|
|
|
|
|
|
|
// ------ Listener -------- //
|
|
|
|
// ------ Listener -------- //
|
|
|
|
|
|
|
|
|
|
|
|
mutating func startGame() { print("Start game !")
|
|
|
|
func startGame() { print("Start game !")
|
|
|
|
msg = "Start !!"
|
|
|
|
msg = "Start !!"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func gameOver() { print("Game over !") }
|
|
|
|
func gameOver() { print("Game over !")
|
|
|
|
|
|
|
|
msg = "Game over !!"
|
|
|
|
|
|
|
|
}
|
|
|
|
func gameChange() { print("Game change !") }
|
|
|
|
func gameChange() { print("Game change !") }
|
|
|
|
func boardChange() {
|
|
|
|
func boardChange() {
|
|
|
|
print("Board change !")
|
|
|
|
print("Board change !")
|
|
|
@ -51,19 +60,31 @@ struct GameView: View {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func moveChose(board:Board,move:Move,player:Player) {
|
|
|
|
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) {
|
|
|
|
func invalidMove(board:Board,move:Move,player:Player,bool:Bool) {
|
|
|
|
print("Move invalid ! (\(bool))") // True == Valid / False == Invalid
|
|
|
|
|
|
|
|
print("Player : \(player.id)")
|
|
|
|
if (bool){ // Valid
|
|
|
|
print("Move : \(move.description)")
|
|
|
|
print("Move valid de \(player.id)")
|
|
|
|
|
|
|
|
print("Move : \(move.description)")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else { // Invalid
|
|
|
|
|
|
|
|
print("Move invalid de \(player.id)")
|
|
|
|
|
|
|
|
print("Move : \(move.description)")
|
|
|
|
|
|
|
|
gameScene.displayBoard(board: gameScene.game.board)
|
|
|
|
|
|
|
|
}
|
|
|
|
print("------------")
|
|
|
|
print("------------")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func removePiece(piece:Piece){
|
|
|
|
|
|
|
|
print("Remove piece")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let node = gameScene.pieces[piece.owner]![piece.animal] {
|
|
|
|
|
|
|
|
print("Remove piece from parent")
|
|
|
|
|
|
|
|
node.removeFromParent()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------- //
|
|
|
|
// ------------------------- //
|
|
|
|
|
|
|
|
|
|
|
|