-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.cpp
69 lines (60 loc) · 1.12 KB
/
grid.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
#include<iostream>
#include <ctime>
//#include <stdio.h>
#include <iomanip>
#include "grid.hpp"
using std::cout;
using std::cin;
using std::endl;
Grid::Grid()
{
field = NULL;
}
Grid::Grid(int x, int y)
{
fill = '-';
critter = 'C';
x_sz = x;
y_sz = y;
curr_x = 0;
curr_y = 0;
field = new char *[x_sz];
for (int i = 0; i < x_sz; i++)
field[i] = new char[y_sz];
for (int i=0; i < x_sz; i++)
{
for (int j=0; j < y_sz; j++)
{
field[i][j] = fill;
}
}
}
Grid::~Grid(){
for (int i=0; i < x_sz; i++)
delete [] field[i];
delete [] field;
}
void Grid::printGrid()
{
cout << "\n";
for (int i=0; i < x_sz; i++)
{
for (int j=0; j < y_sz; j++)
{
cout << field[i][j] << " ";
}
cout << "\n";
}
}
void Grid::updateLocation(int x, int y)
{
//save old position to reinitialize
int old_x = curr_x;
int old_y = curr_y;
curr_x = x;
curr_y = y;
//redash old location on grid
field[old_x][old_y] = fill;
//draw new bug on new location
field[x][y] = critter;
}