From b3818c9c3ffb322a7ae5661db0f9ade163e00d8a Mon Sep 17 00:00:00 2001 From: Biggbada Date: Mon, 31 Jul 2023 10:30:33 +0200 Subject: [PATCH 1/8] work in progress --- classes/player.class.php | 56 +++++++++ index.php | 259 ++++++++++++++++++++------------------- 2 files changed, 190 insertions(+), 125 deletions(-) create mode 100644 classes/player.class.php diff --git a/classes/player.class.php b/classes/player.class.php new file mode 100644 index 0000000..cce35e2 --- /dev/null +++ b/classes/player.class.php @@ -0,0 +1,56 @@ +name = $name; + $this->power = $power; + $this->mana = $mana; + $this->health = $health; + } + public function attack(Player $player) + { + $damage = $this->power; + $player->loseHealth($damage); + } + + public function loseHealth($damage) + { + $this->health -= $damage; + } + + public function cure($mana) + { + $this->health +=; + } + + + public function test() + { + echo 'test'; + } +} + + +class Fight +{ + public object $player1; + public object $player2; + + public function __construct(Player $player1, Player $player2 = null) + { + $this->player1 = $player1; + $this->player2 = $player2; + } + public function countHealth() + { + } + public function stopMatch() + { + } +} diff --git a/index.php b/index.php index 76440eb..e597bde 100644 --- a/index.php +++ b/index.php @@ -1,29 +1,42 @@ test(); +dump($playerOne); + +$playerTwoName = "Batman"; +$playerTwoPower = 100; +$playerTwoMana = 100; +$playerTwoHealth = 100; +$playerTwo = new Player($playerTwoName, $playerTwoPower, $playerTwoMana, $playerTwoHealth); +$playerTwo->test(); +dump($playerTwo); ?> + + Battle - - + + -
- - - -

Battle

+
+ + + +

Battle

@@ -76,128 +89,123 @@
-
-

Match

-
-
- Avatar - +
+

Match

+
+
+ Avatar + - -
    -
  • Name :
  • -
  • Attaque :
  • -
  • Mana :
  • -
+ +
    +
  • Name :
  • +
  • Attaque :
  • +
  • Mana :
  • +
+
-
-
-
- Avatar - +
+
+ Avatar + - -
    -
  • Name :
  • -
  • Attaque :
  • -
  • Mana :
  • -
+ +
    +
  • Name :
  • +
  • Attaque :
  • +
  • Mana :
  • +
+
-
-
-

Combat

-
    +
    +

    Combat

    +
      -
    • - test -
    • +
    • + test +
    • -
    -
    -
    - - -
    -
    - -
    -
    -
    -
    -

    Résultat

    - xxxx est le vainqueur ! -
    - -
    +
+
+
+ + +
+
+ +
+
+
+
+

Résultat

+ xxxx est le vainqueur ! +
+ +
+
-
- + let submitRestart = document.querySelector("#restart"); + let alreadyPlaySongRestart = false; + if (submitRestart) { + submitRestart.addEventListener("click", function(event) { + if (alreadyPlaySongRestart) + return true; + event.preventDefault(); + let fatality_song = document.getElementById("fatality-song"); + fatality_song.play(); + alreadyPlaySongRestart = true; + setTimeout(function() { + submitRestart.click(); + }, 2000); + }) + } + }); + - + + \ No newline at end of file From e385055067b2b901d34ab38b4449c486ae7eaa49 Mon Sep 17 00:00:00 2001 From: Biggbada Date: Mon, 31 Jul 2023 11:02:06 +0200 Subject: [PATCH 2/8] classe player 80% --- classes/player.class.php | 24 ++++++++++++++++++------ index.php | 3 +-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/classes/player.class.php b/classes/player.class.php index cce35e2..f245d51 100644 --- a/classes/player.class.php +++ b/classes/player.class.php @@ -16,23 +16,33 @@ public function __construct(string $name, int $power, int $mana, int $health) public function attack(Player $player) { $damage = $this->power; + echo "$this->name attaque $player->name et lui inflige $damage de dégats"; $player->loseHealth($damage); + // $player->attack($this); + return $player->health; } public function loseHealth($damage) { $this->health -= $damage; + return $this; } public function cure($mana) { - $this->health +=; + $this->health += ($mana / 20); + $mana /= 3; + return $this; } - - - public function test() + public function die() + { + if ($this->health <= 0) { + $this->lose(); + } + } + public function lose() { - echo 'test'; + echo 'You lose ahahah'; } } @@ -47,8 +57,10 @@ public function __construct(Player $player1, Player $player2 = null) $this->player1 = $player1; $this->player2 = $player2; } - public function countHealth() + public function watchHealth() { + if ($this->player1->health <= 0 || $this->player2->health <= 0) { + } } public function stopMatch() { diff --git a/index.php b/index.php index e597bde..0f15048 100644 --- a/index.php +++ b/index.php @@ -6,7 +6,6 @@ $playerOneMana = 100; $playerOneHealth = 100; $playerOne = new Player($playerOneName, $playerOnePower, $playerOneMana, $playerOneHealth); -$playerOne->test(); dump($playerOne); $playerTwoName = "Batman"; @@ -14,8 +13,8 @@ $playerTwoMana = 100; $playerTwoHealth = 100; $playerTwo = new Player($playerTwoName, $playerTwoPower, $playerTwoMana, $playerTwoHealth); -$playerTwo->test(); dump($playerTwo); +$playerOne->attack($playerTwo); ?> From d45057c3081329573ac00e37b3a4f4be815b54fd Mon Sep 17 00:00:00 2001 From: Biggbada Date: Mon, 31 Jul 2023 11:13:29 +0200 Subject: [PATCH 3/8] class Player in progress (80%) --- classes/player.class.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/classes/player.class.php b/classes/player.class.php index f245d51..2033eba 100644 --- a/classes/player.class.php +++ b/classes/player.class.php @@ -15,12 +15,19 @@ public function __construct(string $name, int $power, int $mana, int $health) } public function attack(Player $player) { - $damage = $this->power; - echo "$this->name attaque $player->name et lui inflige $damage de dégats"; + $damage = $this->power / 20; + echo "$this->name attaque $player->name et lui inflige $damage de dégats \r \n"; $player->loseHealth($damage); - // $player->attack($this); + $player->counterAttack($this); + dump($player); return $player->health; } + public function counterAttack($player) + { + $damage = $player->power / 20; + $this->health -= $damage; + echo " \r \n $player->name réplique et inflige $damage de dégat à $this->name."; + } public function loseHealth($damage) { From 8bd539e2fa7404a7b6faf93149cd272d1414f845 Mon Sep 17 00:00:00 2001 From: Biggbada Date: Mon, 31 Jul 2023 14:11:27 +0200 Subject: [PATCH 4/8] fight management ok --- attack.php | 121 ++++++++++++++++++++ classes/player.class.php | 40 +++---- index.php | 230 +++++++++++++++------------------------ resultat.php | 30 +++++ 4 files changed, 254 insertions(+), 167 deletions(-) create mode 100644 attack.php create mode 100644 resultat.php diff --git a/attack.php b/attack.php new file mode 100644 index 0000000..eddc33d --- /dev/null +++ b/attack.php @@ -0,0 +1,121 @@ +getLifeStatus() && $playerTwo->getLifeStatus()) + $playerOne->attack($playerTwo); + $_SESSION['player2'] = $playerTwo; + $playerTwo->getLifeStatus(); + $playerTwo->attack($playerOne); + $_SESSION['player1'] = $playerOne; + $playerOne->getLifeStatus(); + + dump($playerOne, $playerTwo); +} +if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['soin'])) { + $playerOne->cure(); + dump($playerOne, $playerTwo); +} +?> + +
+

Match

+
+
+ Avatar + + + +
    +
  • Name : name ?>
  • +
  • Attaque : power ?>
  • +
  • Mana : mana ?>
  • +
  • Vie : health ?>
  • +
+
+
+
+
+ Avatar + + + +
    +
  • Name : name ?>
  • +
  • Attaque : power ?>
  • +
  • Mana : mana ?>
  • +
  • Vie : health ?>
  • +
+
+
+
+

Combat

+
    + +
  • + test +
  • + +
+
+
+ + +
+
+ +
+
+
+ + \ No newline at end of file diff --git a/classes/player.class.php b/classes/player.class.php index 2033eba..cca9df7 100644 --- a/classes/player.class.php +++ b/classes/player.class.php @@ -15,31 +15,31 @@ public function __construct(string $name, int $power, int $mana, int $health) } public function attack(Player $player) { - $damage = $this->power / 20; + $damage = $this->power / 2; + $player->health -= $damage; echo "$this->name attaque $player->name et lui inflige $damage de dégats \r \n"; - $player->loseHealth($damage); - $player->counterAttack($this); - dump($player); - return $player->health; - } - public function counterAttack($player) - { - $damage = $player->power / 20; - $this->health -= $damage; - echo " \r \n $player->name réplique et inflige $damage de dégat à $this->name."; + $this->getLifeStatus(); + // $damage = $player->power / 20; + // $this->health -= $damage; + // echo " \r \n $player->name réplique et inflige $damage de dégat à $this->name."; } - public function loseHealth($damage) + + public function cure() { - $this->health -= $damage; + $this->health += ($this->mana / 20); + $this->mana /= 3; return $this; } - public function cure($mana) + public function getLifeStatus() { - $this->health += ($mana / 20); - $mana /= 3; - return $this; + if ($this->health > 0) { + return true; + } else { + echo 'you are dead'; + return false; + } } public function die() { @@ -64,11 +64,7 @@ public function __construct(Player $player1, Player $player2 = null) $this->player1 = $player1; $this->player2 = $player2; } - public function watchHealth() - { - if ($this->player1->health <= 0 || $this->player2->health <= 0) { - } - } + public function stopMatch() { } diff --git a/index.php b/index.php index 0f15048..5440f39 100644 --- a/index.php +++ b/index.php @@ -1,20 +1,34 @@ attack($playerTwo); +session_start(); +if ($_SERVER['REQUEST_METHOD'] == 'POST') { + + // $playerOne->attack($playerTwo); + $playerOne = new Player($_SESSION['player_name'], $_SESSION['player_attaque'], $_SESSION['player_mana'], $_SESSION['player_sante']); + $playerTwo = new Player($_SESSION['adversaire_name'], $_SESSION['adversaire_attaque'], $_SESSION['adversaire_mana'], $_SESSION['adversaire_sante']); + $_SESSION['player1'] = $playerOne; + $_SESSION['player2'] = $playerTwo; + + dump($playerOne, $playerTwo); + dump($_SESSION); +} + +// $playerOneName = "Superman"; +// $playerOnePower = 100; +// $playerOneMana = 100; +// $playerOneHealth = 100; +// $playerOne = new Player($playerOneName, $playerOnePower, $playerOneMana, $playerOneHealth); +// dump($playerOne); + +// $playerTwoName = "Batman"; +// $playerTwoPower = 100; +// $playerTwoMana = 100; +// $playerTwoHealth = 100; +// $playerTwo = new Player($playerTwoName, $playerTwoPower, $playerTwoMana, $playerTwoHealth); +// $playerOne->attack($playerTwo); +// dump($playerOne, $playerTwo); + ?> @@ -37,25 +51,25 @@

Battle

-
+
Joueur
- +
- +
- +
- +
@@ -65,19 +79,19 @@
- +
- +
- +
- +
@@ -88,130 +102,56 @@
-
-

Match

-
-
- Avatar - - - -
    -
  • Name :
  • -
  • Attaque :
  • -
  • Mana :
  • -
-
-
-
-
- Avatar - - - -
    -
  • Name :
  • -
  • Attaque :
  • -
  • Mana :
  • -
-
-
-
-

Combat

-
    -
  • - test -
  • -
-
-
- - -
-
- -
-
-
-
-

Résultat

- xxxx est le vainqueur ! -
- -
-
-
-
- + - + \ No newline at end of file diff --git a/resultat.php b/resultat.php new file mode 100644 index 0000000..fe4714b --- /dev/null +++ b/resultat.php @@ -0,0 +1,30 @@ + +
+

Résultat

+ xxxx est le vainqueur ! +
+ +
+
+
+ + \ No newline at end of file From 4c9ff2926feebd5175757155bad61bc263f2a3aa Mon Sep 17 00:00:00 2001 From: Biggbada Date: Mon, 31 Jul 2023 14:47:36 +0200 Subject: [PATCH 5/8] pour verif --- attack.php | 15 +++++++++++---- classes/player.class.php | 11 ++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/attack.php b/attack.php index eddc33d..d674d73 100644 --- a/attack.php +++ b/attack.php @@ -3,7 +3,7 @@ // require './index.php'; require './classes/player.class.php'; session_start(); -if (($_SERVER['REQUEST_METHOD'] == 'POST') && !isset($_POST['attaque'])) { +if (($_SERVER['REQUEST_METHOD'] == 'POST') && !isset($_POST['attaque']) && !isset($_POST['soin'])) { $playerOne = new Player($_POST['player-name'], $_POST['player-attaque'], $_POST['player-mana'], $_POST['player-sante']); $playerTwo = new Player($_POST['adversaire-name'], $_POST['adversaire-attaque'], $_POST['adversaire-mana'], $_POST['adversaire-sante']); @@ -19,14 +19,21 @@ $playerOne->attack($playerTwo); $_SESSION['player2'] = $playerTwo; $playerTwo->getLifeStatus(); - $playerTwo->attack($playerOne); - $_SESSION['player1'] = $playerOne; - $playerOne->getLifeStatus(); + if ($playerTwo->health < 30) { + $playerTwo->cure(); + } else { + $playerTwo->attack($playerOne); + $_SESSION['player1'] = $playerOne; + $playerOne->getLifeStatus(); + } dump($playerOne, $playerTwo); } if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['soin'])) { + $playerOne = $_SESSION['player1']; + $playerTwo = $_SESSION['player2']; $playerOne->cure(); + $playerTwo->attack($playerOne); dump($playerOne, $playerTwo); } ?> diff --git a/classes/player.class.php b/classes/player.class.php index cca9df7..9f20d49 100644 --- a/classes/player.class.php +++ b/classes/player.class.php @@ -2,9 +2,9 @@ class Player { public string $name; - public int $power; - public int $mana; - public int $health; + public float $power; + public float $mana; + public float $health; public function __construct(string $name, int $power, int $mana, int $health) { @@ -15,7 +15,7 @@ public function __construct(string $name, int $power, int $mana, int $health) } public function attack(Player $player) { - $damage = $this->power / 2; + $damage = $this->power / 4; $player->health -= $damage; echo "$this->name attaque $player->name et lui inflige $damage de dégats \r \n"; $this->getLifeStatus(); @@ -28,7 +28,8 @@ public function attack(Player $player) public function cure() { $this->health += ($this->mana / 20); - $this->mana /= 3; + $this->mana /= 4; + echo "$this->name s'est soigné"; return $this; } From b6f6e03e4e1e0ddd7cf91ff665e2731b440c349d Mon Sep 17 00:00:00 2001 From: Biggbada Date: Mon, 31 Jul 2023 15:56:03 +0200 Subject: [PATCH 6/8] All works --- attack.php | 49 +++++++++++++++++++++++++++++++--------- classes/player.class.php | 31 ++++++++----------------- index.php | 26 --------------------- resultat.php | 22 ++++++++++++++++-- 4 files changed, 67 insertions(+), 61 deletions(-) diff --git a/attack.php b/attack.php index d674d73..9ddf31c 100644 --- a/attack.php +++ b/attack.php @@ -3,6 +3,14 @@ // require './index.php'; require './classes/player.class.php'; session_start(); +if (isset($_SESSION['player1'])) { + $playerOne = $_SESSION['player1']; + $playerTwo = $_SESSION['player2']; + if (($playerOne->health < 0) || ($playerTwo->health < 0)) { + echo "end of game"; + header('Location: ./resultat.php'); + } +} if (($_SERVER['REQUEST_METHOD'] == 'POST') && !isset($_POST['attaque']) && !isset($_POST['soin'])) { $playerOne = new Player($_POST['player-name'], $_POST['player-attaque'], $_POST['player-mana'], $_POST['player-sante']); @@ -10,7 +18,6 @@ $_SESSION['player1'] = $playerOne; $_SESSION['player2'] = $playerTwo; } -dump($_SESSION); // $_SESSION['fight'] = true; if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['attaque'])) { $playerOne = $_SESSION['player1']; @@ -18,23 +25,40 @@ // while ($playerOne->getLifeStatus() && $playerTwo->getLifeStatus()) $playerOne->attack($playerTwo); $_SESSION['player2'] = $playerTwo; - $playerTwo->getLifeStatus(); + + if ($playerTwo->health < 0) { + echo "end of game"; + header('Location: ./resultat.php'); + } if ($playerTwo->health < 30) { - $playerTwo->cure(); + $iscured = $playerTwo->cure(); + if ($iscured === false) { + $playerTwo->attack(); + } } else { $playerTwo->attack($playerOne); $_SESSION['player1'] = $playerOne; - $playerOne->getLifeStatus(); + if ($playerOne->health < 0) { + echo "end of game"; + header('Location: ./resultat.php'); + } } - - dump($playerOne, $playerTwo); } if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['soin'])) { $playerOne = $_SESSION['player1']; $playerTwo = $_SESSION['player2']; - $playerOne->cure(); - $playerTwo->attack($playerOne); - dump($playerOne, $playerTwo); + $isCured = $playerOne->cure(); + if ($isCured === false) { + return; + } else { + $playerTwo->attack($playerOne); + $_SESSION['player1'] = $playerOne; + + if ($playerOne->health < 0) { + echo "end of game"; + header('Location: ./resultat.php'); + } + } } ?> @@ -72,8 +96,11 @@

Combat

    -
  • - test + + comment)) { ?> +
  • comment ?>
  • + comment)) { ?> +
  • comment ?>
diff --git a/classes/player.class.php b/classes/player.class.php index 9f20d49..ebe8f6c 100644 --- a/classes/player.class.php +++ b/classes/player.class.php @@ -5,6 +5,7 @@ class Player public float $power; public float $mana; public float $health; + public string $comment; public function __construct(string $name, int $power, int $mana, int $health) { @@ -17,8 +18,7 @@ public function attack(Player $player) { $damage = $this->power / 4; $player->health -= $damage; - echo "$this->name attaque $player->name et lui inflige $damage de dégats \r \n"; - $this->getLifeStatus(); + $this->comment = "$this->name attaque $player->name et lui inflige $damage de dégats \r \n"; // $damage = $player->power / 20; // $this->health -= $damage; // echo " \r \n $player->name réplique et inflige $damage de dégat à $this->name."; @@ -27,31 +27,18 @@ public function attack(Player $player) public function cure() { - $this->health += ($this->mana / 20); - $this->mana /= 4; - echo "$this->name s'est soigné"; - return $this; - } + if ($this->mana > 0) { - public function getLifeStatus() - { - if ($this->health > 0) { - return true; + $this->health += (($this->mana / 20) + 10); + $this->mana /= 4; + $this->mana -= 1; + $this->comment = "$this->name s'est soigné"; + return $this; } else { - echo 'you are dead'; + $this->comment = "$this->name n'a plus assez de mana pour se soigner"; return false; } } - public function die() - { - if ($this->health <= 0) { - $this->lose(); - } - } - public function lose() - { - echo 'You lose ahahah'; - } } diff --git a/index.php b/index.php index 5440f39..447348a 100644 --- a/index.php +++ b/index.php @@ -2,32 +2,6 @@ require_once __DIR__ . '/vendor/autoload.php'; require './classes/player.class.php'; session_start(); -if ($_SERVER['REQUEST_METHOD'] == 'POST') { - - // $playerOne->attack($playerTwo); - $playerOne = new Player($_SESSION['player_name'], $_SESSION['player_attaque'], $_SESSION['player_mana'], $_SESSION['player_sante']); - $playerTwo = new Player($_SESSION['adversaire_name'], $_SESSION['adversaire_attaque'], $_SESSION['adversaire_mana'], $_SESSION['adversaire_sante']); - $_SESSION['player1'] = $playerOne; - $_SESSION['player2'] = $playerTwo; - - dump($playerOne, $playerTwo); - dump($_SESSION); -} - -// $playerOneName = "Superman"; -// $playerOnePower = 100; -// $playerOneMana = 100; -// $playerOneHealth = 100; -// $playerOne = new Player($playerOneName, $playerOnePower, $playerOneMana, $playerOneHealth); -// dump($playerOne); - -// $playerTwoName = "Batman"; -// $playerTwoPower = 100; -// $playerTwoMana = 100; -// $playerTwoHealth = 100; -// $playerTwo = new Player($playerTwoName, $playerTwoPower, $playerTwoMana, $playerTwoHealth); -// $playerOne->attack($playerTwo); -// dump($playerOne, $playerTwo); ?> diff --git a/resultat.php b/resultat.php index fe4714b..b69da46 100644 --- a/resultat.php +++ b/resultat.php @@ -1,9 +1,27 @@

Résultat

- xxxx est le vainqueur ! -
+ health) > ($playerTwo->health)) { + echo "$playerOne->name est le vainqueur"; + + session_destroy(); + } else { + echo "$playertwo->name est le vainqueur"; + + session_destroy(); + } + + ?> +
From ed5cd7b7b4a900158e3882c7b2be2ce45cb5e6c0 Mon Sep 17 00:00:00 2001 From: Biggbada Date: Mon, 31 Jul 2023 15:57:49 +0200 Subject: [PATCH 7/8] Add equality possibility --- resultat.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resultat.php b/resultat.php index b69da46..ea8d12c 100644 --- a/resultat.php +++ b/resultat.php @@ -13,6 +13,11 @@ if (($playerOne->health) > ($playerTwo->health)) { echo "$playerOne->name est le vainqueur"; + session_destroy(); + } + if (($playerOne->health) === ($playerTwo->health)) { + echo "Match nul !!!"; + session_destroy(); } else { echo "$playertwo->name est le vainqueur"; From 4805b8fb7ebe7711170cf2cbab0a6adb1dfe39f1 Mon Sep 17 00:00:00 2001 From: Biggbada Date: Mon, 31 Jul 2023 16:13:43 +0200 Subject: [PATCH 8/8] update results page --- resultat.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/resultat.php b/resultat.php index ea8d12c..3a6c861 100644 --- a/resultat.php +++ b/resultat.php @@ -12,18 +12,16 @@ health) > ($playerTwo->health)) { echo "$playerOne->name est le vainqueur"; - - session_destroy(); + } + if (($playerOne->health) < ($playerTwo->health)) { + echo "$playerTwo->name est le vainqueur"; } if (($playerOne->health) === ($playerTwo->health)) { echo "Match nul !!!"; + } - session_destroy(); - } else { - echo "$playertwo->name est le vainqueur"; - session_destroy(); - } + session_destroy(); ?>