Created
March 11, 2016 14:43
-
-
Save kirkbushell/1fecc35efd38af600860 to your computer and use it in GitHub Desktop.
The question is - does Player upgrade buildings, or does a service do this, or does the building upgrade itself and deduct costs from Player?
This file contains hidden or 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
<?php | |
class Player | |
{ | |
public function upgrade(Building $building) | |
{ | |
if (!$this->canAfford($building)) { | |
throw new DamnImBroke; | |
} | |
$this->deduct($building->upgradeCosts()); | |
$building->upgrade(); | |
} | |
} |
This file contains hidden or 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
<?php | |
class BuildingUpgrader | |
{ | |
public function improve(Player $player, Building $building) | |
{ | |
if (!$player->canAfford($building->upgradeCosts())) { | |
throw new DamnImBroke; | |
} | |
$player->deduct($building->upgradeCosts()); | |
$building->upgrade(); | |
} | |
} |
This file contains hidden or 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
<?php | |
class Building | |
{ | |
publi function upgrade(Player $player) | |
{ | |
if (!$player->canAfford($building->upgradeCosts())) { | |
throw new DamnImBroke; | |
} | |
$player->deduct($this->upgradeCosts()); | |
$this->upgrade(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey kirk, I worked on a similar project and i'm interested of what you ended up doing.
Cheers,
Hugo.