-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard_class.cpp
More file actions
50 lines (50 loc) · 1.41 KB
/
Copy pathboard_class.cpp
File metadata and controls
50 lines (50 loc) · 1.41 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
#include "board_class.h"
#include "snake_class.h"
#include "food_class.h"
#include<iostream>
Board::Board(int width , int height)
{
this->width = width ;
this->height = height;
}
void Board :: Draw(const Snake &snake , const Food & food , int score , int level)
{
std::cout << "\033[H";
for(int y = 0 ; y < height ; y += 1 )
{
for(int x = 0 ; x < width ; x+=1 )
{
if (y == 0 || y == height - 1 || x == 0 || x == width - 1)
{
std::cout << "#";
}
else if (y == food.GetX() && x == food.GetY())
{
std::cout << "*";
}
else {
bool printedSnake = false;
for (auto segment : snake.getBody())
{
if (segment.first == y && segment.second == x) {
std::cout << "o";
printedSnake = true;
break;
}
}
if (!printedSnake) std::cout << " ";
}
}
std::cout << "\n";
}
std::cout << "Score: " << score<<"\n";
}
bool Board :: Check_collision(const Snake &snake)
{
auto head = snake.getBody().back();
if (head.first <= 0 || head.first >= height - 1 ||
head.second <= 0 || head.second >= width - 1) {
return true;
}
return false;
}