Skip to content

Commit

Permalink
Added some basic game logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
logie17 committed Aug 27, 2012
1 parent 9ce1d3d commit ffe3490
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
7 changes: 7 additions & 0 deletions bin/game.pl
@@ -0,0 +1,7 @@
#! /usr/bin/env perl

use strict;
use warnings;
use ArcanusMundus;

ArcanusMundus->new->start_game;
8 changes: 7 additions & 1 deletion lib/ArcanusMundus.pm
@@ -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;
15 changes: 15 additions & 0 deletions lib/ArcanusMundus/Game.pm
@@ -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;
6 changes: 6 additions & 0 deletions lib/ArcanusMundus/Schema/ResultSet.pm
@@ -0,0 +1,6 @@
package ArcanusMundus::Schema::ResultSet;
use strict;
use warnings;
use base 'DBIx::Class::ResultSet';

1;
24 changes: 24 additions & 0 deletions lib/ArcanusMundus/Schema/ResultSet/Monster.pm
@@ -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;

0 comments on commit ffe3490

Please sign in to comment.