Skip to content

Commit

Permalink
rot ok
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent REY committed Apr 13, 2014
1 parent 5351036 commit 9659608
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 25 deletions.
41 changes: 27 additions & 14 deletions attlestar/Class/Fleet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,40 @@ private function _creatSpawnX($p) {
return (5);
}

private function _creatOrient($p) {
if ($p == 1)
return (1);
else if ($p == 2)
return (3);
else if ($p == 3)
return (2);
else if ($p == 4)
return (4);
}

function __construct(array $arg) {
if (array_key_exists('size', $arg) && array_key_exists('player', $arg))
{
$this->_player = $arg['player'];
while ($this->_size < $arg['size'])
{
$this->addShip(
new Ship (array('name' => "Crusader",
'pp' => 10,
'weapon' => new Weapon (array(
'lrange' => 50,
'mrange' => 25,
'srange' => 10,
'damage' => 10)),
'hp' => 20,
'movement' => 10,
'posx' => self::_creatSpawnY($this->_size),
'posy' => self::_creatSpawnX($arg['player']),
'sizex' => 1,
'sizey' => 4
)));
new Ship (array(
'name' => "Crusader",
'pp' => 10,
'weapon' => new Weapon (array(
'lrange' => 50,
'mrange' => 25,
'srange' => 10,
'damage' => 10)),
'hp' => 20,
'movement' => 10,
'orientation' => self::_creatOrient($arg['player']),
'posx' => self::_creatSpawnY($this->_size),
'posy' => self::_creatSpawnX($arg['player']),
'sizex' => 1,
'sizey' => 1
)));
$this->_size++;
}
}
Expand Down
57 changes: 51 additions & 6 deletions attlestar/Class/Highlight.Class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,77 @@
private $_mv;
private $_style;

public function __construct($ship, $status) {
public function __construct($ship, $status, $orientation) {
$this->_posx = $ship->getPosX();
$this->_posy = $ship->getPosY();
$this->_sizex = 1;
if ($status == "move")
{
$this->_sizey = 20;
if ($orientation == 1 || $orientation == 3)
{
$this->_sizey = 20;
$this->_sizex = 1;
}
if ($orientation == 3)
$this->_posy -= 20;
if ($orientation == 2 || $orientation == 4)
{
$this->_sizex = 20;
$this->_sizey = 1;
}
if ($orientation == 4)
$this->_posx -= 20;
$this->_type = 'highlight';
$this->_style = new Style (array('opacity' => 0.95,
'border' => '1px inset #424242',
'color' => '#D9D0D0',
'name' => 'highlight'
));
}
else
else if ($status == "fire")
{
$this->_type = 'fire';
$this->_style = new Style (array('opacity' => 0.95,
'border' => '1px inset #424242',
'color' => '#D17C21',
'name' => 'fire'
));
$this->_sizey = 30;
if ($orientation == 1 || $orientation == 3)
{
$this->_sizey = 30;
$this->_sizex = 1;
}
if ($orientation == 3)
$this->_posy -= 30;
if ($orientation == 2 || $orientation == 4)
{
$this->_sizex = 30;
$this->_sizey = 1;
}
if ($orientation == 4)
$this->_posx -= 30;
}
else if ($status == "rotate")
{
$this->_type = 'rotate';
$this->_style = new Style (array('opacity' => 0.95,
'border' => '1px inset #424242',
'color' => '#000000',
'name' => 'rotate'
));
if ($orientation == 1 || $orientation == 3)
{
$this->_sizex = 5;
$this->_posx -= 2;
$this->_sizey = 1;
}
if ($orientation == 2 || $orientation == 4)
{
$this->_sizey = 5;
$this->_sizex = 1;
$this->_posy -= 2;
}
}
}

public function getType() { return ($this->_type); }
public function getStyle() { return ($this->_style); }
public function getPosX() { return ($this->_posx); }
Expand Down
5 changes: 5 additions & 0 deletions attlestar/Class/Ship.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
private $_type = null;
private $_team = null;
private $_posx = 0;
private $_orientation = 0;
private $_posy = 0;
private $_sizex = 0;
private $_sizey = 0;
Expand All @@ -28,6 +29,7 @@ function __construct(array $arg) {
array_key_exists('posx', $arg) &&
array_key_exists('posy', $arg) &&
array_key_exists('movement', $arg) &&
array_key_exists('orientation', $arg) &&
array_key_exists('sizex', $arg) &&
array_key_exists('sizey', $arg) &&
array_key_exists('weapon', $arg) &&
Expand All @@ -37,6 +39,7 @@ function __construct(array $arg) {
$this->_posx = $arg['posx'];
$this->_posy = $arg['posy'];
$this->_movement = $arg['movement'];
$this->_orientation = $arg['orientation'];
$this->_sizex = $arg['sizex'];
$this->_sizey = $arg['sizey'];
$this->_hp = $arg['hp'];
Expand Down Expand Up @@ -75,6 +78,8 @@ public function setTeam(Fleet $team ) {
public function getType() { return ($this->_type); }
public function setType($val) { $this->_type = $val; }
public function getStyle() { return ($this->_style); }
public function getOrientation() { return ($this->_orientation); }
public function setOrientation($val) { $this->_orientation = $val; }
public function getMovement() { return ($this->_movement); }
public function getPosX() { return ($this->_posx); }
public function setPosX( $posx ) { $this->_posx = $posx; }
Expand Down
2 changes: 1 addition & 1 deletion attlestar/fire.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$sql = New SQLdata;
$game = $sql->getUnivers($id);
$ship = unserialize($_SESSION['ship']);
$hl = new Highlight($ship, "fire");
$hl = new Highlight($ship, "fire", $ship->getOrientation());
$game->getMap()->addElem($hl);
$game->getMap()->addElem($ship);
echo $game->refreshFire();
Expand Down
2 changes: 1 addition & 1 deletion attlestar/highlight.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$_SESSION['ship'] = serialize($ret);
if ($ret)
{
$hl = new Highlight($ret, "move");
$hl = new Highlight($ret, "move", $ret->getOrientation());
$game->getMap()->addElem($hl);
$game->getMap()->addElem($ret);
}
Expand Down
6 changes: 4 additions & 2 deletions attlestar/move.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
$x = $_GET['x'];
$y = $_GET['y'];
$game->getMap()->unsetCoord($ship);
$ship->setPosX($x);
$ship->setPosY($y);
if ($ship->getOrientation() == 2 || $ship->getOrientation() == 4)
$ship->setPosX($x);
if ($ship->getOrientation() == 1 || $ship->getOrientation() == 3)
$ship->setPosY($y);
$game->getMap()->addElem($ship);
$sql->setUnivers($id, $game);
$_SESSION['ship'] = serialize($ship);
Expand Down
6 changes: 6 additions & 0 deletions attlestar/php/Game.Class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function refreshMove() {
echo '</div>';
}

public function refreshRotate() {
echo '<div id="plate">';
$this->getMap()->printRotate();
echo '</div>';
}

public function refreshInactive() {
echo '<div id="plate">';
$this->getMap()->printInactive();
Expand Down
28 changes: 27 additions & 1 deletion attlestar/php/Map.Class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function printMap() {
else {
print($tile->getStyle());
if ($tile->getStyle() != " style =\"background-color: #424242; opacity: 0.95; border: 1px inset #424242; border-radius: 20%;\" title=\"asteroide\"")
echo " onclick='highlight(\"".$x."\",\"".$y."\")'";
echo " onclick='highlight(\"".$x."\",\"".$y."\")' oncontextmenu='javascript:rotate(\"".$x."\",\"".$y."\");return false;'";
}
print('></td>' . PHP_EOL);
++$y;
Expand Down Expand Up @@ -105,6 +105,32 @@ public function printMove() {
print( "</table>" . PHP_EOL );
}

public function printRotate() {
print('<table summary = "map">' . PHP_EOL);
print('<tbody>' . PHP_EOL );
$x = 0;
foreach ($this->getPlate() as $line) {
$y = 0;
print("<tr>" . PHP_EOL );
foreach ($line as $tile) {
print('<td id="' . $x . "x" . $y . '" class="tile" ');
if ($tile == null)
print(' title="space" ' );
else {
print($tile->getStyle());
if ($tile->getStyle() == " style =\"background-color: #000000; opacity: 0.95; border: 1px inset #424242;\" title=\"rotate\"")
echo "onclick='rot(\"".$x."\",\"".$y."\")'";
}
print('></td>' . PHP_EOL);
++$y;
}
++$x;
print( "</tr>" . PHP_EOL);
}
print( '</tbody>' . PHP_EOL );
print( "</table>" . PHP_EOL );
}

public function printFire() {
print('<table summary = "map">' . PHP_EOL);
print('<tbody>' . PHP_EOL );
Expand Down
34 changes: 34 additions & 0 deletions attlestar/rot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?PHP

session_start();
require_once 'php/SQLdata.Class.php';
require_once 'php/Game.Class.php';
require_once 'php/IElem.Class.php';
require_once 'Class/Fleet.Class.php';
require_once 'Class/Highlight.Class.php';
require_once 'php/Obstacle.Class.php';

$id = $_SESSION['id_game'];
$ship = unserialize($_SESSION['ship']);
$sql = New SQLdata;
$game = $sql->getUnivers($id);
$x = $_GET['x'];
$y = $_GET['y'];
$game->getMap()->unsetCoord($ship);
if ($ship->getOrientation() == 2 || $ship->getOrientation() == 4)
{

}
if ($ship->getOrientation() == 1 || $ship->getOrientation() == 3)
{
if (($y) > $ship->getPosY());
$ship->setOrientation(4);
if (($y) < $ship->getPosY());
$ship->setOrientation(2);
}
$game->getMap()->addElem($ship);
$sql->setUnivers($id, $game);
$_SESSION['ship'] = serialize($ship);
echo $game->refreshFire();

?>
26 changes: 26 additions & 0 deletions attlestar/rotate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?PHP

session_start();
require_once 'php/SQLdata.Class.php';
require_once 'php/Game.Class.php';
require_once 'php/IElem.Class.php';
require_once 'Class/Fleet.Class.php';
require_once 'Class/Highlight.Class.php';
require_once 'php/Obstacle.Class.php';

$id = $_SESSION['id_game'];
$sql = New SQLdata;
$game = $sql->getUnivers($id);
$x = $_GET['x'];
$y = $_GET['y'];
$ret = $game->getMap()->getPlate()[$x][$y];
$_SESSION['ship'] = serialize($ret);
if ($ret)
{
$hl = new Highlight($ret, "rotate", $ret->getOrientation());
$game->getMap()->addElem($hl);
$game->getMap()->addElem($ret);
}
echo $game->refreshRotate();

?>
12 changes: 12 additions & 0 deletions attlestar/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ function move(x, y) {
fire();
}

function rot(x, y) {
newmap = file("rot.php?x="+ x +"&y=" + y);
document.getElementById('map').innerHTML = newmap;
fire();
}

function fire() {
newmap = file("fire.php");
document.getElementById('map').innerHTML = newmap;
Expand All @@ -18,11 +24,17 @@ function damage(x, y) {
newmap = file("damage.php?x="+ x +"&y=" + y);
document.getElementById('map').innerHTML = newmap;
}

function highlight(x, y) {
newmap = file("highlight.php?x="+ x +"&y=" + y);
document.getElementById('map').innerHTML = newmap;
}

function rotate(x, y) {
newmap = file("rotate.php?x="+ x +"&y=" + y);
document.getElementById('map').innerHTML = newmap;
}

function file(fichier) //Fonction de traitement AJAX
{
if(window.XMLHttpRequest) // FIREFOX
Expand Down

0 comments on commit 9659608

Please sign in to comment.