-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisuals.h
87 lines (72 loc) · 2.45 KB
/
visuals.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#include <iostream>
#include "snek.h"
// #include "frut.h"
namespace visuals
{
void draw(snekGame::Snek S, snekGame::Frut F)
{
// the improvisation relies on the cmd clearing, so that's the big boy here
std::system("cls");
bool print;
// top line
std::cout << " ";
for (unsigned i = 0; i < snekGame::dimension; i++)
std::cout << "#";
std::cout << "\n";
// Game canvas and side walls
for (unsigned j = 0; j < snekGame::dimension; j++)
{
std::cout << "!";
for (unsigned i = 0; i < snekGame::dimension; i++)
{
print = true;
// this for is the snek's body
for (unsigned k = 0; k < S.posTail.size(); k++)
{
if (i == S.posTail.at(k).first && j == S.posTail.at(k).second)
{
if (k == 0)
{
std::cout << "S";
print = false;
}
else if (k == 1)
{
std::cout << "n";
print = false;
}
else if (k < S.posTail.size() - 1)
{
std::cout << "e";
print = false;
}
else
{
std::cout << "k";
print = false;
}
}
}
if (i == F.pos.first && j == F.pos.second)
{
std::cout << "0";
print = false;
}
if (print == true)
std::cout << " ";
}
std::cout << "!";
std::cout << "\n";
}
// bottom line
std::cout << ' ';
for (unsigned i = 0; i < snekGame::dimension; i++)
std::cout << "#";
std::cout << " \n";
// here for debug reasons: displays the snake coordinates
// for (int k = 0; k < S.posTail.size(); k++)
// std::cout << k << ": " << S.posTail.at(k).first <<", "<< S.posTail.at(k).second << "\n";
// std::cout << "\n------------------------------\n";
}
}