11<?php
22
3- class engine {
4-
3+ class engine
4+ {
55 public $ monster ;
66 public $ hero ;
77
8- function __construct (){
8+ public function __construct ()
9+ {
910 $ this ->hero = $ this ->hero ();
1011 $ this ->monster = $ this ->monster ();
1112 }
1213
13- function hero (){
14+ public function hero ()
15+ {
1416 $ buildHero = new PlayerFactory ;
1517 return $ buildHero ->createPlayer ('hero ' );
1618 }
1719
18- function monster (){
20+ public function monster ()
21+ {
1922 // $monsterEncounter = (new DataBase)->runQuery('SELECT `id` FROM `monster` ORDER BY RAND() LIMIT 0,1;');
2023 $ monsterEncounter = (new DataBase )->runQuery ('SELECT `id` FROM `monster` where id = 1 ' );
2124 $ buildMonster = new PlayerFactory ;
2225 return $ buildMonster ->createPlayer ('monster ' , $ monsterEncounter [0 ]['id ' ]);
2326 }
2427
25- function figth ($ hero , $ monster , $ turn , $ turnCounter = 1 , $ log_pass = '' ){
28+ public function figth ($ hero , $ monster , $ turn , $ turnCounter = 1 , $ log_pass = '' )
29+ {
2630 $ attacker = null ;
2731 $ defender = null ;
2832 $ stop_battle = false ;
2933 $ skill_name = '' ;
3034 $ lucky_damage_pass = '' ;
3135
3236 // set turn to atack and defence
33- if (empty ($ turn )){
37+ if (empty ($ turn )) {
3438 $ turn = $ this ->determinFirstTurnToAttack ($ hero , $ monster , $ turn );
3539 } elseif ($ turn ['turn ' ] === 'hero ' ) {
3640 $ turn ['turn ' ] = 'monster ' ;
3741 $ turn ['id ' ] = $ monster ->getId ();
3842 } else {
3943 $ turn ['turn ' ] = 'hero ' ;
4044 $ turn ['id ' ] = $ hero ->getId ();
41- }
45+ }
4246
43- if ($ turn ['turn ' ] === 'hero ' ){
47+ if ($ turn ['turn ' ] === 'hero ' ) {
4448 $ attacker = $ hero ;
4549 $ defender = $ monster ;
4650 } else {
@@ -53,26 +57,26 @@ function figth($hero, $monster, $turn, $turnCounter = 1, $log_pass = ''){
5357
5458 // skils encounter
5559 $ skill = $ hero ->skills ();
56- if ($ skill !== null && $ skill ['skill_type ' ] === 'attack ' && $ attacker ->getName () === "Orderus " ){
60+ if ($ skill !== null && $ skill ['skill_type ' ] === 'attack ' && $ attacker ->getName () === "Orderus " ) {
5761 $ oldDamage = $ damage ;
5862 $ damage = $ skill ['number_strikes ' ] * $ damage ; // 2 strikes results double the damage
5963 $ skill_name = "Orderus activated attack skill ' " . $ skill ['name ' ] . "' damage increace from " .$ oldDamage ." To " . $ damage ." -> " ;
60- }
64+ }
6165
62- if ($ skill !== null && $ skill ['skill_type ' ] === 'defence ' && $ defender ->getName () === "Orderus " ){
66+ if ($ skill !== null && $ skill ['skill_type ' ] === 'defence ' && $ defender ->getName () === "Orderus " ) {
6367 $ oldDamage = $ damage ;
6468 $ damage = ($ skill ['number_strikes ' ] / 100 ) * $ damage ; // 50 percent of damage/ half of the damage, defence skill
6569 $ skill_name = "Orderus activated defence skill ' " . $ skill ['name ' ] . "' damage reduce from " .$ oldDamage ." To " . $ damage ." -> " ;
66- }
70+ }
6771
68- if (rand (0 , 100 ) < $ defender ->getLuck () ) { // the defender gets lucky that turn.
72+ if (rand (0 , 100 ) < $ defender ->getLuck ()) { // the defender gets lucky that turn.
6973 $ damage = 0 ;
7074 $ lucky_damage_pass = ' Luck change to get 0 damage occured. ' ;
7175 }
7276
7377 $ defender ->setHealth ($ defender ->getHealth () - $ damage ); // The damage is subtracted from the defender’s health.
7478
75- if ($ defender ->getHealth () <= 0 ) { // stop battle if defender health reaches 0
79+ if ($ defender ->getHealth () <= 0 ) { // stop battle if defender health reaches 0
7680 $ defender ->setHealth (0 );
7781 $ stop_battle = true ;
7882 $ log_pass ->Log ('Attack from ' . $ attacker ->getName () . ". " .$ skill_name . $ lucky_damage_pass . " Damage inflicted " .$ damage ." to " .$ defender ->getName () . " health remaning is " .$ defender ->getHealth ()." </br> " );
@@ -81,7 +85,7 @@ function figth($hero, $monster, $turn, $turnCounter = 1, $log_pass = ''){
8185 $ log_pass ->Log ('Attack from ' . $ attacker ->getName () . ". " .$ skill_name . $ lucky_damage_pass . " Damage inflicted " .$ damage ." to " .$ defender ->getName () . " health remaning is " .$ defender ->getHealth ()." </br> " ); // log battle damage and the defender helth
8286 }
8387
84- if ($ turnCounter === 20 ) { // turns reached 20 game over
88+ if ($ turnCounter === 20 ) { // turns reached 20 game over
8589 $ stop_battle = true ;
8690 $ winner = ($ hero ->getHealth () > $ monster ->getHealth ()) ? $ hero ->getName () : $ monster ->getName ();
8791 $ log_pass ->Log ("Max number of turns 20 has been reached , winner is " . $ winner . "</br> " );
@@ -92,9 +96,10 @@ function figth($hero, $monster, $turn, $turnCounter = 1, $log_pass = ''){
9296 return [$ hero , $ monster , $ turn , $ stop_battle , $ turnCounter , $ log_pass ];
9397 }
9498
95- function determinFirstTurnToAttack ($ hero , $ monster , $ turn ){ // The first attack
99+ public function determinFirstTurnToAttack ($ hero , $ monster , $ turn )
100+ { // The first attack
96101
97- if ($ monster ->getSpeed () > $ hero ->getSpeed ()) {
102+ if ($ monster ->getSpeed () > $ hero ->getSpeed ()) {
98103 $ turn = ['turn ' => 'monster ' , 'id ' => $ monster ->getId ()];
99104 } elseif ($ monster ->getSpeed () < $ hero ->getSpeed ()) {
100105 $ turn = ['turn ' => 'hero ' , 'id ' => $ hero ->getId ()];
@@ -110,8 +115,4 @@ function determinFirstTurnToAttack($hero, $monster, $turn){ // The first attack
110115
111116 return $ turn ;
112117 }
113-
114-
115118}
116-
117- ?>
0 commit comments