|
|
|
@ -43,11 +43,14 @@ class SpriteMoople : SKNode {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
|
|
|
var movePoss: [ move ] = refGameScene!.game.rules.getMoves(board: refGameScene!.game.board,owner:refGameScene!.game.rules.getNextPlayer())
|
|
|
|
|
|
|
|
|
|
let movePoss: [ Move ] = refGameScene!.game.rules.getMoves(in: refGameScene!.game.board,of:refGameScene!.game.rules.getNextPlayer(),fromRow: Int(self.cellPosition.x),andColumn: Int(self.cellPosition.y))
|
|
|
|
|
for pos in movePoss {
|
|
|
|
|
var rect = SKShapeNode(rectOf: CGSize(width: 90, height: 90))
|
|
|
|
|
rect.position = returnPositionByCellPos(cellX:move.destinationRow,cellY:move.destinationColm)
|
|
|
|
|
refGameScene!.deplacementPossible.add(rect)
|
|
|
|
|
let rect = SKShapeNode(rectOf: CGSize(width: 90, height: 90))
|
|
|
|
|
rect.position = returnPositionByCellPos(cellX:pos.rowDestination,cellY:pos.columnDestination)
|
|
|
|
|
rect.fillColor = .red
|
|
|
|
|
rect.zPosition = 1
|
|
|
|
|
refGameScene!.deplacementPossible.append(rect)
|
|
|
|
|
refGameScene!.addChild(rect)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -60,34 +63,32 @@ class SpriteMoople : SKNode {
|
|
|
|
|
let localisation = touches.first?.location(in: parent!)
|
|
|
|
|
|
|
|
|
|
// Clean rect
|
|
|
|
|
for rect in refGameScene!.deplacementPossible {
|
|
|
|
|
rect.removeChild()
|
|
|
|
|
}
|
|
|
|
|
refGameScene!.removeChildren(in: refGameScene!.deplacementPossible)
|
|
|
|
|
|
|
|
|
|
if let localisation = localisation {
|
|
|
|
|
|
|
|
|
|
if (localisation.x > 400 || localisation.x < -400 || localisation.y < -300 || localisation.y > 300){
|
|
|
|
|
print(localisation)
|
|
|
|
|
if (localisation.x > 450 || localisation.x < -450 || localisation.y < -350 || localisation.y > 350){
|
|
|
|
|
print("Hors limite !")
|
|
|
|
|
self.position = returnPositionByCellPos(cellX:Int(self.cellPosition.x),cellY:Int(self.cellPosition.y))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
let posX = Int(round((localisation.x - (-400)) / 100))
|
|
|
|
|
let posY = Int(round((localisation.y - (-300)) / 100))
|
|
|
|
|
|
|
|
|
|
// Récupéré le joueur qui doit jouer
|
|
|
|
|
let player = refGameScene!.game.rules.getNextPlayer()
|
|
|
|
|
if ( player == refGameScene!.game.board.grid[self.cellPosition.x][self.cellPosition.y].piece!.owner ){
|
|
|
|
|
let owner = refGameScene!.game.rules.getNextPlayer()
|
|
|
|
|
let player = refGameScene!.game.players[owner]!
|
|
|
|
|
|
|
|
|
|
if ( owner == refGameScene!.game.board.grid[Int(self.cellPosition.x)][Int(self.cellPosition.y)].piece!.owner ){
|
|
|
|
|
if player is HumanPlayer { // Player humain
|
|
|
|
|
try! (refGameScene!.game.players[player] as! HumanPlayer).chooseMove(x)
|
|
|
|
|
Task {
|
|
|
|
|
try! await (player as! HumanPlayer).chooseMove(Move(of: owner, fromRow:Int(self.cellPosition.x), andFromColumn: Int(self.cellPosition.y), toRow: posX, andToColumn: posY))
|
|
|
|
|
}
|
|
|
|
|
else { // IA
|
|
|
|
|
try! await refGameScene!.game.players[player].chooseMove(in: refGameScene!.game.board, with: refGameScene!.game.rules)
|
|
|
|
|
}
|
|
|
|
|
// Change position de la piece
|
|
|
|
|
self.cellPosition = CGPoint(x: posX, y: posY)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Ce n'est pas la bonne personne, reset position
|
|
|
|
|
self.position = returnPositionByCellPos(cellX:self.cellPosition.x,cellY:self.cellPosition.y)
|
|
|
|
|
self.position = returnPositionByCellPos(cellX:Int(self.cellPosition.x),cellY:Int(self.cellPosition.y))
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -99,6 +100,6 @@ class SpriteMoople : SKNode {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func returnPositionByCellPos(cellX:Int,cellY:Int) -> CGPoint {
|
|
|
|
|
return CGPoint(x: SpriteMoople.offset.x + SpriteMoople.direction.dx * cellX,y: self.position.y = SpriteMoople.offset.y + SpriteMoople.direction.dy * cellY)
|
|
|
|
|
return CGPoint(x: SpriteMoople.offset.x + SpriteMoople.direction.dx * CGFloat(cellX),y: SpriteMoople.offset.y + SpriteMoople.direction.dy * CGFloat(cellY))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|