Skip to content

Commit 667675f

Browse files
Refactor
1 parent bf2ce56 commit 667675f

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

tictactoe Shared/GameScene.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,21 @@ class GameScene: SKScene {
7575
drawBoard()
7676
}
7777

78+
@inline(never)
7879
fileprivate func drawBoard() {
7980
let cellSize = min(size.width, size.height) / CGFloat(boardSize)
8081
let offset = -cellSize * CGFloat(boardSize) / 2
81-
board = (0..<boardSize).map { _ in Array(repeating: nil, count: boardSize) }
82+
board = Array(repeating: Array(repeating: nil, count: boardSize), count: boardSize)
8283

83-
for i in 0..<(boardSize * boardSize) {
84-
let row = i / boardSize
85-
let col = i % boardSize
84+
(0..<boardSize * boardSize).forEach { i in
8685
let cell = SKSpriteNode(color: GameColor.gray, size: CGSize(width: cellSize - 10, height: cellSize - 10))
87-
88-
// Explicit CGFloat conversion for col and row
89-
cell.position = CGPoint(x: offset + (CGFloat(col) + 0.5) * cellSize,
90-
y: offset + (CGFloat(row) + 0.5) * cellSize)
91-
92-
cell.name = "\(row)-\(col)"
86+
cell.position = CGPoint(
87+
x: offset + (CGFloat(i % boardSize) + 0.5) * cellSize,
88+
y: offset + (CGFloat(i / boardSize) + 0.5) * cellSize
89+
)
90+
cell.name = "\(i / boardSize)-\(i % boardSize)"
9391
addChild(cell)
94-
board[row][col] = cell
92+
board[i / boardSize][i % boardSize] = cell
9593
}
9694
}
9795

0 commit comments

Comments
 (0)