exit();
}
+global $GAME,$RULES,$CARDS;
+
/* user might get here by clicking on the link in an email, so session might not be set */
if(isset($_SESSION["name"]))
output_status($_SESSION["name"]);
$GT = $gametype." ".$GT;
}
-/* does anyone have both foxes */
-$GAME["schweinchen"]=0;
-for($i=1;$i<5;$i++)
+/* do we need to worry about Schweinchen?
+ * check gametype and rules
+ * if yes, figure out if someone actually has Schweinchen
+ * save information in $GAME
+ */
+$ok=0;
+if( $gamestatus == 'pre' )
{
- $hash = DB_get_hash_from_game_and_pos($gameid,$i);
- $cards = DB_get_all_hand($hash);
- if( in_array("19",$cards) && in_array("20",$cards) )
- {
- $GAME["schweinchen"]=1;
- $GAME["schweinchen-who"]=$hash;
- }
- };
+ /* always need to use Schweinchen to figure out for example who has poverty */
+ $ok=1;
+ }
+else
+ {
+ /* in a game Schweinchen is not valid in all types of games */
+ if( $gametype == 'normal' || $gametype == 'silent' || $gametype=='trump' )
+ if( in_array($RULES['schweinchen'],array('both','second','secondaftercall')) )
+ $ok=1;
+ }
+
+/* these are the defaults */
+$GAME['schweinchen-who'] = NULL;
+$GAME['schweinchen-first'] = NULL;
+$GAME['schweinchen-second'] = NULL;
+
+if($ok)
+{
+ /* need to check for Schweinchen */
+ for($i=1;$i<5;$i++)
+ {
+ $hash = DB_get_hash_from_game_and_pos($gameid,$i);
+ $cards = DB_get_all_hand($hash);
+ if( in_array("19",$cards) && in_array("20",$cards) )
+ $GAME['schweinchen-who']=$hash;
+ };
+ $GAME['schweinchen-first'] = 0; /* to keep track if they have been played already */
+ $GAME['schweinchen-second'] = 0;
+}
+/* end check for Schweinchen */
+
+/* set the $CARDS variable, needed for sorting the cards
+ * we set it to normal so that the pre-game phase is handled ok
+ * and later set it to the correct game type that is played
+ */
+set_gametype('normal');
/* put everyting in a form */
echo "<form action=\"index.php?action=game&me=$me\" method=\"post\">\n";
/* whos turn is it? */
DB_set_player_by_gameid($gameid,$user);
$ok = 0;
+ break;
}
};
if($ok)
case 'init':
/* here we ask the player if he is sick */
$mycards = DB_get_hand($me);
- sort($mycards);
+ $mycards = mysort($mycards,$gametype);
/* output sickness of other playes, in case the already selected and are sitting in front of the current player */
echo "\n<ul class=\"tricks\">\n";
}
else if($_REQUEST["wedding"] == "yes")
{
- /* TODO: add silent solo somewhere*/
+ /* silent solo is set further down */
echo "Ok, you don't want to play a silent solo...wedding was chosen.<br />\n";
DB_set_sickness_by_hash($me,"wedding");
}
if($mystatus=='check')
{
$mycards = DB_get_hand($me);
- sort($mycards);
+ $mycards = mysort($mycards,$gametype);
/* output sickness of other playes, in case the already selected and are sitting in front of the current player */
echo "\n<ul class=\"tricks\">\n";
{
$ok = 0;
DB_set_player_by_gameid($gameid,$user);
+ break;
}
};
* poverty: set re/contra
* dpoverty: first time: set re, send email to second player
* second time: set contra
+ * poverty: set status of other players to 'play'
* set status to play in case 0 trump
* no -> set status to play,
* ask next player or cancle the game if no more players
" WHERE hand_id='$myhand' AND card_id=".DB_quote_smart($exchange));
};
}
+
/* update hand */
$mycards = DB_get_hand($me);
$mycards = mysort($mycards,$gametype);
{
/* user is done, ready to play */
DB_set_hand_status_by_hash($me,'play');
- /* TODO if resolved; email start player, set startplayer */
+
+ /* email start player */
+ $startplayer = DB_get_startplayer_by_gameid($gameid);
+ $email = DB_get_email('position-gameid',$startplayer,$gameid);
+ $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
+ $who = DB_get_userid('email',$email);
+ DB_set_player_by_gameid($gameid,$who);
+
+ if($hash!=$me)
+ {
+ if(DB_get_email_pref_by_hash($hash)!="emailaddict")
+ {
+ /* email startplayer */
+ $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
+ "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
+ mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
+ }
+ }
+ else
+ echo " Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br />\n";
}
/* the following is part A) of what needs to be done */
/* copy trump from player A to B */
$result = DB_query("UPDATE Hand_Card SET hand_id='$myhand' WHERE hand_id='$userhand' AND card_id<'27'" );
+ /* reload cards */
$mycards = DB_get_hand($me);
/* set re/contra */
{
$hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
if($hash==$userhash||$hash==$me)
- DB_set_party_by_hash($hash,"re");
+ {
+ DB_set_party_by_hash($hash,"re");
+ }
else
- DB_set_party_by_hash($hash,"contra");
+ {
+ DB_set_party_by_hash($hash,"contra");
+ DB_set_hand_status_by_hash($hash,'play'); /* the contra party is ready to play */
+ }
}
- /* check if we are done, if so, send everyone into the 'play' phase */
+ /* check if we are done (in case of no trump handed over), if so, go to 'play' phase right away*/
if(count($mycards)==12)
{
- foreach($userids as $user)
- {
- $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
- DB_set_hand_status_by_hash($hash,'play');
- }
+ DB_set_hand_status_by_hash($me,'play');
}
}
else /*dpoverty*/
{
$ok = 0;
DB_set_player_by_gameid($gameid,$user);
+ break;
}
}
if($ok)
$user = $r[6];
/* check if first schweinchen has been played */
- if( $GAME["schweinchen"] && ($r[0] == 19 || $r[0] == 20) )
- $GAME["schweinchen"]++;
+ if( $GAME['schweinchen-who'] && ($r[0] == 19 || $r[0] == 20) )
+ if(!$GAME['schweinchen-first'])
+ $GAME['schweinchen-first'] = 1; /* playing the first fox */
+ else
+ $GAME['schweinchen-second'] = 1; /* this must be the second fox */
/* save card to be able to find the winner of the trick later */
$play[$seq] = array("card"=>$r[0],"pos"=>$pos);
{
$card = $_REQUEST["card"];
$handid = DB_get_handid('hash',$me);
+ $commentSchweinchen =""; /* used to add a comment when Schweinchen is being played */
/* check if we have card and that we haven't played it yet*/
/* set played in hand_card to true where hand_id and card_id*/
$playid = DB_play_card($trickid,$handcardid,$sequence);
- /* check special output for schweinchen in case:
- * schweinchen is in the rules, a fox has been played and the gametype is correct
+ /* check special output for schweinchen in case in case a fox is being played
+ * check for correct rules, etc. has already been done
*/
- if( $GAME["schweinchen"] &&
- ($card == 19 || $card == 20) &&
- ($gametype == "normal" || $gametype == "silent"|| $gametype=="trump"))
+ if( $GAME["schweinchen-who"] && ($card == 19 || $card == 20) )
{
- $GAME["schweinchen"]++; // count how many have been played including this one
- if($GAME["schweinchen"]==3 && $RULES["schweinchen"]=="second" )
- DB_insert_comment("Schweinchen! ",$playid,$myid);
- if($RULES["schweinchen"]=="both" )
- DB_insert_comment("Schweinchen! ",$playid,$myid);
+ if(!$GAME['schweinchen-first'])
+ $GAME['schweinchen-first'] = 1; /* playing the first fox */
+ else
+ $GAME['schweinchen-second'] = 1; /* this must be the second fox */
+
+ if( ($GAME['schweinchen-second']==1 && $RULES['schweinchen']=='second') || $RULES['schweinchen']=='both')
+ {
+ DB_insert_comment("Schweinchen! ",$playid,$myid);
+ $commentSchweinchen = "Schweinchen! ";
+ }
if ($debug)
- echo "schweinchen = ".$GAME["schweinchen"]." ---<br />";
+ echo "schweinchen = ".$GAME["schweinchen-who"]." ---<br />";
}
/* if sequence == 4 check who one in case of wedding */
$comment = $_REQUEST["comment"];
if($comment != "")
DB_insert_comment($comment,$playid,$myid);
+ if($commentSchweinchen)
+ $comment = $commentSchweinchen . $comment;
};
/* check for note */
foreach($mycards as $card)
{
- if($followsuit && !same_type($card,$firstcard))
+ if( ($followsuit && !same_type($card,$firstcard)) ||
+ ( (int)($card)==19 && ($RULES['schweinchen']=='second'||$RULES['schweinchen']=='secondaftercall')
+ && $GAME['schweinchen-who']==$me && !$GAME['schweinchen-first'] )
+ )
display_card($card,$PREF["cardset"]);
else
display_link_card($card,$PREF["cardset"]);