Skip to content

Commit be66a43

Browse files
clean up
1 parent 6524fa0 commit be66a43

File tree

14 files changed

+134
-209
lines changed

14 files changed

+134
-209
lines changed

.phpunit.result.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
C:30:"PHPUnit\Runner\TestResultCache":802:{a:2:{s:7:"defects";a:9:{s:7:"Warning";i:6;s:17:"HeroTest::testOne";i:3;s:18:"HeroTest::testHero";i:4;s:31:"GameTest::testFirstTurnFunction";i:4;s:28:"GameTest::testSkillsFunction";i:4;s:26:"GameTest::testLogsMessages";i:4;s:24:"HeroTest::testHeroUpdate";i:4;s:21:"MonsterTest::testHero";i:4;s:27:"MonsterTest::testHeroUpdate";i:4;}s:5:"times";a:12:{s:7:"Warning";d:0.008;s:17:"HeroTest::testOne";d:0.008;s:18:"HeroTest::testHero";d:0.045;s:24:"HeroTest::testHeroUpdate";d:0;s:31:"GameTest::testFirstTurnFunction";d:0.787;s:28:"GameTest::testSkillsFunction";d:0.027;s:26:"GameTest::testLogsMessages";d:0.037;s:21:"MonsterTest::testHero";d:0;s:27:"MonsterTest::testHeroUpdate";d:0;s:24:"MonsterTest::testMonster";d:0;s:30:"MonsterTest::testMonsterUpdate";d:0;s:28:"HeroTest::testSkillsFunction";d:0.04;}}}
1+
C:30:"PHPUnit\Runner\TestResultCache":802:{a:2:{s:7:"defects";a:9:{s:7:"Warning";i:6;s:17:"HeroTest::testOne";i:3;s:18:"HeroTest::testHero";i:4;s:31:"GameTest::testFirstTurnFunction";i:4;s:28:"GameTest::testSkillsFunction";i:4;s:26:"GameTest::testLogsMessages";i:4;s:24:"HeroTest::testHeroUpdate";i:4;s:21:"MonsterTest::testHero";i:4;s:27:"MonsterTest::testHeroUpdate";i:4;}s:5:"times";a:12:{s:7:"Warning";d:0.008;s:17:"HeroTest::testOne";d:0.008;s:18:"HeroTest::testHero";d:0.001;s:24:"HeroTest::testHeroUpdate";d:0;s:31:"GameTest::testFirstTurnFunction";d:0.031;s:28:"GameTest::testSkillsFunction";d:0.027;s:26:"GameTest::testLogsMessages";d:0.03;s:21:"MonsterTest::testHero";d:0;s:27:"MonsterTest::testHeroUpdate";d:0;s:24:"MonsterTest::testMonster";d:0;s:30:"MonsterTest::testMonsterUpdate";d:0;s:28:"HeroTest::testSkillsFunction";d:0.002;}}}

class/database.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2-
class DataBase {
3-
2+
class DataBase
3+
{
44
private $servername;
55
private $username;
66
private $password;
77
private $dbname;
88

9-
function __construct() {
9+
public function __construct()
10+
{
1011
$this->conn = false;
1112
$this->servername = "localhost";
1213
$this->username = "root";
@@ -15,14 +16,16 @@ function __construct() {
1516
$this->connectDB();
1617
}
1718

18-
function __destruct() {
19-
if($this->conn !== false){
20-
$this->conn->close();
19+
public function __destruct()
20+
{
21+
if ($this->conn !== false) {
22+
$this->conn->close();
2123
}
2224
}
2325

24-
private function connectDB(){
25-
if($this->conn === false){
26+
private function connectDB()
27+
{
28+
if ($this->conn === false) {
2629
$this->conn = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
2730
if ($this->conn->connect_error) {
2831
die("Connection failed: " .$this->conn->connect_error);
@@ -31,16 +34,16 @@ private function connectDB(){
3134
return $this->conn;
3235
}
3336

34-
public function runQuery($query){
37+
public function runQuery($query)
38+
{
3539
$resultArray = [];
3640
$result = $this->conn->query($query);
3741
if ($result->num_rows > 0) {
38-
while($row = $result->fetch_assoc()) {
39-
array_push($resultArray, $row);
42+
while ($row = $result->fetch_assoc()) {
43+
array_push($resultArray, $row);
4044
}
4145
return $resultArray;
42-
}
46+
}
4347
return $resultArray;
4448
}
45-
4649
}

class/gameEngineClass.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,50 @@
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-
?>

class/hero.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22

33
class Hero extends Player
44
{
5-
function skills(){
6-
5+
public function skills()
6+
{
77
$skills = (new DataBase)->runQuery(
88
'SELECT s.* FROM `hero` h
99
INNER JOIN heros_skills hs on hs.id_hero = h.id
1010
inner join skill s on s.id = hs.id_skill
1111
WHERE h.id = 1'
1212
);
1313

14-
foreach($skills as $skill){
15-
if(rand(0, 100) < $skills[0]['skill_chance']) { // check the chance of the skill to occur
14+
foreach ($skills as $skill) {
15+
if (rand(0, 100) < $skills[0]['skill_chance']) { // check the chance of the skill to occur
1616
return $skill;
1717
}
1818
}
1919

2020
return null;
2121
}
2222
}
23-
?>

class/heroBuild.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

class/logger.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2-
class Logger {
2+
class Logger
3+
{
34
private $log;
4-
static function getInstance()
5+
public static function getInstance()
56
{
6-
if (self::$instance == NULL) {
7+
if (self::$instance == null) {
78
self::$instance = new Logger();
89
}
910
return self::$instance;
@@ -13,17 +14,14 @@ private function __construct()
1314
}
1415
private function __clone()
1516
{
16-
1717
}
18-
function Log($str)
18+
public function Log($str)
1919
{
2020
$this->log .= $str;
2121
}
2222
public function getLog()
2323
{
24-
return $this->log;
24+
return $this->log;
2525
}
26-
static private $instance = NULL;
26+
private static $instance = null;
2727
}
28-
29-
?>

class/monster.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<?php
22
class Monster extends Player
33
{
4-
54
}
6-
?>

class/monsterBuild.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)