-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (48 loc) · 1.93 KB
/
main.cpp
File metadata and controls
54 lines (48 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include "Board.h"
#include "Snake.h"
#include <unistd.h>
#include <unistd.h>
int main() {
std::cout << "Starting game!" << std::endl;
Board board = Board(16, 35);
Snake &snake = board.getSnake();
while (true) { // game loop
board.getInput();
if (snake.CanMove()) {
snake.move();
board.activateDioItem(); // try to activate dio item
}
board.checkAppleEngage(); // check if the snake engaged the apple
board.checkDioEngage(); // check if the snake engaged the Dio item
board.draw(); // draw the state of the game
if (board.snakeCollided()) {
usleep(300000); // delay for 300 ms to make snake collision detectable
break;
}
board.isDioEffect() ? usleep(250000) : usleep(110000); /* delay for 110 ms. if you wonder why 110 ms:
https://github.com/romanedgn/snake-game/blob/master/fSnakeGame.cpp */
}
board.endGame();
std::cout << R"(
_______ _______ _______ _______
( ____ \( ___ )( )( ____ \
| ( \/| ( ) || () () || ( \/
| | | (___) || || || || (__
| | ____ | ___ || |(_)| || __)
| | \_ )| ( ) || | | || (
| (___) || ) ( || ) ( || (____/\
(_______)|/ \||/ \|(_______/
_______ _______ _______
( ___ )|\ /|( ____ \( ____ )
| ( ) || ) ( || ( \/| ( )|
| | | || | | || (__ | (____)|
| | | |( ( ) )| __) | __)
| | | | \ \_/ / | ( | (\ (
| (___) | \ / | (____/\| ) \ \__
(_______) \_/ (_______/|/ \__/
)";
std::cout << "Press the Enter key to exit..." << std::endl;
getchar();
return 0;
}