X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Fgame.php;h=0a40bab00032266c0782db4f63c09923367cadaf;hp=a11e6b6eb48d64c56370b2c497dcfbaeb402e753;hb=3851854ad07430dc62337d482e811bf9363480a5;hpb=0edb4b26c049e07af0970e081fab699d2bdd333b diff --git a/include/game.php b/include/game.php index a11e6b6..0a40bab 100644 --- a/include/game.php +++ b/include/game.php @@ -24,10 +24,6 @@ if(!$myid) global $GAME,$RULES,$CARDS; -/* the user has done something, update the timestamp */ -if(isset($_SESSION['id'])) - DB_update_user_timestamp($_SESSION['id']); - /* get some information from the DB */ $gameid = DB_get_gameid_by_hash($me); $myname = DB_get_name('hash',$me); @@ -67,7 +63,7 @@ if( $gamestatus == 'pre' ) else { /* in a game Schweinchen is not valid in all types of games */ - if( $gametype == 'normal' || $gametype == 'silent' || $gametype=='trump' || $gametype=='wedding') + if( in_array($gametype,array('normal','wedding','trump','silent') )) if( in_array($RULES['schweinchen'],array('both','second','secondaftercall')) ) $ok=1; } @@ -210,16 +206,19 @@ if($session) echo " \n \n"; /* show score */ + + echo "
"; + $score = generate_score_table($session); + + /* get the last entry to show on the main page */ $tmpscore= $score; $finalscore = array_pop($tmpscore); $finalscore = $finalscore['players']; - echo "
"; if($finalscore) { echo "Score: \n"; - /* output the final score on the front page */ foreach($finalscore as $user=>$value) { $name = DB_get_name('userid',$user); @@ -232,10 +231,13 @@ if($session) echo " "; } + /* output all games for the score table */ echo format_score_table_html($score,$myid); echo "
\n"; - /* figure out which game in a session we are in and link to the previous and next game if possible */ + /* figure out which game in a session we are in and link to the + * previous and next game if possible + */ $hashes = DB_get_hashes_by_session($session,$myid); $next = NULL; $i = 1; @@ -282,6 +284,16 @@ display_table(); * play: game in progress * gameover: are we revisiting a game */ + +/* the user has done something, update the timestamp. Use $myid in + * active games and check for session-id in old games (myid might be wrong in that case) + */ +if($mystatus!='gameover') + DB_update_user_timestamp($myid); + else + if(isset($_SESSION['id'])) + DB_update_user_timestamp($_SESSION['id']); + switch($mystatus) { case 'start': @@ -589,11 +601,10 @@ switch($mystatus) else if($nines) { /* cancel game */ - $message = "Hello, \n\n". - " the game has been canceled because ".DB_get_name('userid',$nines). + $message = "The game has been canceled because ".DB_get_name('userid',$nines). " has five or more nines and nobody is playing solo.\n\n". - " To redeal either start a new game or, in case the game was part of a tournament, \n". - " go to the last game and use the link at the bottom of the page to redeal.\n\n"; + "To redeal either start a new game or, in case the game was part of a tournament,\n". + "go to the last game and use the link at the bottom of the page to redeal.\n\n"; $userids = DB_get_all_userid_by_gameid($gameid); foreach($userids as $user) @@ -605,9 +616,10 @@ switch($mystatus) /* update game status */ cancel_game('nines',$gameid); - echo "The game has been canceled because ".DB_get_name('userid',$nines). - " has five or more nines and nobody is playing solo.\n"; - return; + echo "

The game has been canceled because ".DB_get_name('userid',$nines). + " has five or more nines and nobody is playing solo.

\n"; + echo "
\n"; + break; } else if($poverty==1) /* one person has poverty */ { @@ -952,8 +964,8 @@ switch($mystatus) /* update game status */ cancel_game('trump',$gameid); - echo "

Game ".DB_format_gameid($gameid)." has been canceled.

"; - return; + echo "

Game ".DB_format_gameid($gameid)." has been canceled.

"; + break; } else { @@ -1414,7 +1426,10 @@ switch($mystatus) $play = DB_get_cards_by_trick($trickid); $winner = get_winner($play,$gametype); /* returns the position */ - /* check if someone caught a fox */ + /* + * check if someone caught a fox + *******************************/ + /* first check if we should account for solos at all, * since it doesn't make sense in some games */ @@ -1447,7 +1462,10 @@ switch($mystatus) } } - /* check for karlchen (jack of clubs in the last trick)*/ + /* + * check for karlchen (jack of clubs in the last trick) + ******************************************************/ + /* same as for foxes, karlchen doesn't always make sense * check what kind of game it is and set karlchen accordingly */ $ok = 1; /* default: karlchen should be accounted for */ @@ -1472,7 +1490,10 @@ switch($mystatus) DB_query("INSERT INTO Score". " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')"); } - /* check for doppelopf (>40 points)*/ + /* + * check for doppelopf (>40 points) + ***********************************/ + $points = 0; foreach($play as $played) { @@ -1487,6 +1508,10 @@ switch($mystatus) " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'doko')"); } + /* + * set winner (for this trick) + */ + if($winner>0) DB_query("UPDATE Trick SET winner='$winner' WHERE id='$trickid'"); else @@ -1910,11 +1935,17 @@ switch($mystatus) * 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 ) + ( (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