forked from serpentinok17/serpentino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildMap.cpp
63 lines (50 loc) · 1.4 KB
/
BuildMap.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
#include <iostream>
#include <conio.h>
#include <stdlib.h>
// Map dimensions
const int MAP_WIDTH = 20;
const int MAP_LENGTH = 40;
const int MAP_SIZE = MAP_WIDTH * MAP_LENGTH;
// Map array
int Map[MAP_SIZE];
// Returns graphical character for display from map value
char getMapValue(int value)
{
switch (value) {
// Return vertical wall
case -1: return '|';
// Return honrizontal wall
case -2: return '-';
}
// Print the map
void printMap()
{
for (int x = 0; x < MAP_WIDTH; ++x) {
for (int y = 0; y < MAP_LENGTH; ++y) {
// Prints the value at current x,y location
std::cout << getMapValue(Map[x + y * MAP_WIDTH]);
}
// Newline
std::cout << std::endl;
}
}
// Initialize the map and snake position
void initialMap()
{
// Places the initial head location in middle of map
headxpos = MAP_WIDTH / 2;
headypos = MAP_LENGTH / 2;
Map[headxpos + headypos * MAP_WIDTH] = 1;
// Places left and right walls
for (int x = 0; x < MAP_WIDTH; ++x) {
Map[x] = -1;
Map[x + (MAP_LENGTH - 1) * MAP_WIDTH] = -1;
}
// Places top and bottom walls
for (int y = 0; y < MAP_LENGTH; y++) {
Map[0 + y * MAP_WIDTH] = -2;
Map[(MAP_WIDTH - 1) + y * MAP_WIDTH] = -2;
}
// Generates first food
generateFood();
}