advent_of_code_2019/day_12/Moon.php

140 lines
2.4 KiB
PHP

<?php
class Moon
{
/** @var int */
protected $x;
/** @var int */
protected $y;
/** @var int */
protected $z;
/** @var string[] */
protected $history = [];
/**
* @var Velocity
*/
protected $velocity;
/**
* Moon constructor.
* @param int $x
* @param int $y
* @param int $z
*/
public function __construct(int $x, int $y, int $z)
{
$this->x = $x;
$this->y = $y;
$this->z = $z;
$this->addHistory(sprintf('%s,%s,%s,0,0,0', $this->getX(), $this->getY(), $this->getZ()));
$this->velocity = new Velocity(0,0,0);
}
/**
* @return int
*/
public function getX(): int
{
return $this->x;
}
/**
* @param int $x
* @return Moon
*/
public function setX(int $x): Moon
{
$this->x = $x;
return $this;
}
/**
* @return int
*/
public function getY(): int
{
return $this->y;
}
/**
* @param int $y
* @return Moon
*/
public function setY(int $y): Moon
{
$this->y = $y;
return $this;
}
/**
* @return int
*/
public function getZ(): int
{
return $this->z;
}
/**
* @param int $z
* @return Moon
*/
public function setZ(int $z): Moon
{
$this->z = $z;
return $this;
}
/**
* @return Velocity
*/
public function getVelocity(): Velocity
{
return $this->velocity;
}
/**
* @param Velocity $velocity
* @return Moon
*/
public function setVelocity(Velocity $velocity): Moon
{
$this->velocity = $velocity;
return $this;
}
/**
* @return string[]
*/
public function getHistory(): array
{
return $this->history;
}
/**
* @param string $history
* @return Moon
*/
public function addHistory($history): Moon
{
$this->history[] = $history;
return $this;
}
public function saveHistory()
{
$velocity = $this->getVelocity();
$this->history[] = sprintf(
'%s,%s,%s,%s,%s,%s',
$this->getX(),
$this->getY(),
$this->getZ(),
$velocity->getX(),
$velocity->getY(),
$velocity->getZ()
);
return $this;
}
}