A CLI based implementation of the famous Nokia Snake game written entirely in C++.
It is a console based game with upto four players allowed.
For the project, I used the following structs:
struct Pos {
int x;
int y;
};
struct Food {
Pos pos;
int color;
char sym;
int size;
bool eaten;
};
struct Snake {
Pos p[MAXLENGTH], tail;
int size, color, speed, score, dir, UP, DOWN, LEFT, RIGHT;
bool alive;
string name;
};
NOTE: Each snake is simply an array of positions. On every frame, we remove the last index of that array and add a new one on the head.
struct Obstacle {
Pos** cord;
int xsize, ysize, color;
char sym;
};
The following rules apply to each player:
- Each player can move in any of the four directions (up, left , down, right).
- Each player must avoid hitting obstacles or else they are eliminated.
- Each player must avoid hitting other players or else they are eliminated.
- Each player must avoid hitting themselves or else they are eliminated.
- Each player grows 1 bit by eating the yellow food.
- Each player grows 5 bits by eating the green food.
- Each player grows 10 bits by eating the red food.
- The game progressively gets faster.
- There are three levels, each with higher difficulty than the previous one.
- Player with the highest score at the end score wins the game.
Player 1 I, J, K, L
Player 2 W, A, S, D
Player 3 G, V, B, N
Player 4 ARROW UP, ARROW LEFT, ARROW DOWN, ARROW RIGHT