Skip to content
Browse files

provided default calculate_join_application

  • Loading branch information...
1 parent 089e2da commit 1e6409283acce037689a1e6f7cf56c17a5e35423 @polettix committed Sep 30, 2012
Showing with 19 additions and 0 deletions.
  1. +19 −0 lib/Narsil/Game.pm
View
19 lib/Narsil/Game.pm
@@ -107,8 +107,27 @@ 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->add_mover($participants[rand @participants]);
+ } ## end if (scalar(@participants...
+ } ## end if (!$match->is_participant...
+
+ return $match;
die 'unimplemented';
}

0 comments on commit 1e64092

Please sign in to comment.
Something went wrong with that request. Please try again.