Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#! /usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
use ArcanusMundus; | ||
|
||
ArcanusMundus->new->start_game; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package ArcanusMundus; | ||
use Moose; | ||
use ArcanusMundus::Game; | ||
use ArcanusMundus::Schema; | ||
|
||
has schema => ( is => 'ro', required => 1, lazy => 1, build => '_build_schema' ); | ||
has schema => ( is => 'ro', required => 1, lazy => 1, builder => '_build_schema' ); | ||
|
||
sub _build_schema { ArcanusMundus::Schema->connect('dbi:SQLite:share/db/game.db') } | ||
|
||
sub start_game { | ||
my $self = shift; | ||
ArcanusMundus::Game->new->run($self->schema); | ||
} | ||
|
||
1; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package ArcanusMundus::Game; | ||
use Moose; | ||
|
||
has map_height => ( is => 'ro', required => 1, default => 100 ); | ||
has map_width => ( is => 'ro', required => 1, default => 100 ); | ||
has monster_count => ( is => 'ro', required => 1, default => 10 ); | ||
|
||
sub run { | ||
my ($self, $schema) = @_; | ||
|
||
$schema->resultset('Monster')->spawn($self->monster_count); | ||
|
||
} | ||
|
||
__PACKAGE__->meta->make_immutable; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ArcanusMundus::Schema::ResultSet; | ||
use strict; | ||
use warnings; | ||
use base 'DBIx::Class::ResultSet'; | ||
|
||
1; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ArcanusMundus::Schema::ResultSet::Monster; | ||
use base 'ArcanusMundus::Schema::ResultSet'; | ||
use strict; | ||
use warnings; | ||
|
||
sub spawn { | ||
my ( $self, $monster_count) = @_; | ||
|
||
my $monster_live_count = $self->search( | ||
undef, | ||
{ | ||
select => [ | ||
{ count => { distinct => 'name' } } | ||
], | ||
as => ['count'] | ||
} | ||
)->count; | ||
|
||
while ( ($monster_live_count++) < $monster_count ) { | ||
my $monster = $self->create({name => 'foo'})->insert; | ||
} | ||
} | ||
|
||
1; |