From 2bd1c94dd7e712bb2cc8e2c16fb317bd0169c59c Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Sun, 13 Nov 2011 20:09:25 -0800 Subject: [PATCH] LAYOUT: move display of cards below switch for mystatus This should make for a more consistent html layout and fix some issues that show up on different browsers and display sizes. --- include/functions.php | 15 +++ include/game.php | 306 +++++++++++++++++++++--------------------- 2 files changed, 169 insertions(+), 152 deletions(-) diff --git a/include/functions.php b/include/functions.php index 0653ce4..ddac182 100644 --- a/include/functions.php +++ b/include/functions.php @@ -86,6 +86,21 @@ define("GAME_RECOVERY", 8); define("GAME_REMINDER", 9); define("GAME_NEW", 10); +/* define possible status for showing cards */ + +define("CARDS_EMPTY", 0); /* show player's hand*/ +define("CARDS_SHOW", 1); /* show player's hand*/ +define("CARDS_MYTURN", 2); /* show radiobuttons for cards that can be played*/ +define("CARDS_EXCHANGE", 3); /* do we need to return cards to our partner in poverty?*/ +define("CARDS_GAMEOVER_ME", 4); /* show all cards from everyone*/ +define("CARDS_GAMEOVER", 5); /* show all cards from everyone (looking at someone else's game)*/ + + /* cards_status: SHOW show our hand + * MYTURN show radiobutton for cards that can be played + * EXCHANGE do we need to return cards to our partner in poverty? + * GAMEOVER show all cards from everyone + */ + function mymail($uid,$gameid=0,$type,$message) { global $EmailName,$WIKI; diff --git a/include/game.php b/include/game.php index 02d6f96..3564d9c 100644 --- a/include/game.php +++ b/include/game.php @@ -328,6 +328,11 @@ display_table(); * gameover: are we revisiting a game */ +/* Depending on the situation we set + * cards_status (see functions.php for possible options) + */ +$cards_status = CARDS_EMPTY; + switch($mystatus) { case 'start': @@ -343,7 +348,7 @@ switch($mystatus) { /* asks the player, if he wants to join the game */ output_check_want_to_play($me); - echo '
'; + $card_status = CARDS_EMPTY; break; } else @@ -393,13 +398,9 @@ switch($mystatus) /*************************** * check if player is sick * ***************************/ - - $mycards = DB_get_hand($me); - $mycards = mysort($mycards,$gametype); - if(!myisset('solo','wedding','poverty','nines','lowtrump') ) { - /* output sickness of other playes, in case the already selected and are sitting in front of the current player */ + /* output sickness of other playes, in case they already selected and are sitting in front of the current player */ echo "\n\n"; /* end div trick, end li trick , end tricks*/ /* end displaying sickness */ + $mycards = DB_get_hand($me); output_check_for_sickness($me,$mycards); - echo '
'._('Your cards are').":
\n"; - foreach($mycards as $card) - display_card($card,$PREF['cardset']); - echo "
\n"; + $card_status = CARDS_SHOW; break; } @@ -445,10 +444,7 @@ switch($mystatus) echo "

You selected more than one sickness, please go back ". "and answer the question again.

"; - echo '
'._('Your cards are').":
\n"; - foreach($mycards as $card) - display_card($card,$PREF['cardset']); - echo "
\n"; + $card_status = CARDS_SHOW; break; } @@ -524,9 +520,6 @@ switch($mystatus) * this can therefore only be handled once all players finished the last stage */ - $mycards = DB_get_hand($me); - $mycards = mysort($mycards,$gametype); - /* output sickness of other playes, in case they already selected and are sitting in front of the current player */ echo "\n\n"; /* end ul tricks*/ - $mycards = DB_get_hand($me); - $mycards = mysort($mycards,$gametype); - echo "
\n"; - if($myturn && !myisset('card') && $mystatus=='play' ) { - echo "Hello ".$myname.", it's your turn!
\n"; - echo _('Your cards are').":
\n"; - - /* do we have to follow suite? */ - $followsuit = 0; - 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($howmanycards>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 - * 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')) - ) - ) - display_card($card,$PREF['cardset']); - else - display_link_card($card,$PREF['cardset'],$type='card',$selected=$howmanycards); - } + $card_status = CARDS_MYTURN; } else if($mystatus=='play' ) { - echo _('Your cards are').":
\n"; - foreach($mycards as $card) - display_card($card,$PREF['cardset']); + $card_status = CARDS_SHOW; } else if($mystatus=='gameover') { - $oldcards = DB_get_all_hand($me); - $oldcards = mysort($oldcards,$gametype); - if(isset($_SESSION['id']) && $myid==$_SESSION['id']) - echo _('Your cards were').":
\n"; + $card_status = CARDS_GAMEOVER_ME; else - { - $name = DB_get_name('userid',$myid); - echo "$name's were:
\n"; - } - - foreach($oldcards as $card) - display_card($card,$PREF['cardset']); - - $userids = DB_get_all_userid_by_gameid($gameid); - foreach($userids as $user) - { - $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); - - if($userhash!=$me) - { - echo "
"; - - $name = DB_get_name('userid',$user); - $oldcards = DB_get_all_hand($userhash); - $oldcards = mysort($oldcards,$gametype); - echo "$name's cards were:
\n"; - foreach($oldcards as $card) - display_card($card,$PREF['cardset']); - } - }; + $card_status = CARDS_GAMEOVER; } - echo "
\n"; /* if the game is over do some extra stuff, therefore exit the swtich statement if we are still playing*/ if($mystatus=='play') @@ -2091,6 +1965,134 @@ switch($mystatus) myerror("error in testing the status"); } /*end of output: tricks, table, messages, card */ +/************** + * show cards * + **************/ + +$mycards = DB_get_hand($me); +$mycards = mysort($mycards,$gametype); + +echo '
'; +switch ($card_status) { + case CARDS_SHOW: + echo _('Your cards are').":
\n"; + foreach($mycards as $card) + display_card($card,$PREF['cardset']); + break; + case CARDS_EXCHANGE: + echo '
'._('You need to get rid of a few cards')."
\n"; + + echo _('Your cards are').":
\n"; + $type='exchange'; + foreach($mycards as $card) + display_link_card($card,$PREF['cardset'],$type); + echo ' '."\n"; + break; + case CARDS_MYTURN: + echo 'Hello '.$myname.", it's your turn!
\n"; + echo _('Your cards are').":
\n"; + + /* do we have to follow suite? */ + $followsuit = 0; + 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($howmanycards>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++; + } + + /* make it boolean, so that we can pass it later to display_link_card */ + if($howmanycards!=1) + $howmanycards=0; + + foreach($mycards as $card) + { + /* 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')) + ) + ) + display_card($card,$PREF['cardset']); + else + display_link_card($card,$PREF['cardset'],$type='card',$selected=$howmanycards); + } + break; + case CARDS_GAMEOVER_ME: + case CARDS_GAMEOVER: + if($card_status == CARDS_GAMEOVER_ME) + echo _('Your cards were').":
\n"; + else + { + $name = DB_get_name('userid',$myid); + echo "$name's were:
\n"; + } + $oldcards = DB_get_all_hand($me); + $oldcards = mysort($oldcards,$gametype); + + foreach($oldcards as $card) + display_card($card,$PREF['cardset']); + + /* display hands of everyone else */ + $userids = DB_get_all_userid_by_gameid($gameid); + foreach($userids as $user) + { + $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); + + if($userhash!=$me) + { + echo "
"; + + $name = DB_get_name('userid',$user); + $oldcards = DB_get_all_hand($userhash); + $oldcards = mysort($oldcards,$gametype); + echo "$name's cards were:
\n"; + foreach($oldcards as $card) + display_card($card,$PREF['cardset']); + } + }; + break; + case CARDS_EMPTY: + default: + break; + } +echo '
'; + + /*********************************************** * Comments, re/contra calls, user menu ***********************************************/ -- 2.25.1