From ad18e30823df8fbce790d74e05810d528d8b0e54 Mon Sep 17 00:00:00 2001 From: Cyril HERON Date: Tue, 13 Jan 2015 14:54:43 +0100 Subject: [PATCH] d07 full --- d07/ex00/Tyrion.class.php | 14 ++++++ d07/ex01/Greyjoy.class.php | 7 +++ d07/ex02/Targaryen.class.php | 15 +++++++ d07/ex03/House.class.php | 9 ++++ d07/ex04/Jaime.class.php | 15 +++++++ d07/ex04/Lannister.class.php | 6 +++ d07/ex04/Tyrion.class.php | 15 +++++++ d07/ex05/IFighter.class.php | 7 +++ d07/ex05/NightsWatch.class.php | 14 ++++++ d07/ex06/Fighter.class.php | 15 +++++++ d07/ex06/UnholyFactory.class.php | 28 ++++++++++++ d07/misc/ex00/test.php | 21 +++++++++ d07/misc/ex01/Euron.class.php | 11 +++++ d07/misc/ex01/test1.php | 9 ++++ d07/misc/ex01/test2.php | 10 +++++ d07/misc/ex02/test.php | 20 +++++++++ d07/misc/ex03/test1.php | 35 +++++++++++++++ d07/misc/ex03/test2.php | 15 +++++++ d07/misc/ex04/test.php | 29 ++++++++++++ d07/misc/ex05/test1.php | 41 +++++++++++++++++ d07/misc/ex05/test2.php | 20 +++++++++ d07/misc/ex06/test1.php | 76 ++++++++++++++++++++++++++++++++ d07/misc/ex06/test2.php | 38 ++++++++++++++++ 23 files changed, 470 insertions(+) create mode 100644 d07/ex00/Tyrion.class.php create mode 100644 d07/ex01/Greyjoy.class.php create mode 100644 d07/ex02/Targaryen.class.php create mode 100644 d07/ex03/House.class.php create mode 100644 d07/ex04/Jaime.class.php create mode 100644 d07/ex04/Lannister.class.php create mode 100644 d07/ex04/Tyrion.class.php create mode 100644 d07/ex05/IFighter.class.php create mode 100644 d07/ex05/NightsWatch.class.php create mode 100644 d07/ex06/Fighter.class.php create mode 100644 d07/ex06/UnholyFactory.class.php create mode 100644 d07/misc/ex00/test.php create mode 100644 d07/misc/ex01/Euron.class.php create mode 100644 d07/misc/ex01/test1.php create mode 100644 d07/misc/ex01/test2.php create mode 100644 d07/misc/ex02/test.php create mode 100644 d07/misc/ex03/test1.php create mode 100644 d07/misc/ex03/test2.php create mode 100644 d07/misc/ex04/test.php create mode 100644 d07/misc/ex05/test1.php create mode 100644 d07/misc/ex05/test2.php create mode 100644 d07/misc/ex06/test1.php create mode 100644 d07/misc/ex06/test2.php diff --git a/d07/ex00/Tyrion.class.php b/d07/ex00/Tyrion.class.php new file mode 100644 index 0000000..6a4c8d4 --- /dev/null +++ b/d07/ex00/Tyrion.class.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/d07/ex02/Targaryen.class.php b/d07/ex02/Targaryen.class.php new file mode 100644 index 0000000..2a5c706 --- /dev/null +++ b/d07/ex02/Targaryen.class.php @@ -0,0 +1,15 @@ +resistsFire() == True) + return "emerges naked but unharmed"; + else + return "burns alive"; + } + public function resistsFire() { + return False; + } +} + +?> diff --git a/d07/ex03/House.class.php b/d07/ex03/House.class.php new file mode 100644 index 0000000..12f9433 --- /dev/null +++ b/d07/ex03/House.class.php @@ -0,0 +1,9 @@ +getHouseName() . " of " . $this->getHouseSeat() . " : \"" . $this->getHouseMotto() . "\"" . PHP_EOL); + } +} + +?> \ No newline at end of file diff --git a/d07/ex04/Jaime.class.php b/d07/ex04/Jaime.class.php new file mode 100644 index 0000000..650c7f8 --- /dev/null +++ b/d07/ex04/Jaime.class.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/d07/ex04/Lannister.class.php b/d07/ex04/Lannister.class.php new file mode 100644 index 0000000..8890669 --- /dev/null +++ b/d07/ex04/Lannister.class.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/d07/ex04/Tyrion.class.php b/d07/ex04/Tyrion.class.php new file mode 100644 index 0000000..197234f --- /dev/null +++ b/d07/ex04/Tyrion.class.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/d07/ex05/IFighter.class.php b/d07/ex05/IFighter.class.php new file mode 100644 index 0000000..0bed85d --- /dev/null +++ b/d07/ex05/IFighter.class.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/d07/ex05/NightsWatch.class.php b/d07/ex05/NightsWatch.class.php new file mode 100644 index 0000000..2015c22 --- /dev/null +++ b/d07/ex05/NightsWatch.class.php @@ -0,0 +1,14 @@ +fight() . PHP_EOL; + } + public function fight() { + print($_fight); + } +} + +?> \ No newline at end of file diff --git a/d07/ex06/Fighter.class.php b/d07/ex06/Fighter.class.php new file mode 100644 index 0000000..e6d1493 --- /dev/null +++ b/d07/ex06/Fighter.class.php @@ -0,0 +1,15 @@ +_name = $str; + return; + } + public function getName() { + return ($this->_name); + } + abstract public function fight( $target ); +} + +?> diff --git a/d07/ex06/UnholyFactory.class.php b/d07/ex06/UnholyFactory.class.php new file mode 100644 index 0000000..270ba04 --- /dev/null +++ b/d07/ex06/UnholyFactory.class.php @@ -0,0 +1,28 @@ +_absorbed ) ) + { + $this->_absorbed[ $rhs->getName() ] = $rhs; + print( "(Factory absorbed a fighter of type " . $rhs->getName() . ")" . PHP_EOL ); + } + else + print( "(Factory already absorbed a fighter of type " . $rhs->getName() . ")" . PHP_EOL ); + } + public function fabricate( $type ) { + if ( array_key_exists( $type, $this->_absorbed ) ) + { + print( "(Factory fabricates a fighter of type $type)" . PHP_EOL ); + return ( clone $this->_absorbed[$type] ); + } + else + print( "(Factory hasn't absorbed any fighter of type $type)" . PHP_EOL); + } +} \ No newline at end of file diff --git a/d07/misc/ex00/test.php b/d07/misc/ex00/test.php new file mode 100644 index 0000000..51bfe23 --- /dev/null +++ b/d07/misc/ex00/test.php @@ -0,0 +1,21 @@ +getSize() . PHP_EOL); +print($tyrion->houseMotto() . PHP_EOL); +?> diff --git a/d07/misc/ex01/Euron.class.php b/d07/misc/ex01/Euron.class.php new file mode 100644 index 0000000..ec0456c --- /dev/null +++ b/d07/misc/ex01/Euron.class.php @@ -0,0 +1,11 @@ +familyMotto . PHP_EOL); + } +} + +?> diff --git a/d07/misc/ex01/test1.php b/d07/misc/ex01/test1.php new file mode 100644 index 0000000..9c970da --- /dev/null +++ b/d07/misc/ex01/test1.php @@ -0,0 +1,9 @@ +announceMotto(); + +?> diff --git a/d07/misc/ex01/test2.php b/d07/misc/ex01/test2.php new file mode 100644 index 0000000..2d360ce --- /dev/null +++ b/d07/misc/ex01/test2.php @@ -0,0 +1,10 @@ +familyMotto . PHP_EOL); + +?> + diff --git a/d07/misc/ex02/test.php b/d07/misc/ex02/test.php new file mode 100644 index 0000000..ea176f6 --- /dev/null +++ b/d07/misc/ex02/test.php @@ -0,0 +1,20 @@ +getBurned() . PHP_EOL); +print("Daenerys " . $daenerys->getBurned() . PHP_EOL); + +?> diff --git a/d07/misc/ex03/test1.php b/d07/misc/ex03/test1.php new file mode 100644 index 0000000..144f275 --- /dev/null +++ b/d07/misc/ex03/test1.php @@ -0,0 +1,35 @@ +introduce(); +} + +?> diff --git a/d07/misc/ex03/test2.php b/d07/misc/ex03/test2.php new file mode 100644 index 0000000..58f52fe --- /dev/null +++ b/d07/misc/ex03/test2.php @@ -0,0 +1,15 @@ +introduce(); + +?> + diff --git a/d07/misc/ex04/test.php b/d07/misc/ex04/test.php new file mode 100644 index 0000000..0ac9e86 --- /dev/null +++ b/d07/misc/ex04/test.php @@ -0,0 +1,29 @@ +sleepWith($t); +$j->sleepWith($s); +$j->sleepWith($c); + +$t->sleepWith($j); +$t->sleepWith($s); +$t->sleepWith($c); + +?> diff --git a/d07/misc/ex05/test1.php b/d07/misc/ex05/test1.php new file mode 100644 index 0000000..b52f09f --- /dev/null +++ b/d07/misc/ex05/test1.php @@ -0,0 +1,41 @@ +recruit($jon); +$nw->recruit($aemon); +$nw->recruit($sam); + +$nw->fight(); + +?> diff --git a/d07/misc/ex05/test2.php b/d07/misc/ex05/test2.php new file mode 100644 index 0000000..b3c664b --- /dev/null +++ b/d07/misc/ex05/test2.php @@ -0,0 +1,20 @@ +recruit($varys); + +$nw->fight(); + +?> + diff --git a/d07/misc/ex06/test1.php b/d07/misc/ex06/test1.php new file mode 100644 index 0000000..8839beb --- /dev/null +++ b/d07/misc/ex06/test1.php @@ -0,0 +1,76 @@ +absorb(new Footsoldier()); +$uf->absorb(new Footsoldier()); +$uf->absorb(new Archer()); +$uf->absorb(new Assassin()); +$uf->absorb(new Llama()); + +$requested_fighters = Array( + "foot soldier", + "llama", + "foot soldier", + "archer", + "foot soldier", + "assassin", + "foot soldier", + "archer", +); + +$actual_fighters = Array( +); + +foreach ($requested_fighters as $rf) { + $f = $uf->fabricate($rf); + if ($f != null) { + array_push($actual_fighters, $f); + } +} + +$targets = Array("the Hound", "Tyrion", "Podrick"); + +foreach ($actual_fighters as $f) { + foreach ($targets as $t) { + $f->fight($t); + } +} diff --git a/d07/misc/ex06/test2.php b/d07/misc/ex06/test2.php new file mode 100644 index 0000000..e35f574 --- /dev/null +++ b/d07/misc/ex06/test2.php @@ -0,0 +1,38 @@ +absorb(new CrippledSoldier()); + +$requested_fighters = Array( + "crippled soldier", + "crippled soldier", + "crippled soldier", + "crippled soldier", +); + +$actual_fighters = Array( +); + +foreach ($requested_fighters as $rf) { + $f = $uf->fabricate($rf); + if ($f != null) { + array_push($actual_fighters, $f); + } +} + +$targets = Array("the Hound", "Tyrion", "Podrick"); + +foreach ($actual_fighters as $f) { + foreach ($targets as $t) { + $f->fight($t); + } +}