Skip to content

Instantly share code, notes, and snippets.

@kirkbushell
Created March 11, 2016 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirkbushell/1fecc35efd38af600860 to your computer and use it in GitHub Desktop.
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?
<?php
class Player
{
public function upgrade(Building $building)
{
if (!$this->canAfford($building)) {
throw new DamnImBroke;
}
$this->deduct($building->upgradeCosts());
$building->upgrade();
}
}
<?php
class BuildingUpgrader
{
public function improve(Player $player, Building $building)
{
if (!$player->canAfford($building->upgradeCosts())) {
throw new DamnImBroke;
}
$player->deduct($building->upgradeCosts());
$building->upgrade();
}
}
<?php
class Building
{
publi function upgrade(Player $player)
{
if (!$player->canAfford($building->upgradeCosts())) {
throw new DamnImBroke;
}
$player->deduct($this->upgradeCosts());
$this->upgrade();
}
}
@hugo-dlb
Copy link

Hey kirk, I worked on a similar project and i'm interested of what you ended up doing.

Cheers,
Hugo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment