aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/main.cpp b/main.cpp
index 148ae62..58a6f3e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -213,7 +213,7 @@ class Snake {
mUnoccupy(mApple.x, mApple.y);
mOccupy(NewApple.x, NewApple.y);
- mApple = {mUnoccupied[iPos].x, mUnoccupied[iPos].y, mApple.appearance};
+ mApple = {NewApple.x, NewApple.y, mApple.appearance};
}
std::tuple<int, int> mGetDirectionOffset(char c) {
@@ -232,7 +232,7 @@ class Snake {
return std::tuple<int, int>(0, 0);
}
- bool mProcessApple(int &PotentialX, int &PotentialY) {
+ bool mProcessApple(const int &PotentialX, const int &PotentialY) {
if (mApple.x == PotentialX && mApple.y == PotentialY) {
mAddApple();
return true;
@@ -256,6 +256,11 @@ class Snake {
}
}
+ void mPushSnakeFront(mSnakeUnit input) {
+ mOccupy(input.x, input.y);
+ mSnake.push_front(input);
+ }
+
mSnakeUnit mPopSnake() {
mSnakeUnit tr = mSnake.front();
mCell val(tr.x, tr.y);
@@ -274,6 +279,7 @@ class Snake {
void mAdvanceSnake(int &PotentialX, int &PotentialY) {
mPushSnake({PotentialX, PotentialY, HEAD_ARROWS.at(mSnakeDirection)});
+
mSnake[mSnake.size() - 2].appearance = mGetTurningCharacter(
mSnake[mSnake.size() - 3], mSnake[mSnake.size() - 2],
mSnake[mSnake.size() - 1]);
@@ -287,17 +293,21 @@ class Snake {
bool AteApple = mProcessApple(PotentialX, PotentialY);
+ if (!AteApple) {
+ mLastDequeued = mPopSnake();
+ }
+
bool DeathTicked = mCheckDeathTick(PotentialX, PotentialY);
if (!DeathTicked) {
- mGraceFrames = mGraceFrames + 1 >= GRACE_FRAMES ? GRACE_FRAMES
- : mGraceFrames + 1;
- mAdvanceSnake(PotentialX, PotentialY);
+ if (mGraceFrames + 1 >= GRACE_FRAMES)
+ mGraceFrames = GRACE_FRAMES;
+ else
+ mGraceFrames++;
- if (!AteApple) {
- mLastDequeued = mPopSnake();
- }
+ mAdvanceSnake(PotentialX, PotentialY);
} else {
+ mPushSnakeFront(mLastDequeued);
mSnake.back().appearance = HEAD_ARROWS.at(mSnakeDirection);
mLastDequeued = mSnakeUnit(-1, -1, " ");
}