feat: add first loose condition
This commit is contained in:
23
src/game.zig
23
src/game.zig
@@ -73,6 +73,12 @@ const Game = struct {
|
||||
}
|
||||
|
||||
const newHead = self.body.items[0] + self.direction.vector();
|
||||
if (newHead[0] == 0 or newHead[0] == self.playFieldSize[0] or
|
||||
newHead[1] == 0 or newHead[1] == self.playFieldSize[1])
|
||||
{
|
||||
self.state = State.lost;
|
||||
return;
|
||||
}
|
||||
try self.body.insert(0, newHead);
|
||||
_ = self.body.pop();
|
||||
}
|
||||
@@ -116,7 +122,22 @@ test "should not be able to change direction to the previous position" {
|
||||
try testing.expectEqual(Direction.right, game.direction);
|
||||
}
|
||||
|
||||
test "should loose if exiting playField" {}
|
||||
test "should loose if exiting playField right" {
|
||||
const allocator = testing.allocator;
|
||||
|
||||
var game = try Game.create(allocator);
|
||||
defer game.deinit();
|
||||
|
||||
for (0..10) |_| {
|
||||
try game.tick();
|
||||
}
|
||||
|
||||
const expected = [_]Vec2{ Vec2{ 19, 10 }, Vec2{ 18, 10 }, Vec2{ 17, 10 } };
|
||||
try testing.expectEqualSlices(Vec2, &expected, game.body.items);
|
||||
|
||||
try testing.expectEqual(State.lost, game.state);
|
||||
}
|
||||
|
||||
test "should loose if eating itself" {}
|
||||
test "should grow if eating food" {}
|
||||
test "should win if no space is left" {}
|
||||
|
||||
Reference in New Issue
Block a user