feat: model battlefield terrain and movement costs
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace BattleForge\Domain;
|
||||
|
||||
final readonly class Position
|
||||
{
|
||||
public function __construct(
|
||||
public int $x,
|
||||
public int $y,
|
||||
) {
|
||||
}
|
||||
|
||||
public function key(): string
|
||||
{
|
||||
return $this->x . ':' . $this->y;
|
||||
}
|
||||
|
||||
public function distanceTo(self $position): int
|
||||
{
|
||||
return abs($this->x - $position->x) + abs($this->y - $position->y);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user