-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.php
More file actions
58 lines (45 loc) · 1.12 KB
/
App.php
File metadata and controls
58 lines (45 loc) · 1.12 KB
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
<?php
declare(strict_types=1);
namespace Ardillo\Examples\Snake;
use Ardillo\Examples\Snake\Main\{
Handler,
Window,
};
use Ardillo\{
ReactApp,
Size,
TimedTask,
};
class App extends ReactApp
{
public Window $win;
protected TimedTask $timer;
public function stopDrawing(): void
{
if (isset($this->timer)) {
$this->loop->cancelTimer($this->timer);
}
}
public function onSigInt(int $signo): void
{
echo 'Caught SIGINT ...' . PHP_EOL;
$this->stopDrawing();
unset($this->win);
$this->stop();
}
protected function OnInit(): void
{
$this->win = new Window(
'Press <space> to start',
new Size(Handler::GAME_AREA_WIDTH, Handler::GAME_AREA_HEIGHT),
false
);
$this->win->setup();
$this->win->show();
$this->timer = $this->loop->addPeriodicTimer(1 / 2, function () {
$this->win->handler->moveSnake();
$this->win->area->queueRedrawAll();
});
$this->loop->addSignal(self::SIGINT, $this->onSigInt(...));
}
}