parent
d1488a7dac
commit
2de681284d
@ -0,0 +1,69 @@
|
|||||||
|
//
|
||||||
|
// GameScene.swift
|
||||||
|
// DouShouQi_App
|
||||||
|
//
|
||||||
|
// Created by etudiant on 28/05/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SpriteKit
|
||||||
|
import DouShouQiModel
|
||||||
|
|
||||||
|
class GameScene : SKScene {
|
||||||
|
var game: Game = try! Game(withRules: ClassicRules(), andPlayer1: RandomPlayer(withName: "Rayhan", andId: .player1)!, andPlayer2: RandomPlayer(withName: "Rémi", andId: .player2)!)
|
||||||
|
|
||||||
|
let pieces: [Owner : [Animal:SpriteMeeple]] = [
|
||||||
|
.player1: [
|
||||||
|
.rat: SpriteMeeple(imageNamed: "rat", size: CGSize(width: 100, height: 100), backgroundColor: .black),
|
||||||
|
.cat: SpriteMeeple(imageNamed: "cat", size: CGSize(width: 100, height: 100), backgroundColor: .black),
|
||||||
|
.dog: SpriteMeeple(imageNamed: "dog", size: CGSize(width: 100, height: 100), backgroundColor: .black),
|
||||||
|
.wolf: SpriteMeeple(imageNamed: "wolf", size: CGSize(width: 100, height: 100), backgroundColor: .black),
|
||||||
|
.leopard: SpriteMeeple(imageNamed: "leopard", size: CGSize(width: 100, height: 100), backgroundColor: .black),
|
||||||
|
.lion: SpriteMeeple(imageNamed: "lion", size: CGSize(width: 100, height: 100), backgroundColor: .black),
|
||||||
|
.tiger: SpriteMeeple(imageNamed: "tiger", size: CGSize(width: 100, height: 100), backgroundColor: .black),
|
||||||
|
.elephant: SpriteMeeple(imageNamed: "elephant", size: CGSize(width: 100, height: 100), backgroundColor: .black),
|
||||||
|
],
|
||||||
|
.player2: [
|
||||||
|
.rat: SpriteMeeple(imageNamed: "rat-inv", size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
||||||
|
.cat: SpriteMeeple(imageNamed: "cat-inv", size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
||||||
|
.dog: SpriteMeeple(imageNamed: "dog-inv", size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
||||||
|
.wolf: SpriteMeeple(imageNamed: "wolf-inv", size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
||||||
|
.leopard: SpriteMeeple(imageNamed: "leopard-inv", size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
||||||
|
.lion: SpriteMeeple(imageNamed: "lion-inv", size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
||||||
|
.tiger: SpriteMeeple(imageNamed: "tiger-inv", size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
||||||
|
.elephant: SpriteMeeple(imageNamed: "elephant-inv", size: CGSize(width: 100, height: 100), backgroundColor: .blue),
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
|
let imageBoard: SKSpriteNode = SKSpriteNode(imageNamed: "board")
|
||||||
|
|
||||||
|
override init(size: CGSize) {
|
||||||
|
super.init(size: size)
|
||||||
|
imageBoard.size = size
|
||||||
|
self.scaleMode = .aspectFit
|
||||||
|
self.anchorPoint = CGPoint(x: 0.5, y: 0.5)
|
||||||
|
self.backgroundColor = .yellow
|
||||||
|
|
||||||
|
self.addChild(imageBoard)
|
||||||
|
|
||||||
|
for piece in pieces.flatMap({owner, pieces in pieces.values}) {
|
||||||
|
self.addChild(piece)
|
||||||
|
}
|
||||||
|
|
||||||
|
displayBoard(game.board)
|
||||||
|
}
|
||||||
|
|
||||||
|
func displayBoard(_ board: Board) {
|
||||||
|
for row in 0..<board.nbRows {
|
||||||
|
for col in 0..<board.nbColumns {
|
||||||
|
if let p = board.grid[row][col].piece, let sprite = pieces[p.owner]?[p.animal] {
|
||||||
|
sprite.cellPosition = CGPoint(x: row, y: col)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder aDecoder: NSCoder) {
|
||||||
|
super.init(coder: aDecoder);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue