Skip to content

Commit

Permalink
Feat: improve object-oriented game design.
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarchevskyi committed Apr 7, 2024
1 parent 30e1c08 commit c0eaf6e
Show file tree
Hide file tree
Showing 23 changed files with 695 additions and 538 deletions.
4 changes: 2 additions & 2 deletions src/Controllers/ConsoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct()
#[\Override] protected function getX(): int
{
do {
$xSize = $this->view->getX();
$xSize = $this->view->getFieldXSize();
} while (!is_numeric($xSize) || $xSize <= 0);

return intval($xSize);
Expand All @@ -68,7 +68,7 @@ public function __construct()
#[\Override] protected function getY(): int
{
do {
$ySize = $this->view->getY();
$ySize = $this->view->getFieldYSize();
} while (!is_numeric($ySize) || $ySize <= 0);

return intval($ySize);
Expand Down
10 changes: 1 addition & 9 deletions src/Models/AbstractGame/Cells/AbstractCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

abstract class AbstractCell
{
protected bool $alive;

protected int $x;

protected int $y;

public function __construct(bool $alive, int $x, int $y)
public function __construct(int $x, int $y)
{
$this->alive = $alive;
$this->x = $x;
$this->y = $y;
}
Expand All @@ -30,9 +27,4 @@ public function getY(): int
{
return $this->y;
}

public function isAlive(): bool
{
return $this->alive;
}
}
4 changes: 3 additions & 1 deletion src/Models/AbstractGame/Fields/AbstractField.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ abstract class AbstractField

protected const int START_Y = 0;

protected const array CELLS = [];

protected readonly int $xSize;

protected readonly int $ySize;
Expand Down Expand Up @@ -105,7 +107,7 @@ public function calculateStep(int $step): void
* @param int $y
* @return array<AbstractCell>
*/
protected function getNeighborhoods(int $x, int $y): array
public function getNeighborhoods(int $x, int $y): array
{
return $this->connectBorders
? $this->getNeighborsOnConnectedBoard($x, $y)
Expand Down
113 changes: 0 additions & 113 deletions src/Models/Cells/ForestCell.php

This file was deleted.

18 changes: 0 additions & 18 deletions src/Models/CellsTypes/ForestCellTypes.php

This file was deleted.

14 changes: 14 additions & 0 deletions src/Models/ConwaysGame/Cells/AbstractConwaysCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,19 @@

abstract class AbstractConwaysCell extends AbstractCell
{
protected bool $alive;

public function __construct(bool $alive, int $x, int $y)
{
parent::__construct($x, $y);

$this->alive = $alive;
}

abstract public function getNextMoveCell(int $neighborsCount): AbstractConwaysCell;

public function isAlive(): bool
{
return $this->alive;
}
}
Loading

0 comments on commit c0eaf6e

Please sign in to comment.