Permalink
Browse files

moved pay rent logic to Ownable pay_rent method, therefore, only Util…

…ity tiles now overrides this, while all others rely on same logic (laziness++)
  • Loading branch information...
1 parent 65627e2 commit 60704a617378b1f6283f81f22656838b80cffbb3 @jberger committed Nov 29, 2011
Showing with 15 additions and 19 deletions.
  1. +15 −19 lib/Games/Opoly/Board/Tile.pm
@@ -72,12 +72,20 @@ class Games::Opoly::Board::Tile::Ownable
$player->add_action({ 'Buy ($' . $self->price . ")" => sub{ $self->buy($player) } });
} else {
#The tiles are different in their action if owned, therefore call class specific action here
- $action = inner($player) unless $self->mortgaged;
+ unless ($self->mortgaged) {
+ $self->pay_rent($player);
+ $action = inner($player);
+ }
}
return $action if $action;
}
+ method pay_rent (Games::Opoly::Player $player) {
+ my $rent = $self->get_rent;
+ $player->must_pay($rent, $self->owner);
+ }
+
after leave (Games::Opoly::Player $player) {
#remove the buy action from the player's menu
$player->remove_action("Buy");
@@ -142,14 +150,6 @@ class Games::Opoly::Board::Tile::Property
return $rent;
}
- augment arrive (Games::Opoly::Player $player) {
- my $rent = $self->get_rent;
-
- $player->must_pay($rent, $self->owner);
-
- return 0;
- }
-
augment mortgage () {
my $collect = 0;
foreach my $tile ( @{ $self->group->tiles } ) {
@@ -181,19 +181,15 @@ class Games::Opoly::Board::Tile::Property
class Games::Opoly::Board::Tile::Railroad
extends Games::Opoly::Board::Tile::Ownable {
+ has 'rent' => ( isa => 'Num', is => 'ro', default => 25 );
+ has 'multiplier' => ( isa => 'Int', is => 'ro', default => 2 );
+
override get_rent () {
- my @rents = (25, 50, 100, 200);
- my $rent = $rents[
- $self->group->number_owned_by($self->owner) - 1
- ];
+ my $rent = $self->rent;
+ $rent *= $self->multiplier ** ( $self->group->number_owned_by($self->owner) - 1 );
return $rent;
}
- augment arrive (Games::Opoly::Player $player) {
- my $rent = $self->get_rent;
- $player->must_pay($rent, $self->owner);
- }
-
}
class Games::Opoly::Board::Tile::Utility
@@ -217,7 +213,7 @@ class Games::Opoly::Board::Tile::Utility
}
}
- augment arrive ( Games::Opoly::Player $player ) {
+ override pay_rent ( Games::Opoly::Player $player ) {
my ($rent, $roll, $multiplier) = $self->get_rent;
$player->ui->log(

0 comments on commit 60704a6

Please sign in to comment.