Skip to content

Instantly share code, notes, and snippets.

@davit
Last active December 13, 2015 17:58
Show Gist options
  • Save davit/4951974 to your computer and use it in GitHub Desktop.
Save davit/4951974 to your computer and use it in GitHub Desktop.
<?php
class Figure // Chessboard - Rook coordinates and its motion:
{
private $x, $y;
// setting initial position of the Rook:
public function SetCoords($absc, $oord) {
if (($absc>=1 and $absc<=8) and ($oord>=1 and $oord<=8)) {
$this->x = $absc;
$this->y = $oord;
}
else echo "Coordinates out of range! The piece would fall off the board!";
}
// print current coordinates:
public function printcords(){
echo "\n<b>X Coordinate</b>: ".$this->x ."<b> Y Coordinate</b>: ".$this->y;
}
// Rook motion:
public function move($a, $b) {
if (($a>=1 and $a<=8) and ($b>=1 and $b<=8)) {
if ($a <> $this->x and $b <> $this->y)
echo "At least one of two new coordinates should be the same as old one
for the Rook to make a move!";
else if ($a = $this->x)
$this->y += abs($this->y = $b);
else
$this->x += abs($this->x - $a);
}
else echo "Out of range. Your piece fell of the board lol!";
}
}
$obj = new Figure();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment