|
|
|
@ -19,24 +19,24 @@ class GameScene : SKScene {
|
|
|
|
|
|
|
|
|
|
let pieces: [Owner : [Animal:SpriteMeeple]] = [
|
|
|
|
|
.player1: [
|
|
|
|
|
.rat: SpriteMeeple(imageNamed: AppImages.Rat, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!),
|
|
|
|
|
.cat: SpriteMeeple(imageNamed: AppImages.Cat, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!),
|
|
|
|
|
.dog: SpriteMeeple(imageNamed: AppImages.Dog, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!),
|
|
|
|
|
.wolf: SpriteMeeple(imageNamed: AppImages.Wolf, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!),
|
|
|
|
|
.leopard: SpriteMeeple(imageNamed: AppImages.Leopard, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!),
|
|
|
|
|
.lion: SpriteMeeple(imageNamed: AppImages.Lion, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!),
|
|
|
|
|
.tiger: SpriteMeeple(imageNamed: AppImages.Tigger, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!),
|
|
|
|
|
.elephant: SpriteMeeple(imageNamed: AppImages.Elephant, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!),
|
|
|
|
|
.rat: SpriteMeeple(imageNamed: AppImages.Rat, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!, imageRotation: 180),
|
|
|
|
|
.cat: SpriteMeeple(imageNamed: AppImages.Cat, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!, imageRotation: 180),
|
|
|
|
|
.dog: SpriteMeeple(imageNamed: AppImages.Dog, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!, imageRotation: 180),
|
|
|
|
|
.wolf: SpriteMeeple(imageNamed: AppImages.Wolf, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!, imageRotation: 180),
|
|
|
|
|
.leopard: SpriteMeeple(imageNamed: AppImages.Leopard, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!, imageRotation: 180),
|
|
|
|
|
.lion: SpriteMeeple(imageNamed: AppImages.Lion, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!, imageRotation: 180),
|
|
|
|
|
.tiger: SpriteMeeple(imageNamed: AppImages.Tigger, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!, imageRotation: 180),
|
|
|
|
|
.elephant: SpriteMeeple(imageNamed: AppImages.Elephant, size: CGSize(width: 100, height: 100), backgroundColor: Colors.MeepleP1!, imageRotation: 180),
|
|
|
|
|
],
|
|
|
|
|
.player2: [
|
|
|
|
|
.rat: SpriteMeeple(imageNamed: AppImages.Rat, size: CGSize(width: 100, height: 100), backgroundColor: .blue, imageRotation: 180),
|
|
|
|
|
.cat: SpriteMeeple(imageNamed: AppImages.Cat, size: CGSize(width: 100, height: 100), backgroundColor: .blue, imageRotation: 180),
|
|
|
|
|
.dog: SpriteMeeple(imageNamed: AppImages.Dog, size: CGSize(width: 100, height: 100), backgroundColor: .blue, imageRotation: 180),
|
|
|
|
|
.wolf: SpriteMeeple(imageNamed: AppImages.Wolf, size: CGSize(width: 100, height: 100), backgroundColor: .blue, imageRotation: 180),
|
|
|
|
|
.leopard: SpriteMeeple(imageNamed: AppImages.Leopard, size: CGSize(width: 100, height: 100), backgroundColor: .blue, imageRotation: 180),
|
|
|
|
|
.lion: SpriteMeeple(imageNamed: AppImages.Lion, size: CGSize(width: 100, height: 100), backgroundColor: .blue, imageRotation: 180),
|
|
|
|
|
.tiger: SpriteMeeple(imageNamed: AppImages.Tigger, size: CGSize(width: 100, height: 100), backgroundColor: .blue, imageRotation: 180),
|
|
|
|
|
.elephant: SpriteMeeple(imageNamed: AppImages.Elephant, size: CGSize(width: 100, height: 100), backgroundColor: .blue, imageRotation: 180),
|
|
|
|
|
.rat: SpriteMeeple(imageNamed: AppImages.Rat, size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
|
|
|
|
.cat: SpriteMeeple(imageNamed: AppImages.Cat, size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
|
|
|
|
.dog: SpriteMeeple(imageNamed: AppImages.Dog, size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
|
|
|
|
.wolf: SpriteMeeple(imageNamed: AppImages.Wolf, size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
|
|
|
|
.leopard: SpriteMeeple(imageNamed: AppImages.Leopard, size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
|
|
|
|
.lion: SpriteMeeple(imageNamed: AppImages.Lion, size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
|
|
|
|
.tiger: SpriteMeeple(imageNamed: AppImages.Tigger, size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
|
|
|
|
.elephant: SpriteMeeple(imageNamed: AppImages.Elephant, size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
@ -60,24 +60,12 @@ class GameScene : SKScene {
|
|
|
|
|
|
|
|
|
|
for piece in pieces.flatMap({owner, pieces in pieces.values}) {
|
|
|
|
|
self.addChild(piece)
|
|
|
|
|
piece.setOnMove(onMove: onMeepleMove)
|
|
|
|
|
piece.setOnMove(onMove: gameVM.onMeepleMove)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initializeBoard(game!.board)
|
|
|
|
|
|
|
|
|
|
game?.addInvalidMoveCallbacksListener { _, move, player, result in
|
|
|
|
|
if result {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
print("**************************************")
|
|
|
|
|
print("⚠️⚠️⚠️⚠️ Invalid Move detected: \(move) by \(player.name) (\(player.id))")
|
|
|
|
|
print("**************************************")
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Task {
|
|
|
|
|
try await game?.start()
|
|
|
|
|
}
|
|
|
|
|
gameVM.start()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func initializeBoard(_ board: Board) {
|
|
|
|
@ -86,7 +74,6 @@ class GameScene : SKScene {
|
|
|
|
|
if let piece = currentCell.piece {
|
|
|
|
|
pieces[piece.owner]?[piece.animal]?.cellPosition = CGPoint(x: cellIndex, y: lineIndex)
|
|
|
|
|
pieces[piece.owner]?[piece.animal]?.cellPosition = CGPoint(x: 0, y: 0)
|
|
|
|
|
print("line :", lineIndex, " column: ", cellIndex)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -96,24 +83,4 @@ class GameScene : SKScene {
|
|
|
|
|
game = try! Game(withRules: ClassicRules(), andPlayer1: DouShouQiModel.Player(withName: "P1", andId: .player1)!, andPlayer2: DouShouQiModel.Player(withName: "P2", andId: .player2)!)
|
|
|
|
|
super.init(coder: aDecoder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func onMeepleMove(_ start: CGPoint, _ end: CGPoint) {
|
|
|
|
|
|
|
|
|
|
if let game: Game = self.game {
|
|
|
|
|
let owner = game.rules.getNextPlayer()
|
|
|
|
|
let player: DouShouQiModel.Player = game.players[owner]!
|
|
|
|
|
|
|
|
|
|
let move = Move(of: owner, fromRow: Int(start.y), andFromColumn: Int(start.x), toRow: Int(end.y), andToColumn: Int(end.x))
|
|
|
|
|
|
|
|
|
|
print("Meeple moved = ", start, " -> ", end)
|
|
|
|
|
|
|
|
|
|
Task {
|
|
|
|
|
try! await (player as! HumanPlayer).chooseMove(move)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public func start() async throws {
|
|
|
|
|
try await game?.start()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|