NEW FEATURE: pre select card to play if there is only one option
authorArun Persaud <arun@nubati.net>
Wed, 22 Sep 2010 03:27:12 +0000 (20:27 -0700)
committerArun Persaud <arun@nubati.net>
Wed, 22 Sep 2010 03:32:39 +0000 (20:32 -0700)
include/game.php
include/output.php

index eb66a987157c6bcd98ddbcf57f0ce343e7e7fcca..04df1620816beba6d79798ed379e601065555753 100644 (file)
@@ -1990,6 +1990,38 @@ switch($mystatus)
        if(have_suit($mycards,$firstcard))
          $followsuit = 1;
 
        if(have_suit($mycards,$firstcard))
          $followsuit = 1;
 
+       /* count how many cards we can play, so that we can pre-select it if there is only one */
+       $howmanycards = 0;
+       foreach($mycards as $card)
+         {
+           if($howmanycard>1)
+             break;
+
+           /* display only cards that the player is allowed to play as links, the rest just display normal
+            * also check if we have both schweinchen, in that case only display on of them as playable
+            */
+           if( ($followsuit && !same_type($card,$firstcard)) ||
+               ( (int)($card)==19 &&
+                 !$GAME['schweinchen-first'] &&
+                 ( $RULES['schweinchen']=='second' ||
+                   ( $RULES['schweinchen']=='secondaftercall' &&
+                    (DB_get_call_by_hash($GAME['schweinchen-who']) ||
+                     DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
+                   )
+                 ) &&
+                 $GAME['schweinchen-who']==$me &&
+                 in_array($gametype,array('normal','wedding','trump','silent'))
+                 )
+               )
+             continue ;
+           else
+             $howmanycards++;
+         }
+       if($howmanycards==1)
+         $howmanycards=1;
+       else
+         $howmanycards=0;
+
        foreach($mycards as $card)
          {
            /* display only cards that the player is allowed to play as links, the rest just display normal
        foreach($mycards as $card)
          {
            /* display only cards that the player is allowed to play as links, the rest just display normal
@@ -2010,7 +2042,7 @@ switch($mystatus)
                )
              display_card($card,$PREF['cardset']);
            else
                )
              display_card($card,$PREF['cardset']);
            else
-             display_link_card($card,$PREF['cardset']);
+             display_link_card($card,$PREF['cardset'],$selected=$howmanycards);
          }
       }
     else if($mystatus=='play' )
          }
       }
     else if($mystatus=='play' )
index 3ad0552e02012341f93b718c17c385e335d3dae0..0c2ff967ad05d5830a46b47bf5c9f9734285592c 100644 (file)
@@ -202,12 +202,15 @@ function display_card($card,$dir="english")
   return;
 }
 
   return;
 }
 
-function display_link_card($card,$dir="english",$type="card")
+function display_link_card($card,$dir="english",$type="card", $selected=0)
 {
 {
+  if($selected)
+    $selected = 'selected="selected"';
+
   if( $card/2 - (int)($card/2) == 0.5)
   if( $card/2 - (int)($card/2) == 0.5)
-    echo "<div class=\"cardinput\"><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" /><img src=\"cards/".$dir."/".$card.".png\" alt=\"".DB_get_card_name($card)."\" /></div>\n";
+    echo "<div class=\"cardinput\"><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" $selected /><img src=\"cards/".$dir."/".$card.".png\" alt=\"".DB_get_card_name($card)."\" /></div>\n";
   else
   else
-    echo "<div class=\"cardinput\" ><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" /><img src=\"cards/".$dir."/".($card-1).".png\" alt=\"".DB_get_card_name($card-1)."\" /></div>\n";
+    echo "<div class=\"cardinput\" ><input type=\"radio\" name=\"".$type."\" value=\"".$card."\" $selected /><img src=\"cards/".$dir."/".($card-1).".png\" alt=\"".DB_get_card_name($card-1)."\" /></div>\n";
   return;
 }
 
   return;
 }