diff options
| author | roy <[email protected]> | 2026-07-14 08:38:17 +0300 |
|---|---|---|
| committer | roy <[email protected]> | 2026-07-14 08:38:17 +0300 |
| commit | b23def4b020d1475b1b4b848b65b81ca821abc16 (patch) | |
| tree | 2917337f981efff47dd25ef82cdbd51d05219afe | |
| parent | f5908ca581f6fe88ac5637982183aac5b7612f3a (diff) | |
| -rwxr-xr-x | main | bin | 511712 -> 512056 bytes | |||
| -rw-r--r-- | main.cpp | 26 |
2 files changed, 18 insertions, 8 deletions
| Binary files differ @@ -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, " "); } |
