Skip to content

Commit

Permalink
d07 full
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril HERON committed Jan 13, 2015
1 parent f7a7a05 commit ad18e30
Show file tree
Hide file tree
Showing 23 changed files with 470 additions and 0 deletions.
14 changes: 14 additions & 0 deletions d07/ex00/Tyrion.class.php
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!";
}
}
7 changes: 7 additions & 0 deletions d07/ex01/Greyjoy.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?PHP

class Greyjoy {
protected $familyMotto = "We do not sow";
}

?>
15 changes: 15 additions & 0 deletions d07/ex02/Targaryen.class.php
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;
}
}

?>
9 changes: 9 additions & 0 deletions d07/ex03/House.class.php
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);
}
}

?>
15 changes: 15 additions & 0 deletions d07/ex04/Jaime.class.php
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);
}
}

?>
6 changes: 6 additions & 0 deletions d07/ex04/Lannister.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?PHP

class Lannister {
}

?>
15 changes: 15 additions & 0 deletions d07/ex04/Tyrion.class.php
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);
}
}

?>
7 changes: 7 additions & 0 deletions d07/ex05/IFighter.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?PHP

interface IFighter {
function fight();
}

?>
14 changes: 14 additions & 0 deletions d07/ex05/NightsWatch.class.php
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);
}
}

?>
15 changes: 15 additions & 0 deletions d07/ex06/Fighter.class.php
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 );
}

?>
28 changes: 28 additions & 0 deletions d07/ex06/UnholyFactory.class.php
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);
}
}
21 changes: 21 additions & 0 deletions d07/misc/ex00/test.php
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);
?>
11 changes: 11 additions & 0 deletions d07/misc/ex01/Euron.class.php
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);
}
}

?>
9 changes: 9 additions & 0 deletions d07/misc/ex01/test1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

include('Euron.class.php');

$euron = new Euron();

$euron->announceMotto();

?>
10 changes: 10 additions & 0 deletions d07/misc/ex01/test2.php
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);

?>

20 changes: 20 additions & 0 deletions d07/misc/ex02/test.php
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);

?>
35 changes: 35 additions & 0 deletions d07/misc/ex03/test1.php
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();
}

?>
15 changes: 15 additions & 0 deletions d07/misc/ex03/test2.php
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();

?>

29 changes: 29 additions & 0 deletions d07/misc/ex04/test.php
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);

?>
41 changes: 41 additions & 0 deletions d07/misc/ex05/test1.php
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();

?>
20 changes: 20 additions & 0 deletions d07/misc/ex05/test2.php
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();

?>

Loading

0 comments on commit ad18e30

Please sign in to comment.