-
Notifications
You must be signed in to change notification settings - Fork 0
/
View.cpp
131 lines (119 loc) · 1.95 KB
/
View.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include<iostream>
using namespace std;
#include "View.h"
View::View()
{
size = 11;
scale = 2;
origin = Cart_Point(0,0);
}
//checks if the object is within the display
bool View::get_subscripts(int &ix, int &iy, Cart_Point location)
{
ix = (location.x-origin.x)/scale;
iy = (location.y-origin.y)/scale;
if(ix <= size-1 && iy <= size-1 && ix >= 0 && iy >= 0)
{
return true;
}
else
{
cout << "An object is outside the display" << endl;
return false;
}
}
//clears the display
void View::clear()
{
for(int i = 0; i < 11; i++)
{
for(int j = 0; j < 11; j++)
{
grid[i][j][0] = '.';
grid[i][j][1] = ' ';
}
}
}
void View::plot(Game_Object* ptr)
{
int ix;
int iy;
if(get_subscripts(ix, iy, ptr->get_location()) == true)
{
if(grid[ix][iy][0] != '.')
{
grid[ix][iy][0] = '*';
grid[ix][iy][1] = ' ';
}
else
{
ptr->drawself(grid[ix][iy]);
}
}
}
void View::draw()
{
int printx = 0;
int printy = 20;
for(int j = 10; j >= -1; j--) // the rows
{
for(int i = -1; i < 11; i++) // the columns
{
//If it is the bottom row
if(j == -1)
{
if(i%2 == 0)
{
if(printx == 0)
{
cout << printx;
printx+=4;
cout << " ";
}
if(printx != 24)
{
cout << " ";
cout << printx;
printx+=4;
}
}
else
{
if(printx == 16||printx == 20)
cout << ' ';
else
cout << " ";
}
}
//If its an odd row first column
else if(i == -1)
{
if(j%2 == 0)
{
if (printy< 12)
{
cout << printy;
printy-=4;
cout << ' ';
}
else
{
cout << printy;
printy-=4;
}
}
else
{
cout << " ";
}
}
//puts the dots and spaces
else
{
cout << grid[i][j][0];
cout << grid[i][j][1];
}
}
cout << endl;
}
}