Skip to content

Commit 6524fa0

Browse files
set factory class functions
1 parent 622a2e2 commit 6524fa0

File tree

5 files changed

+136
-50
lines changed

5 files changed

+136
-50
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.001;s:24:"HeroTest::testHeroUpdate";d:0;s:31:"GameTest::testFirstTurnFunction";d:0.018;s:28:"GameTest::testSkillsFunction";d:0.027;s:26:"GameTest::testLogsMessages";d:0.04;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.004;}}}
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;}}}

class/heroBuild.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
class buildHeroClass extends Hero {
3+
4+
public function buildHero(){
5+
$db = new DataBase;
6+
$heroDB = $db->runQuery(
7+
'SELECT * FROM hero where id=1'
8+
);
9+
$statsHero = $db->runQuery(
10+
'SELECT *
11+
FROM `attributes_max_min`
12+
WHERE subject_type="hero" and subject_id='.$heroDB[0]['id']
13+
);
14+
$stats = $this->getDBStats($statsHero);
15+
$this->setId($heroDB[0]['id']);
16+
$this->setLevel($heroDB[0]['level']);
17+
$this->setExperience($heroDB[0]['experience']);
18+
$this->setName($heroDB[0]['name']);
19+
$this->setHealth($stats['health']);
20+
$this->setStrength($stats['strength']);
21+
$this->setDefence($stats['defence']);
22+
$this->setSpeed($stats['speed']);
23+
$this->setLuck($stats['luck']);
24+
$this->setStats($statsHero);
25+
return $this;
26+
}
27+
28+
public function getDBStats($statsHero){
29+
$stats = [
30+
'health' => 0,
31+
'strength' => 0,
32+
'defence' => 0,
33+
'speed' => 0,
34+
'luck' => 0,
35+
];
36+
foreach($statsHero as $stat){
37+
$stats[$stat['subject_attribute']] = rand($stat['min'], $stat['max']);
38+
}
39+
return $stats;
40+
}
41+
}
42+
?>

class/monsterBuild.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
class buildMonsterClass extends Monster {
4+
5+
public function buildMonster($id = 1){
6+
$db = new DataBase;
7+
$monster_DB = $db->runQuery(
8+
'SELECT * FROM monster where id=1'
9+
);
10+
$stats_monster = $db->runQuery(
11+
'SELECT *
12+
FROM `attributes_max_min`
13+
WHERE subject_type="monster" and subject_id='.$monster_DB[0]['id']
14+
);
15+
$stats = $this->getDBStats($stats_monster);
16+
$this->setId($monster_DB[0]['id']);
17+
$this->setLevel($monster_DB[0]['level']);
18+
$this->setExperience($monster_DB[0]['experience']);
19+
$this->setName($monster_DB[0]['name']);
20+
$this->setHealth($stats['health']);
21+
$this->setStrength($stats['strength']);
22+
$this->setDefence($stats['defence']);
23+
$this->setSpeed($stats['speed']);
24+
$this->setLuck($stats['luck']);
25+
$this->setStats($stats_monster);
26+
return $this;
27+
}
28+
29+
public function getDBStats($statsMonster){
30+
$stats = [
31+
'health' => 0,
32+
'strength' => 0,
33+
'defence' => 0,
34+
'speed' => 0,
35+
'luck' => 0,
36+
];
37+
foreach($statsMonster as $stat){
38+
$stats[$stat['subject_attribute']] = rand($stat['min'], $stat['max']);
39+
}
40+
return $stats;
41+
}
42+
}
43+
?>

class/player.php

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -93,52 +93,5 @@ public function setStats($stats){
9393
$this->stats = $stats;
9494
}
9595

96-
public function getDBResults($player, $player_id=1){
97-
98-
$db = new DataBase;
99-
100-
$player_DB = $db->runQuery(
101-
'SELECT * FROM '.$player.' where id=' . $player_id
102-
);
103-
104-
$this->setId($player_DB[0]['id']);
105-
$this->setLevel($player_DB[0]['level']);
106-
$this->setExperience($player_DB[0]['experience']);
107-
$this->setName($player_DB[0]['name']);
108-
109-
return $this;
110-
}
111-
112-
public function getDBStats($player){
113-
114-
$db = new DataBase;
115-
116-
$stats_player = $db->runQuery(
117-
'SELECT *
118-
FROM `attributes_max_min`
119-
WHERE subject_type="'.$player.'" and subject_id='.$this->getId()
120-
);
121-
122-
$stats = [
123-
'health' => 0,
124-
'strength' => 0,
125-
'defence' => 0,
126-
'speed' => 0,
127-
'luck' => 0,
128-
];
129-
130-
foreach($stats_player as $stat){
131-
$stats[$stat['subject_attribute']] = rand($stat['min'], $stat['max']);
132-
}
133-
134-
$this->setHealth($stats['health']);
135-
$this->setStrength($stats['strength']);
136-
$this->setDefence($stats['defence']);
137-
$this->setSpeed($stats['speed']);
138-
$this->setLuck($stats['luck']);
139-
$this->setStats($stats_player);
140-
141-
return $this;
142-
}
14396
}
14497
?>

class/playerFactory.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,60 @@ public function createPlayer($player, $player_id=1){
99
$player_obj = new Monster();
1010
}
1111

12-
$player_obj->getDBResults($player, $player_id);
13-
$player_obj->getDBStats($player);
12+
$player_obj = $this->getDBResults($player_obj, $player, $player_id);
13+
$player_obj = $this->getDBStats($player_obj, $player);
1414

1515
return $player_obj;
1616

1717
}
1818

19+
public function getDBResults($player_obj, $player, $player_id=1){
20+
21+
$db = new DataBase;
22+
23+
$player_DB = $db->runQuery(
24+
'SELECT * FROM '.$player.' where id=' . $player_id
25+
);
26+
27+
$player_obj->setId($player_DB[0]['id']);
28+
$player_obj->setLevel($player_DB[0]['level']);
29+
$player_obj->setExperience($player_DB[0]['experience']);
30+
$player_obj->setName($player_DB[0]['name']);
31+
32+
return $player_obj;
33+
}
34+
35+
public function getDBStats($player_obj, $player){
36+
37+
$db = new DataBase;
38+
39+
$stats_player = $db->runQuery(
40+
'SELECT *
41+
FROM `attributes_max_min`
42+
WHERE subject_type="'.$player.'" and subject_id='.$player_obj->getId()
43+
);
44+
45+
$stats = [
46+
'health' => 0,
47+
'strength' => 0,
48+
'defence' => 0,
49+
'speed' => 0,
50+
'luck' => 0,
51+
];
52+
53+
foreach($stats_player as $stat){
54+
$stats[$stat['subject_attribute']] = rand($stat['min'], $stat['max']);
55+
}
56+
57+
$player_obj->setHealth($stats['health']);
58+
$player_obj->setStrength($stats['strength']);
59+
$player_obj->setDefence($stats['defence']);
60+
$player_obj->setSpeed($stats['speed']);
61+
$player_obj->setLuck($stats['luck']);
62+
$player_obj->setStats($stats_player);
63+
64+
return $player_obj;
65+
}
66+
1967
}
2068
?>

0 commit comments

Comments
 (0)