Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud committed Apr 15, 2016
1 parent 670099c commit b96ffbc
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 100 deletions.
4 changes: 2 additions & 2 deletions piscine/php/j08/api/map.php
Expand Up @@ -3,7 +3,7 @@
require_once '../class/Game.class.php';
header("Content-Type: application/json");

if ($_SESSION['party_id']) {
if (isset($_SESSION['party_id'])) {
$party = Game::load($_SESSION['party_id']);
$ships = array();
foreach ($party->getPlayers() as $player) {
Expand All @@ -23,4 +23,4 @@
else {
header("HTTP/1.0 401 Unauthorized");
}
?>
?>
54 changes: 36 additions & 18 deletions piscine/php/j08/class/Game.class.php
@@ -1,24 +1,30 @@
<?PHP
require_once 'Player.class.php';

require_once 'SpaceShip.class.php';
require_once 'Weapon.class.php';
require_once 'impls/ImperialFregate.class.php';
require_once 'impls/OrkDestructor.class.php';
class Game {

protected $_id = 0;
protected $_players = array();

static function load($id) {
if (file_exists("../../datas/parties/". $id) == false)
return null;
$content = unserialize(file_get_contents("../../datas/parties/" . $id));
$instance = new GameManager();
$instance.set_players($content['_players']);
$instance.set_id($id);
$instance.set_turn($content['_turn']);
return $instance;

function __construct () {
$this->_id = Game::gen_uuid();
$one = new Player();
$one->setColor("blue");
$one->addShip(new ImperialFregate());
$one->getShips()[0]->setPosition(array( 40, 30 ));
$two = new Player();
$two->setColor("red");
$two->addShip(new OrkDestructor());
$two->getShips()[0]->setPosition(array( 80, 70 ));
$this->_players = array ($one, $two);
}


public function save() {
file_put_contents("../../datas/parties/" . $this->_id, serialize($this));
file_put_contents($_SERVER['DOCUMENT_ROOT'] ."/datas/parties/" . $this->_id, serialize($this));
}

public static function gen_uuid() {
Expand All @@ -28,12 +34,24 @@ public static function gen_uuid() {
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
}

public function getId() {
return $this->_id;
}

public function getPlayers() {
return $this->_players;

public function getId() { return $this->_id; }

public function setId($_id) { $this->_id = $_id; }

public function getPlayers() { return $this->_players; }

public function setPlayers($_players) { $this->_players = $_players; }

static function load($id) {
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/datas/parties/". $id) == false)
return null;
$content = unserialize(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/datas/parties/" . $id));
$instance = new Game();
$instance->setPlayers($content->getPlayers());
$instance->setId($id);
return $instance;
}

}
?>
7 changes: 6 additions & 1 deletion piscine/php/j08/class/Player.class.php
@@ -1,6 +1,6 @@
<?PHP

class Player {

protected $_ships = array ();
protected $_color = "red";

Expand All @@ -15,5 +15,10 @@ public function getShips() {
public function getColor() {
return $this->_color;
}

public function setColor($color) {
return $this->_color = $color;
}

}
?>
56 changes: 52 additions & 4 deletions piscine/php/j08/class/SpaceShip.class.php
Expand Up @@ -8,16 +8,16 @@ abstract class SpaceShip {
const DISABLED = 3;
const DEAD = 4;
const NONE = 5;

protected $_name = "Default Ship";
protected $_sprite = null;
protected $_size = new array (1,1);
protected $_size = array (1,1);
protected $_resistance = 0;
protected $_power = 0;
protected $_speed = 0;
protected $_weight = 0;
protected $_shield = 0;
protected $_state = ShapeShip::NONE;
protected $_state = SpaceShip::NONE;
protected $_weapons = array();
protected $_bonus = array();
protected $_position = array(0,0);
Expand All @@ -32,6 +32,54 @@ function __set($attrb, $value) {

static function doc() {
return file_get_contents("docs/SpaceShip.doc.txt");
}
}

public function getName() { return $this->_name; }

public function setName($_name) { $this->_name = $_name; }

public function getSprite() { return $this->_sprite; }

public function setSprite($_sprite) { $this->_sprite = $_sprite; }

public function getSize() { return $this->_size; }

public function setSize($_size) { $this->_size = $_size; }

public function getResistance() { return $this->_resistance; }

public function setResistance($_resistance) { $this->_resistance = $_resistance; }

public function getPower() { return $this->_power; }

public function setPower($_power) { $this->_power = $_power; }

public function getSpeed() { return $this->_speed; }

public function setSpeed($_speed) { $this->_speed = $_speed; }

public function getWeight() { return $this->_weight; }

public function setWeight($_weight) { $this->_weight = $_weight; }

public function getShield() { return $this->_shield; }

public function setShield($_shield) { $this->_shield = $_shield; }

public function getState() { return $this->_state; }

public function setState($_state) { $this->_state = $_state; }

public function getWeapons() { return $this->_weapons; }

public function setWeapons($_weapons) { $this->_weapons = $_weapons; }

public function getBonus() { return $this->_bonus; }

public function setBonus($_bonus) { $this->_bonus = $_bonus; }

public function getPosition() { return $this->_position; }

public function setPosition($_position) { $this->_position = $_position; }
}
?>
10 changes: 10 additions & 0 deletions piscine/php/j08/class/Weapon.class.php
Expand Up @@ -25,5 +25,15 @@ function __set($attrb, $value) {
static function doc() {
return file_get_contents("docs/Weapon.doc.txt");
}

public function getCharge() { return $this->_charge; }

public function setCharge($_charge) { $this->_charge = $_charge; }

public function getDistance() { return $this->_distance; }

public function getEffect() { return $this->_effect; }

public function getRayon() { return $this->_rayon; }
}
?>
4 changes: 1 addition & 3 deletions piscine/php/j08/class/impls/HeavySpear.class.php
@@ -1,6 +1,4 @@
<?PHP
require_once '../Weapon.class.php';

class HeavySpear extends Weapon {

function __construct () {
Expand All @@ -12,6 +10,6 @@ function __construct () {

static function doc() {
return file_get_contents("docs/WeaponImpl.doc.txt");
}
}
}
?>
11 changes: 5 additions & 6 deletions piscine/php/j08/class/impls/ImperialDestroyer.class.php
@@ -1,18 +1,17 @@
<?PHP
require_once '../Weapon.class.php';
require_once '../SpaceShip.class.php';
require_once 'MultipleLaser.class.php';

class ImperialDestroyer extends SpaceShip {

function __construct () {
$this->_name = "Imperial Destroyer";
$this->_sprite = "ImperialDestroyer.png")
$this->_size = new array(3, 1);
$this->_sprite = "ImperialDestroyer.png";
$this->_size = array(3, 1);
$this->_power = 10;
$this->_resistance = 4;
$this->_weight = 4;
$this->_speed = 18;
$this->_weapons = array( new MultipleLaser() );
}
}
}
?>
9 changes: 4 additions & 5 deletions piscine/php/j08/class/impls/ImperialFregate.class.php
@@ -1,17 +1,16 @@
<?PHP
require_once '../Weapon.class.php';
require_once '../SpaceShip.class.php';
require_once 'MultipleLaser.class.php';

class ImperialFregate extends SpaceShip {

function __construct () {
$this->_name = "Imperial Fregate";
$this->_size = new array(4, 1);
$this->_size = array(4, 1);
$this->_power = 10;
$this->_resistance = 5;
$this->_weight = 4;
$this->_speed = 15;
$this->_weapons = array( new MultipleLaser() );
}
}
}
?>
7 changes: 3 additions & 4 deletions piscine/php/j08/class/impls/LightSpear.class.php
@@ -1,6 +1,5 @@
<?PHP
require_once '../Weapon.class.php';


class LightSpear extends Weapon {

function __construct () {
Expand All @@ -9,9 +8,9 @@ function __construct () {
$this->_effect = Weapon::LINE;
$this->_rayon = 1;
}

static function doc() {
return file_get_contents("docs/WeaponImpl.doc.txt");
}
}
}
?>
7 changes: 3 additions & 4 deletions piscine/php/j08/class/impls/MultipleLaser.class.php
@@ -1,8 +1,7 @@
<?PHP
require_once '../Weapon.class.php';


class MultipleLaser extends Weapon {

function __construct () {
$this->_charge = 0;
$this->_distance = array (10, 20, 30);
Expand All @@ -12,6 +11,6 @@ function __construct () {

static function doc() {
return file_get_contents("docs/WeaponImpl.doc.txt");
}
}
}
?>
7 changes: 2 additions & 5 deletions piscine/php/j08/class/impls/OrkDestructor.class.php
@@ -1,13 +1,10 @@
<?PHP
require_once '../Weapon.class.php';
require_once '../SpaceShip.class.php';

class OrkDestructor extends SpaceShip {

function __construct () {
$this->_name = "Ork Destructor";
$this->_sprite = "OrkDestructor.png")
$this->_size = new array(2, 1);
$this->_sprite = "OrkDestructor.png";
$this->_size = array(2, 1);
$this->_power = 10;
$this->_resistance = 4;
$this->_weight = 3;
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion piscine/php/j08/game.php
Expand Up @@ -13,7 +13,7 @@
$case_id = 0;
for($y = 0; $y < 100; $y++) {
echo '<tr id="row' . $y .'">';
for($i = 0; $i < 150; $i++) {
for($i = 0; $i < 100; $i++) {
echo '<td id="case' . $case_id .'"></td>';
$case_id++;
}
Expand Down
37 changes: 0 additions & 37 deletions piscine/php/j08/index.html

This file was deleted.

11 changes: 11 additions & 0 deletions piscine/php/j08/index.php
@@ -0,0 +1,11 @@
<?PHP
require_once './class/Game.class.php';
session_start();
if (count($_SESSION) == 0) {
$game = new Game();
$_SESSION['party_id'] = $game->getId();
$game->save();
} else {
header('Location: game.php');
}
?>
5 changes: 3 additions & 2 deletions piscine/php/j08/styles/css/game.css
Expand Up @@ -10,7 +10,8 @@ body {

table {
border-collapse: collapse;
width: 100%;
width: 80%;
height: 80%;
}

td {
Expand All @@ -19,5 +20,5 @@ td {
}

td:hover {
background-color: red;
background-color: black;
}

0 comments on commit b96ffbc

Please sign in to comment.