vm fonctionnel

pull/28/head
Your Name 10 months ago
parent f0ce1123bc
commit 61961bbd5f

@ -23,6 +23,7 @@
82CE59E92C045D1100ADEE24 /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CE59E82C045D1100ADEE24 /* GameScene.swift */; };
82CE59EB2C045E3800ADEE24 /* GameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CE59EA2C045E3800ADEE24 /* GameView.swift */; };
82CE59EF2C0460E500ADEE24 /* SpriteMoople.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82CE59EE2C0460E500ADEE24 /* SpriteMoople.swift */; };
82D7BDA22C29A25500723ABA /* VMGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82D7BDA12C29A25500723ABA /* VMGame.swift */; };
82FBE2F22C25811400672F32 /* lion.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 82FBE2E92C25811400672F32 /* lion.usdz */; };
82FBE2F32C25811400672F32 /* dog.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 82FBE2EA2C25811400672F32 /* dog.usdz */; };
82FBE2F42C25811400672F32 /* board.usdz in Resources */ = {isa = PBXBuildFile; fileRef = 82FBE2EB2C25811400672F32 /* board.usdz */; };
@ -113,6 +114,7 @@
82CE59E82C045D1100ADEE24 /* GameScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameScene.swift; sourceTree = "<group>"; };
82CE59EA2C045E3800ADEE24 /* GameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameView.swift; sourceTree = "<group>"; };
82CE59EE2C0460E500ADEE24 /* SpriteMoople.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpriteMoople.swift; sourceTree = "<group>"; };
82D7BDA12C29A25500723ABA /* VMGame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VMGame.swift; sourceTree = "<group>"; };
82FBE2E92C25811400672F32 /* lion.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; name = lion.usdz; path = Ressources/3DModel/lion.usdz; sourceTree = SOURCE_ROOT; };
82FBE2EA2C25811400672F32 /* dog.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; name = dog.usdz; path = Ressources/3DModel/dog.usdz; sourceTree = SOURCE_ROOT; };
82FBE2EB2C25811400672F32 /* board.usdz */ = {isa = PBXFileReference; lastKnownFileType = file.usdz; name = board.usdz; path = Ressources/3DModel/board.usdz; sourceTree = SOURCE_ROOT; };
@ -249,6 +251,7 @@
82CE59E52C045C7500ADEE24 /* Game */ = {
isa = PBXGroup;
children = (
82D7BDA12C29A25500723ABA /* VMGame.swift */,
C2DF07672C2071B300BEE0E1 /* SKActions */,
C2DF075C2C20719800BEE0E1 /* SKAnimations */,
82CE59EC2C0460AA00ADEE24 /* SKNodes */,
@ -604,6 +607,7 @@
C2DF076B2C2071B300BEE0E1 /* ActionRemove.swift in Sources */,
C2F015252C09D3E7000F7221 /* ItemCollectionParty.swift in Sources */,
82CE59EF2C0460E500ADEE24 /* SpriteMoople.swift in Sources */,
82D7BDA22C29A25500723ABA /* VMGame.swift in Sources */,
C2F0150C2C09D3A4000F7221 /* KeyboardReadable.swift in Sources */,
82CE59E92C045D1100ADEE24 /* GameScene.swift in Sources */,
C2F015242C09D3E7000F7221 /* ProfileComponent.swift in Sources */,

@ -15,14 +15,14 @@ struct GameView: View {
var player2Name: String = "toto"
var player2Image: UIImage
var vm:VMGame = VMGame()
@ObservedObject var vm:VMGame = VMGame()
var body: some View {
ZStack {
Text(msg)
SpriteView(scene: gameScene)
Text(vm.msg)
SpriteView(scene: vm.gameScene)
.edgesIgnoringSafeArea(.all)
.task { vm.start() }
.task { await vm.start() }
VStack {
HStack {
@ -54,7 +54,7 @@ struct GameView: View {
}
.padding()
Spacer()
Text(msg)
Text(vm.msg)
.font(.title)
.foregroundColor(.white)
.padding()

@ -1,35 +1,37 @@
import Foundation
import SwiftUI
import DouShouQiModel
struct VMGame {
class VMGame : ObservableObject {
@State var msg: String = ""
@Published var msg: String = ""
var gameScene: GameScene = GameScene(size: CGSize(width: 940, height: 740),player1Name:"TOTO",player1Image: Image("profil"),player2Name:"toto2",player2Image: Image("profil"))
func start(){
func start() async {
defineListener()
try! await gameScene.game.start()
}
func defineListener(){
gameScene.game.addGameStartedListener { board in startGame() }
gameScene.game.addGameOverListener { board, result, player in gameOver(result : result) }
gameScene.game.addGameChangedListener { game in gameChange() }
gameScene.game.addBoardChangedListener { board in boardChange() }
gameScene.game.addGameStartedListener { board in self.startGame() }
gameScene.game.addGameOverListener { board, result, player in self.gameOver(result : result) }
gameScene.game.addGameChangedListener { game in self.gameChange() }
gameScene.game.addBoardChangedListener { board in self.boardChange() }
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.addMoveChosenCallbacksListener { board, move, player in self.moveChose(board: board, move: move, player: player) }
gameScene.game.addInvalidMoveCallbacksListener { board, move, player, bool in self.invalidMove(board: board, move: move, player: player, bool: bool) }
gameScene.game.addPieceRemovedListener { _, _, piece in removePiece(piece: piece) }
gameScene.game.addPieceRemovedListener { _, _, piece in self.removePiece(piece: piece) }
gameScene.game.addPlayerNotifiedListener { board, player in
print("Player notif : \(player.id) à toi de jouer ")
msg = "Player notif : \(player.id) à toi de jouer !"
self.msg = "Player notif : \(player.id) à toi de jouer !"
if player is IAPlayer {
try! await player.chooseMove(in: board, with: gameScene.game.rules)
try! await player.chooseMove(in: board, with: self.gameScene.game.rules)
}
}
}
@ -91,4 +93,4 @@ struct VMGame {
print("Remove piece from parent")
}
}
}
}

Loading…
Cancel
Save