Skip to content

Commit

Permalink
dealer no longer has to type !join
Browse files Browse the repository at this point in the history
  • Loading branch information
scythe committed May 3, 2011
1 parent e89b17d commit 3fe6574
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions whist.pl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -166,31 +166,51 @@ sub handle_msgs {


if(substr($message,0,5) eq "!deal" and ($playing == 0 or $server->command("MSG $target We're already playing!") and 0)) { if(substr($message,0,5) eq "!deal" and ($playing == 0 or $server->command("MSG $target We're already playing!") and 0)) {
new_deck(); new_deck();
add_nick($nick, $server);
} }
if(substr($message,0,5) eq "!play" and ($playing == 1 or $server->command("MSG $target We haven't started yet!") and 0)) { if(substr($message,0,5) eq "!play" and ($playing == 1 or $server->command("MSG $target We haven't started yet!") and 0)) {
play_card(translate(substr($message, 6)), substr($nick,0,length($nick)), $server, $target); play_card(translate(substr($message, 6)), substr($nick,0,length($nick)), $server, $target);
} }
if(substr($message, 0, 5) eq "!join" and ($playing == 2 or $server->command("MSG $target You have to wait for the next game.") and 0)) { if(substr($message, 0, 5) eq "!join" and ($playing == 2 or $server->command("MSG $target You have to wait for the next game.") and 0)) {
$players[$numplayers] = $nick; add_nick($nick, $server);
$numplayers++;
my $hand = "";
for(my $i = ($numplayers - 1) * 13; $i < $numplayers * 13; $i++ ) {
$hand = $hand . untranslate($hands[$i]) . ", ";
}
$server->command("MSG $nick Your hand contains $hand ");
if($numplayers == 4) { if($numplayers == 4) {
$trick = 1; $trick = 1;
$turn = 0; $turn = 0;
@player_scores = qw(0 0 0 0); @player_scores = qw(0 0 0 0);
$playing = 1; $playing = 1;
$server->command("MSG $target trumps are " . untranslate($hands[51])); $trickstarter = 1;
$trumpsuit = $hands[51] % 4; $server->command("MSG $target trumps are " . untranslate($hands[48]));
$server->command("MSG " . $players[0] . " it's your turn."); $trumpsuit = $hands[48] % 4;
$server->command("MSG " . $players[1] . " it's your turn.");
}
}
if(substr($message, 0, 5) eq "!hand" and ($playing == 1 or $server->command("MSG $target We haven't started yet!") and 0)) {
for(my $pnum = 0; $pnum < 4; $pnum++) {
if($players[$pnum] eq $nick) {
my $hs = "";
for(my $cnum = 13 * $pnum; $cnum < 13 * ($pnum + 1); $cnum++) {
if($hands[$cnum] != -1) {
$hs = $hs . ", " . untranslate($hands[$cnum]);
}
}
print("Your hand is $hs");
}
} }
} }
#Irssi::print("server: $server data: $data nick: $nick address: $address"); #Irssi::print("server: $server data: $data nick: $nick address: $address");
} }


sub add_nick {
my ($nick, $server) = @_;
$players[$numplayers] = $nick;
$numplayers++;
my $hand = "";
for(my $i = ($numplayers - 1) * 13; $i < $numplayers * 13; $i++ ) {
$hand = $hand . untranslate($hands[$i]) . ", ";
}
$server->command("MSG $nick Your hand contains $hand ");
}

sub translate { # converts number / suit format to card numbers sub translate { # converts number / suit format to card numbers
my ($arg) = @_; my ($arg) = @_;
my ($num, $suit) = split(/\s+/, $arg); # cards must have number and suit separated by a space my ($num, $suit) = split(/\s+/, $arg); # cards must have number and suit separated by a space
Expand Down

0 comments on commit 3fe6574

Please sign in to comment.