-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay.php
50 lines (40 loc) · 1.16 KB
/
Display.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
<?php
class Display
{
private $intToSymbols = [
1 => ['nothing', 'right', 'nothing', 'right', 'nothing'],
2 => ['line', 'right', 'line', 'left', 'line'],
4 => ['nothing', 'borders', 'line', 'right', 'nothing'],
];
public function draw($number)
{
$digits = [];
foreach (str_split($number) as $i => $intDigit) {
$digits[$i] = $this->drawDigit($intDigit);
}
$results = $this->enqueueDigitsStings($digits);
return $results;
}
private function drawDigit($intDigit)
{
$symbols = [];
foreach ($this->intToSymbols[$intDigit] as $singleSymbol) {
$className = ucfirst(strtolower($singleSymbol));
$symbol = new $className();
foreach ($symbol->draw() as $s) {
$symbols[] = $s;
}
}
return $symbols;
}
private function enqueueDigitsStings($digits)
{
$results = [];
for ($line = 0; $line < 7; $line++) {
for ($i = 0; $i < count($digits); $i++) {
$results[] = $digits[$i][$line];
}
}
return $results;
}
}