Skip to content

Commit 4815b06

Browse files
committed
Added checking borders
1 parent f1f0559 commit 4815b06

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

SnakeGame/GameModel.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,14 @@ class GameBrain {
164164
headPoint.x += direction.x
165165
headPoint.y += direction.y
166166

167-
let outX = self.headPoint.x == fRect.origin.x || self.headPoint.x == fRect.origin.x - side + fRect.width
168-
let outY = self.headPoint.y == fRect.origin.y || self.headPoint.y == fRect.origin.y - side + fRect.height
169-
170-
if outX || outY {
171-
//change it for the death
172-
setDefaults()
173-
}else{
174-
moveHead()
167+
for border in borders {
168+
169+
if border.rect().contains(headPoint) {
170+
print("U dead")
171+
}
175172
}
173+
174+
moveHead()
176175
}
177176

178177
private func moveHead() {

0 commit comments

Comments
 (0)