-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.php
59 lines (47 loc) · 1.36 KB
/
Grid.php
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
<?php
class Grid {
public $cols;
public $rows;
public $cells;
public function __construct($cols, $rows) {
$this->cols = $cols;
$this->rows = $rows;
$this->cells = array();
for ($i = 0; $i < $this->cols; $i++) {
for ($j = 0; $j < $this->rows; $j++) {
$this->cells[$i][$j] = 0;
}
}
}
public function generateCells() {
for ($i = 0; $i < $this->cols; $i++) {
for ($j = 0; $j < $this->rows; $j++) {
$this->cells[$i][$j] = rand(0, 1);
}
}
return $this;
}
public function createCanvas($header) {
echo '<strong>' . $header . '</strong><br><br>';
for ($i = 0; $i < $this->cols; $i++) {
for ($j = 0; $j < $this->rows; $j++) {
$mark = $this->cells[$i][$j] == 1 ? '*' : '-';
echo ' ' . $mark . ' ';
}
echo '<br>';
}
echo '<br><br>';
}
public function getCell($x, $y) {
return $this->cells[$x][$y];
}
public function setCell($x, $y, $value) {
$this->cells[$x][$y] = $value;
}
public function getCols() {
return $this->cols;
}
public function getRows() {
return $this->rows;
}
}