diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift index 21d5495..69e63d0 100644 --- a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift +++ b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift @@ -56,24 +56,38 @@ class ArKitView : ARView { @objc private func handleGesture(_ recognizer: UIGestureRecognizer) { guard let translationGesture = recognizer as? EntityTranslationGestureRecognizer, let entity = translationGesture.entity else { return } - switch translationGesture.state { + let positionInitial = entity.position + let initialPosGame = vmArkit!.converWorldPosIntoPosModele(pos: entity.position) + + switch translationGesture.state { case .began: self.initialTransform = entity.transform case .ended: entity.move(to: initialTransform, relativeTo: entity.parent, duration: 1) - let pos = entity.position - /* - if ( pos.x > ) - if (localisation.x > 450 || localisation.x < -450 || localisation.y < -350 || localisation.y > 350){ + let pos = entity.position + if ( pos.x > 0.14656 || pos.x < -0.14656 || pos.z < -0.2748 || pos.z > 0.2748 ){ print("Hors limite !") - self.position = returnPositionByCellPos(cellX:Int(self.cellPosition.x),cellY:Int(self.cellPosition.y)) + // Return pos + entity.position = positionInitial return } - */ + let posX = Int(round((pos.x - (-0.14656)) / 0.458)) + let posY = Int(round((pos.z - (-0.2748)) / 0.3435)) + + // Récupéré le joueur qui doit jouer + let owner = vmArkit!.game.rules.getNextPlayer() + let player = vmArkit!.game.players[owner]! + if ( owner == vmArkit!.game.board.grid[Int(initialPosGame.x)][Int(initialPosGame.y)].piece!.owner ){ + if player is HumanPlayer { // Player humain + Task { + try! await (player as! HumanPlayer).chooseMove(Move(of: owner, fromRow:Int(initialPosGame.x), andFromColumn: Int(initialPosGame.y), toRow: posX, andToColumn: posY)) + } + } + } default: break diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift index aaf6e94..115fa9c 100644 --- a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift +++ b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift @@ -15,7 +15,9 @@ struct ContentArkit: View { var body: some View { VStack { Text("toto") - ArKitViewRepresentable(vm) + ArKitViewRepresentable(vm).task { + try! await vm.game.start() + } } } }