summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Persaud <arun@nubati.net>2008-05-17 11:02:37 -0700
committerArun Persaud <arun@nubati.net>2008-05-17 11:02:37 -0700
commitf7037807083af50fcbf136cfbf18b617342d7c4e (patch)
tree88e844f2560d964fe85ae45b1cb287557540ae53
parentb5dc679f1b8166fe6d6b37b6b18149700c7cab91 (diff)
downloade-DoKo-f7037807083af50fcbf136cfbf18b617342d7c4e.tar.gz
e-DoKo-f7037807083af50fcbf136cfbf18b617342d7c4e.tar.bz2
e-DoKo-f7037807083af50fcbf136cfbf18b617342d7c4e.zip
CLEANUP: rewrote code for Schweinchen
should be easier to add some new features now. Signed-off-by: Arun Persaud <arun@nubati.net>
-rw-r--r--include/functions.php6
-rw-r--r--include/game.php68
2 files changed, 48 insertions, 26 deletions
diff --git a/include/functions.php b/include/functions.php
index dca9640..fdb461e 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -171,14 +171,14 @@ function compare_cards($a,$b,$game)
case "normal":
case "silent":
case "trump":
- if($RULES["schweinchen"]=="both" && $GAME["schweinchen"])
+ if($RULES['schweinchen']=='both' && $GAME['schweinchen-who'])
{
if($a == 19 || $a == 20 )
return 1;
if($b == 19 || $b == 20 )
return 0;
};
- if($RULES["schweinchen"]=="second" && $GAME["schweinchen"]==3)
+ if($RULES['schweinchen']=='second' && $GAME['schweinchen-second'])
{
if($a == 19 || $a == 20 )
return 1;
@@ -705,7 +705,7 @@ function display_table ()
/* add hints for poverty, wedding, solo, etc */
if( $gametype != "solo")
- if($GAME["schweinchen"] && $RULES["schweinchen"]=="both" && $GAME["schweinchen-who"]==$hash)
+ if( $RULES["schweinchen"]=="both" && $GAME["schweinchen-who"]==$hash )
echo " Schweinchen. <br />";
if($GT=="poverty" && $party=="re")
diff --git a/include/game.php b/include/game.php
index d29c2c9..3191793 100644
--- a/include/game.php
+++ b/include/game.php
@@ -57,18 +57,35 @@ if($gametype=="solo")
$GT = $gametype." ".$GT;
}
-/* does anyone have both foxes */
-$GAME["schweinchen"]=0;
-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"]=1;
- $GAME["schweinchen-who"]=$hash;
- }
- };
+/* 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( $gametype == 'normal' || $gametype == 'silent' || $gametype=='trump' )
+ if( in_array($RULES['schweinchen'],array('both','second','secondaftercall')) )
+ $ok=1;
+
+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;
+}
+else
+{
+ /* no need to check for Schweinchen */
+ $GAME['schweinchen-who']=NULL;
+}
+/* end check for Schweinchen */
/* put everyting in a form */
echo "<form action=\"index.php?action=game&me=$me\" method=\"post\">\n";
@@ -1026,8 +1043,11 @@ switch($mystatus)
$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);
@@ -1134,20 +1154,22 @@ switch($mystatus)
$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" )
+ 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' )
DB_insert_comment("Schweinchen! ",$playid,$myid);
- if($RULES["schweinchen"]=="both" )
+ if($RULES['schweinchen']=='both' )
DB_insert_comment("Schweinchen! ",$playid,$myid);
if ($debug)
- echo "schweinchen = ".$GAME["schweinchen"]." ---<br />";
+ echo "schweinchen = ".$GAME["schweinchen-who"]." ---<br />";
}
/* if sequence == 4 check who one in case of wedding */