Devel-PerlySense
view release on metacpan or search on metacpan
t/data/project-lib/Game/Application.pm view on Meta::CPAN
use Data::Dumper;
use Game::Controller;
use Game::UI;
use Game::Controller;
use Game::Object::Worm;
use Game::Object::Worm::Bot;
use Game::Object::Prize;
use Game::Object::Wall;
=head1 PROPERTIES
=head2 oUI
Game::UI object.
=cut
use Class::MethodMaker get_set => [ "oUI" ];
=head1 METHODS
=head2 new()
Create new Application.
=cut
sub new { my $pkg = shift;
my $self = {};
bless $self, $pkg;
$self->oUI( Game::UI->new($self) );
return($self);
}
=head2 runMain()
Run the Main menu, providing the user with e.g. options to
play.
Return 1 on success, else 0.
=cut
sub runMain { my $self = shift;
$self->oUI->runMainMenu($self);
return( 1 );
}
=head2 runGame()
Run the the Game, i.e. dispay a Lawn and start off the game.
Return 1 on success, else 0.
=cut
sub runGame {
my $self = shift;
my ($width, $height) = (74, 40);
my ($offsetLeft, $offsetTop) = (3, 1);
my $oController = Game::Controller->new($offsetLeft, $offsetTop, $width, $height);
$oController->oUI->soundsEnabled(1);
#Create worm
my ($wormLeft, $wormTop, $wormDirection, $wormLength) = (40, 10, "left", 15);
my $oWorm = Game::Object::Worm->new($wormLeft, $wormTop, $wormDirection, $wormLength);
$oController->placeWormOnLawn($oWorm);
my $oWormBot = Game::Object::Worm::Bot->new($wormLeft, $wormTop + 8, $wormDirection, $wormLength);
$oWormBot->oEventMove->timeInterval(0.12);
$oWormBot->probabilityTurnRandomly(0.04);
$oWormBot->probabilityTurnTowardsPrize(1.00);
$oController->placeWormBotOnLawn($oWormBot);
$oWormBot = Game::Object::Worm::Bot->new($wormLeft, $wormTop + 16, $wormDirection, $wormLength);
$oWormBot->probabilityTurnRandomly(0.07);
$oWormBot->probabilityTurnTowardsPrize(0.60);
$oController->placeWormBotOnLawn($oWormBot);
$oWormBot = Game::Object::Worm::Bot->new($wormLeft, $wormTop + 24, $wormDirection, $wormLength);
$oWormBot->probabilityTurnTowardsPrize(0.80);
$oController->placeWormBotOnLawn($oWormBot);
if(0) {
for my $i (1..3) {
$oWormBot = Game::Object::Worm::Bot->new($wormLeft - $i, $wormTop - 5 + ($i * 3), $wormDirection, $wormLength);
$oWormBot->probabilityTurnRandomly(0.07);
$oWormBot->probabilityTurnTowardsPrize(0.80);
$oWormBot->oEventMove->timeInterval(0.12);
$oController->placeWormBotOnLawn($oWormBot);
}
}
( run in 1.969 second using v1.01-cache-2.11-cpan-524268b4103 )