forked from iTzDyms/PiscinePHP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cyril HERON
committed
Jan 13, 2015
1 parent
f7a7a05
commit ad18e30
Showing
23 changed files
with
470 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
class Tyrion extends Lannister { | ||
public function __construct() { | ||
parent::__construct(); | ||
print("My name is Tyrion" . PHP_EOL); | ||
} | ||
public function getSize() { | ||
return "Short"; | ||
} | ||
public function houseMotto() { | ||
return "Hear me roar!"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?PHP | ||
|
||
class Greyjoy { | ||
protected $familyMotto = "We do not sow"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?PHP | ||
|
||
class Targaryen { | ||
public function getBurned() { | ||
if ( $this->resistsFire() == True) | ||
return "emerges naked but unharmed"; | ||
else | ||
return "burns alive"; | ||
} | ||
public function resistsFire() { | ||
return False; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
class House { | ||
public function introduce() { | ||
print( "House " . $this->getHouseName() . " of " . $this->getHouseSeat() . " : \"" . $this->getHouseMotto() . "\"" . PHP_EOL); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?PHP | ||
|
||
class Jaime { | ||
public function sleepWith( $rhs ) { | ||
$class = get_class( $rhs ); | ||
if ( $class == "Tyrion" ) | ||
print("Not even if I'm drunk" . PHP_EOL); | ||
else if ( $class == "Sansa") | ||
print("Let's do this" . PHP_EOL); | ||
else if ( $class == "Cersei") | ||
print("With pleasure, but only in a tower in Winterfell, then." . PHP_EOL); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?PHP | ||
|
||
class Lannister { | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?PHP | ||
|
||
class Tyrion { | ||
public function sleepWith( $rhs ) { | ||
$class = get_class( $rhs ); | ||
if ( $class == "Jaime" ) | ||
print("Not even if I'm drunk" . PHP_EOL); | ||
else if ( $class == "Sansa") | ||
print("Let's do this" . PHP_EOL); | ||
else if ( $class == "Cersei") | ||
print("Not even if I'm drunk" . PHP_EOL); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?PHP | ||
|
||
interface IFighter { | ||
function fight(); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?PHP | ||
|
||
class NightsWatch implements IFighter { | ||
private $_fight; | ||
public function recruit( $rhs ) { | ||
if ( method_exists( $rhs, 'fight' ) ) | ||
$_fight = $rhs->fight() . PHP_EOL; | ||
} | ||
public function fight() { | ||
print($_fight); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?PHP | ||
|
||
abstract class Fighter { | ||
protected $_name; | ||
public function __construct( $str ) { | ||
$this->_name = $str; | ||
return; | ||
} | ||
public function getName() { | ||
return ($this->_name); | ||
} | ||
abstract public function fight( $target ); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?PHP | ||
|
||
class Unholyfactory { | ||
private $_absorbed = array(); | ||
public function absorb( $rhs ) { | ||
if ( get_parent_class( $rhs ) != 'Fighter' ) | ||
{ | ||
print( "(Factory can't absorb this, it's not a fighter)" . PHP_EOL ); | ||
return ; | ||
} | ||
if ( !in_array( $rhs, $this->_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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
class Lannister { | ||
public function __construct() { | ||
print("A Lannister is born !" . PHP_EOL); | ||
} | ||
public function getSize() { | ||
return "Average"; | ||
} | ||
public function houseMotto() { | ||
return "Hear me roar!"; | ||
} | ||
} | ||
|
||
include('Tyrion.class.php'); | ||
|
||
$tyrion = new Tyrion(); | ||
|
||
print($tyrion->getSize() . PHP_EOL); | ||
print($tyrion->houseMotto() . PHP_EOL); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
include('Greyjoy.class.php'); | ||
|
||
class Euron extends Greyjoy { | ||
public function announceMotto() { | ||
print($this->familyMotto . PHP_EOL); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
include('Euron.class.php'); | ||
|
||
$euron = new Euron(); | ||
|
||
$euron->announceMotto(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
include('Euron.class.php'); | ||
|
||
$euron = new Euron(); | ||
|
||
print($euron->familyMotto . PHP_EOL); | ||
|
||
?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
include('Targaryen.class.php'); | ||
|
||
class Viserys extends Targaryen { | ||
} | ||
|
||
class Daenerys extends Targaryen { | ||
public function resistsFire() { | ||
return True; | ||
} | ||
} | ||
|
||
$viserys = new Viserys(); | ||
$daenerys = new Daenerys(); | ||
|
||
print("Viserys " . $viserys->getBurned() . PHP_EOL); | ||
print("Daenerys " . $daenerys->getBurned() . PHP_EOL); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
include('House.class.php'); | ||
|
||
class HouseStark extends House { | ||
public function getHouseName() { | ||
return "Stark"; | ||
} | ||
public function getHouseMotto() { | ||
return "Winter is coming"; | ||
} | ||
public function getHouseSeat() { | ||
return "Winterfell"; | ||
} | ||
} | ||
|
||
class HouseMartell extends House { | ||
public function getHouseName() { | ||
return "Martell"; | ||
} | ||
public function getHouseMotto() { | ||
return "Unbowed, Unbent, Unbroken"; | ||
} | ||
public function getHouseSeat() { | ||
return "Sunspear"; | ||
} | ||
} | ||
|
||
$houses = Array(new HouseStark(), new HouseMartell()); | ||
|
||
foreach ($houses as $house) { | ||
$house->introduce(); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
include('House.class.php'); | ||
|
||
class DrHouse extends House { | ||
public function diagnose() { | ||
print("It's not lupus !" . PHP_EOL); | ||
} | ||
} | ||
|
||
$house = new DrHouse(); | ||
$house->introduce(); | ||
|
||
?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
include_once('Lannister.class.php'); | ||
include_once('Jaime.class.php'); | ||
include_once('Tyrion.class.php'); | ||
|
||
class Stark { | ||
} | ||
|
||
class Cersei extends Lannister { | ||
} | ||
|
||
class Sansa extends Stark { | ||
} | ||
|
||
$j = new Jaime(); | ||
$c = new Cersei(); | ||
$t = new Tyrion(); | ||
$s = new Sansa(); | ||
|
||
$j->sleepWith($t); | ||
$j->sleepWith($s); | ||
$j->sleepWith($c); | ||
|
||
$t->sleepWith($j); | ||
$t->sleepWith($s); | ||
$t->sleepWith($c); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
include_once('IFighter.class.php'); | ||
include_once('NightsWatch.class.php'); | ||
|
||
class JonSnow implements IFighter { | ||
public function fight() { | ||
print("* looses his wolf on the enemy, and charges with courage *" . PHP_EOL); | ||
} | ||
public function isABastard() { | ||
return True; | ||
} | ||
} | ||
|
||
class MaesterAemon { | ||
public function sendRavens() { | ||
print("* sends a raven carrying an important message *" . PHP_EOL); | ||
} | ||
} | ||
|
||
class SamwellTarly implements IFighter { | ||
public function fight() { | ||
print("* flees, finds a girl, grows a spine, and defends her to the bitter end *" . PHP_EOL); | ||
} | ||
public function makeHisFatherProud() { | ||
return False; | ||
} | ||
} | ||
|
||
$jon = new JonSnow(); | ||
$aemon = new MaesterAemon(); | ||
$sam = new SamwellTarly(); | ||
$nw = new NightsWatch(); | ||
|
||
$nw->recruit($jon); | ||
$nw->recruit($aemon); | ||
$nw->recruit($sam); | ||
|
||
$nw->fight(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
include_once('IFighter.class.php'); | ||
include_once('NightsWatch.class.php'); | ||
|
||
class Varys implements IFighter { | ||
public function pretendToFight() { | ||
print("* finds someone to fight for him *" . PHP_EOL); | ||
} | ||
} | ||
|
||
$varys = new Varys(); | ||
$nw = new NightsWatch(); | ||
|
||
$nw->recruit($varys); | ||
|
||
$nw->fight(); | ||
|
||
?> | ||
|
Oops, something went wrong.