summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functions.php54
-rw-r--r--index.php59
-rw-r--r--output.php23
3 files changed, 98 insertions, 38 deletions
diff --git a/functions.php b/functions.php
index 31167e9..ce549c1 100644
--- a/functions.php
+++ b/functions.php
@@ -78,6 +78,7 @@ function compare_cards($a,$b,$game)
global $CARDS;
global $RULES;
+ global $GAME;
/* first map all cards to the odd number,
* this insure that the first card wins the trick
@@ -93,6 +94,20 @@ function compare_cards($a,$b,$game)
{
case "normal":
case "silent":
+ if($RULES["schweinchen"]=="both" && $GAME["schweinchen"])
+ {
+ if($a == 19 || $a == 20 )
+ return 1;
+ if($b == 19 || $b == 20 )
+ return 0;
+ };
+ if($RULES["schweinchen"]=="second" && $GAME["schweinchen"]==3)
+ {
+ if($a == 19 || $a == 20 )
+ return 1;
+ if($b == 19 || $b == 20 )
+ return 0;
+ };
case "trump":
case "heart":
case "spade":
@@ -102,6 +117,7 @@ function compare_cards($a,$b,$game)
return 0; /* second one wins.*/
}
+ /* normal case */
if(is_trump($a) && is_trump($b) && $a<=$b)
return 1;
else if(is_trump($a) && is_trump($b) )
@@ -221,6 +237,8 @@ function check_wedding($cards)
function count_trump($cards)
{
+ global $RULES;
+
$trump = 0;
/* count each trump */
@@ -228,14 +246,23 @@ function count_trump($cards)
if( (int)($c) <27)
$trump++;
- /* subtract foxes */
- if( in_array("19",$cards))
- $trump--;
- if( in_array("20",$cards) )
- $trump--;
- /* add one, in case the player has both foxes (schweinchen) */
- if( in_array("19",$cards) && in_array("20",$cards) )
- $trump++;
+ switch($RULES["schweinchen"])
+ {
+ case "none":
+ break;
+ case "second":
+ case "secondaftercall":
+ /* add one, in case the player has both foxes (schweinchen) */
+ if( in_array("19",$cards) && in_array("20",$cards) )
+ $trump++;
+ case "both":
+ /* subtract foxes */
+ if( in_array("19",$cards))
+ $trump--;
+ if( in_array("20",$cards) )
+ $trump--;
+ break;
+ }
return $trump;
}
@@ -391,11 +418,12 @@ function create_array_of_random_numbers()
$r = array();
$a = array();
- for($i=1;$i<49;$i++)
- $a[$i]=$i;
-
- $r = array_rand($a,48);
+ for($i=0;$i<48;$i++)
+ $a[$i]=$i+1;
+# $r = array_rand($a,48);
+ $r =$a;
+
return $r;
}
@@ -492,7 +520,7 @@ function set_gametype($gametype)
$CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
$CARDS["spades"] = array('35','36','37','38','39','40','41','42');
$CARDS["hearts"] = array('43','44','45','46','47','48');
- $CARDS["foxes"] = array('21','22');
+ $CARDS["foxes"] = array('19','20');
if($RULES["dullen"]=='none')
{
$CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
diff --git a/index.php b/index.php
index eded836..302ec69 100644
--- a/index.php
+++ b/index.php
@@ -229,6 +229,19 @@ else if(myisset("me"))
echo "schweinchen: ".$r[3]."<br />";
echo "</div>\n";
+ /* 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;
+ }
+ };
+
/* mystatus gets the player through the different stages of a game.
* start: yes/no
@@ -486,17 +499,16 @@ else if(myisset("me"))
break;
if($usersick == "solo" && $gametype =="solo")
break;
- };
+
+ };
+
+ if( $gametype != "solo")
+ if($GAME["schweinchen"] && $RULES["schweinchen"]=="both" )
+ echo DB_get_name_by_hash($GAME["schweinchen-who"])." has Schweinchen. <br />";
+
echo "<br />\n";
- /* check for Schweinchen (cards 21,22) */
- if($RULES["schweinchen"]=="both")
- {
- set_gametype($gametype);
- echo "TODO: check if one user has both foxes and output here ";
- }
-
- /* finished the setup, go to next stage unless there is a case of poverty*/
+ /* finished the setup, set re/contra parties if possible, go to next stage unless there is a case of poverty*/
switch($gametype)
{
case "solo":
@@ -509,7 +521,8 @@ else if(myisset("me"))
DB_set_hand_status_by_hash($me,'play');
break;
case "wedding":
- echo "Don't know who will be Re and Contra, you need to figure that out at the end of the game yourself <br />\n";
+ echo "Don't know who will be Re and Contra, you need to ".
+ "figure that out at the end of the game yourself <br />\n";
DB_set_hand_status_by_hash($me,'play');
break;
case "normal":
@@ -567,7 +580,7 @@ else if(myisset("me"))
else
$gametype="normal";
- set_gametype($gametype);
+ set_gametype($gametype); /* this sets the $CARDS variable */
/* get some infos about the game */
$gamestatus = DB_get_game_status_by_gameid($gameid);
@@ -660,6 +673,10 @@ else if(myisset("me"))
$trick = $r[3];
$comment = $r[4];
+ /* check if first schweinchen has been played */
+ if($r[0] == 19 || $r[0] == 20 )
+ $GAME["schweinchen"]++;
+
/* save card to be able to find the winner of the trick later */
$play[$seq] = array("card"=>$r[0],"pos"=>$pos);
@@ -744,10 +761,24 @@ else if(myisset("me"))
if($handcardid)
{
+ $comment = "";
+
/* mark card as played */
mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
DB_quote_smart($card));
+ /* check for schweinchen */
+ echo "schweinchen = ".$GAME["schweinchen"]." --$card-<br />";
+ if($card == 19 || $card == 20 )
+ {
+ $GAME["schweinchen"]++;
+ if($GAME["schweinchen"]==3 && $RULES["schweinchen"]=="second" )
+ $comment="Schweinchen! ";
+ if($RULES["schweinchen"]=="both" )
+ $comment="Schweinchen! ";
+ echo "schweinchen = ".$GAME["schweinchen"]." ---<br />";
+ }
+
/* get trick id or start new trick */
$a = DB_get_current_trickid($gameid);
$trickid = $a[0];
@@ -758,9 +789,11 @@ else if(myisset("me"))
/* check for coment */
if(myisset("comment"))
{
- DB_insert_comment($_REQUEST["comment"],$playid,$myid);
+ $comment.=$_REQUEST["comment"];
};
-
+ if($comment != "")
+ DB_insert_comment($comment,$playid,$myid);
+
/* display played card */
echo "<div class=\"card\">";
echo " you played <br />";
diff --git a/output.php b/output.php
index d20d725..ba3c473 100644
--- a/output.php
+++ b/output.php
@@ -111,11 +111,10 @@ function output_form_for_new_game($names)
echo " <option>$name</option>\n";
}
echo " </select>\n";
- unset($names[$randkey]);
}
?>
<h2> Rules </h2>
-
+ <p> Some areas are grayed out which means that the rule is not implemented yet and therefore cannot be selected </p>
<p> ten of hearts:
<ul>
<li> <input type="radio" name="dullen" value="none" /> just normal non-trump </li>
@@ -123,20 +122,20 @@ function output_form_for_new_game($names)
<li> <input type="radio" name="dullen" value="secondwins" checked="checked" /> second ten of hearts wins the trick </li>
</ul>
</p>
- <p> schweinchen (both foxes):
+ <p> schweinchen (both foxes), only in normal games or silent solos:
<ul>
- <li> <input type="radio" name="schweinchen" value="none" /> none </li>
+ <li> <input type="radio" name="schweinchen" value="none" checked="checked" /> none </li>
<li> <input type="radio" name="schweinchen" value="both" />
both become highest trump (automatic call at beginning of the game)
- (does not work yet) </li>
- <li> <input type="radio" name="schweinchen" value="second" checked="checked" />
- first one normal, second one becomes highest (call during the game) (does not work yet) </li>
- <li> <input type="radio" name="schweinchen" value="secondaftercall" />
- second one become highest only in case re/contra was announced
- (does not work yet)</li>
- </ul>
+ </li>
+ <li> <input type="radio" name="schweinchen" value="second" />
+ first one normal, second one becomes highest (call during the game) </li>
+ <li> <input type="radio" name="schweinchen" value="secondaftercall" disabled="disabled" />
+ second one become highest only in case re/contra was announced (not working yet)
+ </li>
+ </ul>
</p>
-
+
<input type="submit" value="start game" />
</form>
<?php