-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlansza.cpp
106 lines (96 loc) · 2.06 KB
/
Plansza.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
#include "Plansza.h"
Plansza::Plansza()
{
// Tablica domyślna 10x10
this->ekran = new int [100];
this->szer = 10;
this->wys = 10;
}
Plansza::~Plansza()
{
delete ekran;
}
Plansza::Plansza(int m,int n)
{
this->ekran = new int [m*n];
this->szer = m;
this->wys = n;
}
void Plansza::Wyswietl()
{
int pol = this->szer * this->wys;
for (int j = 0; j < this->Wysokosc(); j++)
{
for (int i = 0; i < this->Szerokosc(); i++)
{
std::cout << Plansza::KOLOR[this->Get(i, j)];
}
std::cout << "\n";
}
}
int Plansza::Szerokosc()
{
return this->szer;
}
int Plansza::Wysokosc()
{
return this->wys;
}
void Plansza::Set(int x, int y, int k)
{
int pos;
if ((x+1) > this->szer || (y+1) > this->wys)
std::cout << "OUT OF RANGE!";
else
{
pos = (y*this->szer) + x;
this->ekran[pos] = k;
}
}
int Plansza::Get(int x,int y)
{
if ((x+1) > this->szer || (y+1) > this->wys || x < 0 || y < 0)
{
return 0;
}
return this->ekran[(y*this->szer) + x];
}
/**
* Zwraca ilość sąsiadów dookoła punktu (x,y), których wartości zawierają się w 'od_'..'do_'
*/
int Plansza::liczSasiadow(int x, int y, int od_, int do_)
{
int suma = 0;
for (int i = x-1; i <= x+1; i++)
{
for (int j = y-1; j <= y +1; j++)
{
if ( (i != x || j != y) && (this->Get(i,j) >= od_ && this->Get(i,j) <= do_))
{
suma++;
}
}
}
return suma;
}
/**
* Zwraca ilość sąsiadów dookoła punktu (x,y), których wartości są równe 'rowne'
*/
int Plansza::liczSasiadow(int x, int y, int rowne)
{
return this->liczSasiadow(x, y, rowne, rowne);
}
int Plansza::sumaStanow(int x, int y)
{
int suma = 0;
for (int i = x-1; i <= x+1; i++)
{
for (int j = y-1; j <= y +1; j++)
{
int test;
//std::cout << "\n [ " << suma << " " << this->Get(i,j) << " " << i << " " << j << " ] \n";
suma += this->Get(i,j);
}
}
return suma;
}