Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: polettix/narsil-core
base: 089e2da9fc
...
head fork: polettix/narsil-core
compare: 5f5efbdae7
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 28 additions and 1 deletion.
  1. +21 −0 lib/Narsil/Game.pm
  2. +7 −1 lib/Narsil/Match.pm
21 lib/Narsil/Game.pm
View
@@ -7,6 +7,7 @@ use English qw( -no_match_vars );
use Try::Tiny;
use Moo;
use 5.012;
+use List::Util qw< shuffle >;
extends 'Narsil::Object';
@@ -107,8 +108,28 @@ sub calculate_move_application {
die 'unimplemented';
}
+sub allowed_number_of_users {
+ return 2;
+}
+
sub calculate_join_application {
my ($self, $match, $join) = @_;
+
+ die {reason => 'not accepting players'}
+ unless $match->is_gathering();
+
+ my $userid = $join->userid();
+ if (!$match->is_participant($userid)) {
+ $match->add_participant($userid);
+ my @participants = $match->participants();
+ if (scalar(@participants) == $self->allowed_number_of_users()) {
+ $match->phase('active');
+ $match->participants(@participants = shuffle @participants);
+ $match->add_mover($participants[0]);
+ } ## end if (scalar(@participants...
+ } ## end if (!$match->is_participant...
+
+ return $match;
die 'unimplemented';
}
8 lib/Narsil/Match.pm
View
@@ -149,10 +149,16 @@ sub _flagify {
sub participants {
my $self = shift;
my $p = $self->_participants();
- @$p = [@_] if @_;
+ @$p = @_ if @_;
return @$p;
} ## end sub participants
+sub set_participants {
+ my $self = shift;
+ @{$self->_participants()} = @_;
+ return $self;
+}
+
sub add_participant {
my ($self, $userid) = @_;
push @{$self->_participants()}, $userid;

No commit comments for this range

Something went wrong with that request. Please try again.