-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.cpp
82 lines (69 loc) · 2.06 KB
/
map.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <unistd.h>
#include <iostream>
#include "utilities.h"
#include <cstring>
#include "map.h"
#include "Snake.h"
#include "Main.h"
using namespace std;
std::string yellow = "\e[1;33m";
std::string green = "\033[0;32m";
std::string white = "\e[0;97m";
std::string bold = "\e[1m";
std::string reset = "\e[0m";
std::string lightgray = "\e[0;37m";
std::string map [mapSize][mapSize];
std::pair <int, int> food [amountOfFood];
string printout;
void setTile (int x, int y, std::string c) {
if (x < mapSize && y < mapSize) {
map[x][y] = c;
}
}
bool foodTilesCreated = false;
void initMap () {
if (!foodTilesCreated && network.isServer) {
for (int i = 0; i < ARRAY_SIZE(food); i ++) {
int rx = random(0, ARRAY_SIZE(map)); // Create new random positions for the food
int ry = random(0, ARRAY_SIZE(map[0]));
food[i].first = rx; // Set them
food[i].second = ry;
}
foodTilesCreated = true;
}
for (int y = 0; y < ARRAY_SIZE(map[0]); y ++) {
for (int x = 0; x < ARRAY_SIZE(map); x ++) {
if (x % 4 == 0 && y % 4 == 0) {
setTile(x, y, "`");
} else {
setTile(x, y, " ");
}
}
}
for (int i = 0; i < ARRAY_SIZE(food); i ++) {
setTile(food[i].first, food[i].second, bold + yellow + "&" + reset); // Change the tile at the food positions to &
}
}
void clearScreen () {
printf("\033c"); // Clears the screen to make way for a new frame
}
void printMap () {
// Loops through the 2D array map, n prints the character contained at that index
for (int y = 0; y < ARRAY_SIZE(map[0]); y ++) {
for (int x = 0; x < ARRAY_SIZE(map); x ++) {
std::cout << map[x][y] << " ";
}
printf("\n");
}
}
void log (string s) {
printout = s + "\n";
}
void spamLog (string s) {
printout += s + "\n";
}
void printStat () {
printf("Press \"q\" to quit.\n");
printf("You have a score of: %d \n", (int)snake.score);
printf("\n%s \n", printout.c_str());
}