From f94dd2d6d58f37306d1da0f6bb12f5276883cd6b Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Tue, 21 Sep 2010 20:27:12 -0700 Subject: NEW FEATURE: pre select card to play if there is only one option --- include/game.php | 34 +++++++++++++++++++++++++++++++++- include/output.php | 9 ++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/include/game.php b/include/game.php index eb66a98..04df162 100644 --- a/include/game.php +++ b/include/game.php @@ -1990,6 +1990,38 @@ switch($mystatus) 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 @@ -2010,7 +2042,7 @@ switch($mystatus) ) display_card($card,$PREF['cardset']); else - display_link_card($card,$PREF['cardset']); + display_link_card($card,$PREF['cardset'],$selected=$howmanycards); } } else if($mystatus=='play' ) diff --git a/include/output.php b/include/output.php index 3ad0552..0c2ff96 100644 --- a/include/output.php +++ b/include/output.php @@ -202,12 +202,15 @@ function display_card($card,$dir="english") 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) - echo "
\"".DB_get_card_name($card)."\"
\n"; + echo "
\"".DB_get_card_name($card)."\"
\n"; else - echo "
\"".DB_get_card_name($card-1)."\"
\n"; + echo "
\"".DB_get_card_name($card-1)."\"
\n"; return; } -- cgit v1.2.3-18-g5258