parent
c3db0a8e86
commit
e8bea4a595
@ -1,22 +1,41 @@
|
||||
import SpriteKit
|
||||
|
||||
public class GameScene: SKScene {
|
||||
public override init(size: CGSize) {
|
||||
super.init(size: size)
|
||||
private var boardNode: SKShapeNode
|
||||
private var cells: [PieceNode]
|
||||
|
||||
anchorPoint = CGPoint(x: 0.5, y: 0.5)
|
||||
public init(s: (w: Int, h: Int)) {
|
||||
let boardHeight = CGFloat(s.h) * PieceNode.pieceSize
|
||||
let gWidth = CGFloat(s.w) * PieceNode.pieceSize
|
||||
let gHeight = boardHeight + PieceNode.pieceSize
|
||||
|
||||
backgroundColor = .cyan
|
||||
boardNode = SKShapeNode(rect: CGRect(x: 0, y: 0, width: gWidth, height: boardHeight))
|
||||
boardNode.fillColor = .blue
|
||||
boardNode.strokeColor = .black
|
||||
|
||||
let rect = SKShapeNode(rect: CGRect(x: 10, y: 10, width: 100, height: 100))
|
||||
rect.strokeColor = .clear
|
||||
rect.fillColor = .red
|
||||
cells = (0..<(s.w * s.h)).map({ index in
|
||||
let piece = PieceNode()
|
||||
piece.intPosition = (x: index % s.w, y: index / s.w)
|
||||
piece.piece = switch(index % 3) {
|
||||
case 1: .init(withOwner: .player1)
|
||||
case 2: .init(withOwner: .player2)
|
||||
default: .init(withOwner: .noOne)
|
||||
}
|
||||
return piece
|
||||
})
|
||||
|
||||
super.init(size: CGSize(width: gWidth, height: gHeight))
|
||||
|
||||
addChild(rect)
|
||||
// anchorPoint = CGPoint(x: 0.5, y: 0.5)
|
||||
|
||||
addChild(boardNode)
|
||||
for cell in cells {
|
||||
addChild(cell)
|
||||
}
|
||||
}
|
||||
|
||||
public required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
fatalError("Unreachable")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
import Foundation
|
||||
import SpriteKit
|
||||
import Connect4Core
|
||||
|
||||
class PieceNode : SKNode {
|
||||
static let pieceSize: CGFloat = 100
|
||||
|
||||
private var circle: SKShapeNode
|
||||
|
||||
var piece: Piece = .init(withOwner: .noOne) {
|
||||
didSet {
|
||||
switch (piece.owner) {
|
||||
case .player1:
|
||||
circle.fillColor = .yellow
|
||||
circle.strokeColor = .orange
|
||||
case .player2:
|
||||
circle.fillColor = .red
|
||||
circle.strokeColor = .orange
|
||||
|
||||
default:
|
||||
circle.fillColor = .lightGray
|
||||
circle.strokeColor = .clear
|
||||
}
|
||||
}
|
||||
}
|
||||
var intPosition: (x: Int, y: Int) = (0, 0) {
|
||||
didSet {
|
||||
position = CGPoint(
|
||||
x: CGFloat(intPosition.x) * Self.pieceSize + Self.pieceSize / 2,
|
||||
y: CGFloat(intPosition.y) * Self.pieceSize + Self.pieceSize / 2
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override init() {
|
||||
circle = SKShapeNode(circleOfRadius: Self.pieceSize / 2 * 0.90)
|
||||
|
||||
super.init()
|
||||
|
||||
addChild(circle)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
enum PlayerType: CaseIterable, Identifiable {
|
||||
var id: Self { self }
|
||||
|
||||
case Human, AIRandom, AIFinnishHim, AISimpleNegaMax
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
import Foundation
|
||||
|
||||
class InGameVM: ObservableObject {
|
||||
|
||||
}
|
Loading…
Reference in new issue