-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile.php
54 lines (46 loc) · 1.25 KB
/
tile.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
<?php
class Tile {
const USE_ANSI = true;
private static $allTiles;
public static function allTiles() {
if (!self::$allTiles) {
self::$allTiles = [];
foreach (Color::colors() as $color) {
foreach (Shape::shapes() as $shape) {
$tile = new Tile($color, $shape);
self::$allTiles[] = $tile;
self::$allTiles[] = $tile;
self::$allTiles[] = $tile;
}
}
}
return self::$allTiles;
}
public static function get(Color $color, Shape $shape) {
foreach (self::allTiles() as $tile) {
if ($tile->color() === $color && $tile->shape() === $shape) {
return $tile;
}
}
}
public function __construct(Color $color, Shape $shape) {
$this->color = $color;
$this->shape = $shape;
}
public function color() {
return $this->color;
}
public function shape() {
return $this->shape;
}
public function __toString() {
if (self::USE_ANSI) {
$colorString = Color::ANSI_BACKGROUND . $this->color()->ansi();
$closeColorString = "\e[0m" /* turn off previous escape codes */;
} else {
$colorString = "{$this->color()}";
$closeColorString = '';
}
return "{$colorString}{$this->shape()}{$closeColorString}";
}
}