-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.cpp
More file actions
40 lines (37 loc) · 756 Bytes
/
grid.cpp
File metadata and controls
40 lines (37 loc) · 756 Bytes
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
//grid.cpp
//Michael Griffith
//Project 06
#include"grid.h"
#include<iostream>
#include<cassert>
//Default constructor
Grid::Grid()
{
grid_array = new char*[24]; //Initialilze 24 rows
for(int i(0); i<24; i++)
*(grid_array+i) = new char[60]{}; //Initialize 60 chars per each row
for(int i(0); i<24; i++)
{
for(int j(0); j<60; j++)
{
grid_array[i][j] = ' '; //Set all chars to ' '
}
}
}
void Grid::print()
{
for(int i(0); i<24; i++)
{
for (int j(0); j<60; j++)
{
std::cout << *(*(grid_array+i)+j);
}
std::cout << "\n";
}
}
void Grid::set(int x, int y, char put)
{
if(x < 0 || x > 59) return; //Sets boundaries
if(y < 0 || y > 23) return; //Avoids Seg faults.
*(*(grid_array+y)+x) = put;
}