pull/24/head^2
Your Name 11 months ago
parent 0acd544cb0
commit 011f741e73

@ -12,9 +12,7 @@ import DouShouQiModel
class GameScene : SKScene {
let imageBoard:SKSpriteNode = SKSpriteNode(imageNamed: "board")
var game:Game = try! Game(withRules: ClassicRules(), andPlayer1: RandomPlayer(withName: "Bot1", andId: .player1)!, andPlayer2: HumanPlayer(withName: "Bot2", andId: .player2,andInputMethod:)!)
static var lastMove:Move? = nil
var game:Game = try! Game(withRules: ClassicRules(), andPlayer1: RandomPlayer(withName: "Bot1", andId: .player1)!, andPlayer2: HumanPlayer(withName: "Bot2", andId: .player2)!)
var pieces: [Owner : [ Animal : SpriteMoople]] = [ .player1 : [ .cat : SpriteMoople(nameImage: "catMeeple", couleur: .red),
.dog : SpriteMoople(nameImage: "dogMeeple", couleur: .red),
@ -40,7 +38,7 @@ class GameScene : SKScene {
override init(size: CGSize) {
super.init(size: size)
// -- -- //
scaleMode = .aspectFit
anchorPoint = CGPoint(x: 0.5, y: 0.5)
@ -49,10 +47,12 @@ class GameScene : SKScene {
for c in pieces.flatMap({ _,values in return values })
{
c.self.value.refGameScene = self
self.addChild(c.self.value)
}
displayBoard(board: game.board)
}
@ -68,12 +68,5 @@ class GameScene : SKScene {
}
}
func humanChoseMove(player:HumanPlayer){
while ( GameScene.lastMove == nil ) { }
//return Move(of: player.id, fromRow: <#T##Int#>, andFromColumn: <#T##Int#>, toRow: <#T##Int#>, andToColumn: <#T##Int#>)
}
}

@ -13,12 +13,10 @@ struct GameView: View {
var game:GameScene = GameScene(size: CGSize(width: 940, height: 740))
var body: some View {
//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() }
@ -28,18 +26,23 @@ struct GameView: View {
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("Player notif : \(player.id) à toi de jouer ")
/*
if player is HumanPlayer {
var x:Move
//let newThread = Thread { x = game.humanChoseMove(player: player as! HumanPlayer) }
//newThread.start()
//let move = await game.humanChoseMove(player: player as! HumanPlayer)
try! await (player as! HumanPlayer).chooseMove(x)
}
else {
try await player.chooseMove(in: board, with: game.game.rules)
}*/
print("------------")
}
try! await game.game.start()
}
}
@ -52,7 +55,6 @@ struct GameView: View {
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) {

@ -17,6 +17,8 @@ class SpriteMoople : SKNode {
let image:SKSpriteNode
let ellipse:SKShapeNode = SKShapeNode(circleOfRadius: 40)
weak var refGameScene:GameScene?
var cellPosition:CGPoint = CGPoint(x: 0, y: 0) {
didSet {
self.position.x = SpriteMoople.offset.x + SpriteMoople.direction.dx * cellPosition.x
@ -59,11 +61,15 @@ class SpriteMoople : SKNode {
let posX = Int(round((localisation.x - (-400)) / 100))
let posY = Int(round((localisation.y - (-300)) / 100))
GameScene.lastMove = Move(of:.noOne, fromRow:Int(self.cellPosition.x),andFromColumn:Int(self.cellPosition.y),toRow:posX, andToColumn:posY)
//GameScene.lastMove = Move(of:.noOne, fromRow:Int(self.cellPosition.x),andFromColumn:Int(self.cellPosition.y),toRow:posX, andToColumn:posY)
//print("Change lastMove -> \(GameScene.lastMove)");
self.cellPosition = CGPoint(x: posX, y: posY)
// Faire un retour en arrière si lastMove != nil
// Get player
let x = refGameScene?.game.rules.getNextPlayer()
//try! refGameScene?.game.players.
// Faire un retour en arrière si lastMove != nil
return
}
}

Loading…
Cancel
Save