-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.cpp
68 lines (59 loc) · 1.07 KB
/
main.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unistd.h>
#include <bits/stdc++.h>
#include "input.h"
#include "snake.h"
#include "snake_map.h"
#include <utility>
#include "macros.h"
using namespace std;
Snake snake;
SnakeMap snake_map(&snake);
void initialize()
{
input_init();
input_enter_off();
}
bool is_game_end()
{
bool result = false;
pair<int, int> snake_head = snake.snake_head;
if (snake_head.first < 0 || snake_head.first >= MAP_HEIGHT || snake_head.second < 0 || snake_head.second >= MAP_WIDTH)
{
result = true;
}
if (snake.is_dead)
{
result = true;
}
return result;
}
void game_over()
{
cout << "GAME IS OVER" << endl;
}
void start_game()
{
while (true)
{
snake.update_movement();
if (is_game_end())
{
game_over();
break;
}
snake_map.redraw();
usleep(PAUSE_LENGTH);
snake.validate_direction();
}
}
int main()
{
initialize();
start_game();
return 0;
}