Skip to content

Commit d4044ef

Browse files
committed
Initialize snake with a length of 4 and remove heal method
1 parent 70e4e3d commit d4044ef

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

Snake/Snake.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55

66
Snake::Snake(int startX, int startY) {
77
head = new Node(startX, startY);
8-
tail = head;
9-
length = 1;
8+
NodePtr current = head;
9+
10+
for (int i = 1; i < 4; ++i) {
11+
NodePtr newNode = new Node(startX - i, startY);
12+
current->next = newNode;
13+
current = newNode;
14+
}
15+
16+
tail = current;
17+
length = 4;
1018
collisionCount = 0;
11-
dx = 1; dy = 0; // Initial direction to the right
19+
dx = 1; dy = 0;
1220
}
1321

1422
void Snake::move() {
@@ -35,12 +43,6 @@ void Snake::grow() {
3543
length++;
3644
}
3745

38-
void Snake::heal() {
39-
if (collisionCount > 0) {
40-
collisionCount--;
41-
}
42-
}
43-
4446
void Snake::changeDirectionOnCollision(int& dx, int& dy) {
4547
// Change the direction of the snake when it collides with itself
4648
if (dx == 1) {
@@ -147,4 +149,4 @@ void Snake::setDirection(int dx, int dy) {
147149
}
148150
this->dx = dx;
149151
this->dy = dy;
150-
}
152+
}

Snake/Snake.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class Snake {
2020
Snake(int startX, int startY);
2121
void move();
2222
void grow();
23-
void heal();
2423
bool checkSelfCollision();
2524
void checkWallCollision();
2625
void changeDirectionOnCollision(int& dx, int& dy);

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int main(int argc, char** argv) {
9696
while (!glfwWindowShouldClose(window)) {
9797
glClear(GL_COLOR_BUFFER_BIT);
9898

99-
renderText(0.0f, 2.0f, "Score: " + std::to_string(snake.getLength() - 1));
99+
renderText(0.0f, 2.0f, "Score: " + std::to_string(snake.getLength() - 4));
100100
renderText(0.0f, 6.0f, "Health:");
101101

102102
// Calculate health percentage (assuming max health is 3)

0 commit comments

Comments
 (0)