IAS/incTron/Coords.php

40 lines
839 B
PHP
Raw Normal View History

2016-11-10 21:34:06 +01:00
<?php
class Coords{
private static $min = 0;
2016-11-29 18:50:56 +01:00
private static $max = 99;
2016-11-10 21:34:06 +01:00
public $x;
public $y;
public function __construct(int $x = 0, int $y = 0) {
2016-11-21 16:15:13 +01:00
2016-11-10 21:34:06 +01:00
if (($x < Coords::$min) || ($x > Coords::$max) || ($y < Coords::$min) || ($y > Coords::$max)){
//out of limits
error_log("a bot out of limits");
return false;
}
$this->x = $x;
$this->y = $y;
}
public function __toString(){
return $this->x.",".$this->y;
}
public function addDirection(Direction $dir){
2016-11-21 16:15:13 +01:00
if (
($this->x + $dir->deltaX > Coords::$max)
|| ($this->x + $dir->deltaX < Coords::$min)
|| ($this->y + $dir->deltaY > Coords::$max)
|| ($this->y + $dir->deltaY < Coords::$min)
){
return false;
}
2016-11-10 21:34:06 +01:00
return new Coords(
$this->x + $dir->deltaX,
$this->y + $dir->deltaY
);
}
}