From: arun Date: Fri, 17 Nov 2006 20:29:29 +0000 (+0000) Subject: cards are now deleted from your hand, still need to add some tests at the beginning... X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=commitdiff_plain;h=ff0bce79b7a8d040afc336fa3cde2bff97630c07 cards are now deleted from your hand, still need to add some tests at the beginning and add up scores --- diff --git a/index.php b/index.php index cf877cd..05dc42f 100644 --- a/index.php +++ b/index.php @@ -69,6 +69,7 @@ function save_status() return; } +$history=array(); /* check for status file and read it, if possible */ @@ -173,7 +174,7 @@ if(sizeof($lines)<2) $game["init"]=0; $tmp = explode( ":",$lines[0]); - $hash[] = $tmp[0]; + $hash[0] = $tmp[0]; $player[$tmp[0]]["number"] = 0; $player[$tmp[0]]["hash"] = $tmp[0]; $player[$tmp[0]]["name"] = $tmp[1]; @@ -183,7 +184,7 @@ if(sizeof($lines)<2) if(ereg("s",$tmp[3])) $game["init"]++; $tmp = explode( ":",$lines[1]); - $hash[] = $tmp[0]; + $hash[1] = $tmp[0]; $player[$tmp[0]]["number"] = 1; $player[$tmp[0]]["hash"] = $tmp[0]; $player[$tmp[0]]["name"] = $tmp[1]; @@ -193,7 +194,7 @@ if(sizeof($lines)<2) if(ereg("s",$tmp[3])) $game["init"]++; $tmp = explode( ":",$lines[2]); - $hash[] = $tmp[0]; + $hash[2] = $tmp[0]; $player[$tmp[0]]["number"] = 2; $player[$tmp[0]]["hash"] = $tmp[0]; $player[$tmp[0]]["name"] = $tmp[1]; @@ -203,7 +204,7 @@ if(sizeof($lines)<2) if(ereg("s",$tmp[3])) $game["init"]++; $tmp = explode( ":",$lines[3]); - $hash[] = $tmp[0]; + $hash[3] = $tmp[0]; $player[$tmp[0]]["number"] = 3; $player[$tmp[0]]["hash"] = $tmp[0]; $player[$tmp[0]]["name"] = $tmp[1]; @@ -215,9 +216,13 @@ if(sizeof($lines)<2) /* save the game history */ for($i=4;$i @@ -266,7 +271,7 @@ if(sizeof($lines)<2) { $b=$_REQUEST["b"]; - if( ereg("[is]",$player[$b]["option"]) && $game["init"]<4) + if( ereg("s",$player[$b]["option"]) && $game["init"]<4) { echo "just wait for the game to start"; } @@ -348,76 +353,146 @@ if(sizeof($lines)<2) else { $me = $_REQUEST["me"]; - if(isset($_REQUEST["card"])) - { - $card=$_REQUEST["card"]; - echo "EMAIL: you played $card
"; - echo "check,if card correct remove card from deck
"; - - - $tmp = explode(":",$history[sizeof($history)-1]); - $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":"; - $history[sizeof($history)-1]=join(":",$tmp); - save_status(); - } echo "game in progress and you are in it
"; foreach($history as $play) { - $trick = explode(":",$play); + echo "
"; - $last=-1; + $trick = explode(":",$play); + + $last=-2; /* found old trick, display it */ for($i=0;$i",$card); - echo $player[$hash[$tmp[0]]]["name"]." played "; - display_card($tmp[1]); - $last=$tmp[0]; + if(ereg("->",$card)) + { + $tmp = explode("->",$card); + echo $player[$hash[$tmp[0]]]["name"]." played "; + display_card($tmp[1]); + $last=$tmp[0]; + } } - echo "
"; - - - $next = $last + 1; - if ($next>=4) - $next -= 4 ; - - switch(sizeof($trick)) + } + + $next = $last + 1; + if ($next>=4) + $next -= 4 ; + if($last<0) + { + $next=$history[sizeof($history)-1][0]; + } + + + if(isset($_REQUEST["card"])) + { + if($hash[$next]==$me) { - case 1: - echo "new trick , next player ".$trick[0]."
"; - break; - case 4: - echo "figure out who will win
"; - case 2: - case 3: - echo "some played $next"; - if($hash[$next]==$me) + $card=$_REQUEST["card"]; + echo "EMAIL: you played $card "; + $mycards = explode(";",$player[$me]["cards"]); + if(in_array($card,$mycards)) { + $tmp=array(); + echo "
"; + foreach($mycards as $m) + { + if($m!=$card) + { + $tmp[]=$m; + echo "adding card $m
"; + } + } + $tmp2=""; + for($i=0;$i"; + } + $tmp2.=$tmp[$i]; + echo "adding card $tmp2 at $i *
"; + $player[$me]["cards"]=$tmp2; + + if($last<0) + { + $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n"; + } + else + { + $tmp = explode(":",$history[sizeof($history)-1]); + $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":"; + $history[sizeof($history)-1]=join(":",$tmp); + } + save_status(); - echo "ITS YOUR TURN
"; - $allcards = $player[$me]["cards"]; - $mycards = explode(";",$allcards); - - sort($mycards); - echo "your cards are
"; - foreach($mycards as $card) - { - display_link_card($card,$me); - } - echo "
\n"; + display_card($card); } - echo "
"; - break; - default: - echo "default
"; + else + echo "seems like you don't have that card
"; + } + + } + else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3) + { + $win=$_REQUEST["win"]; + $history[]=$win.":\n"; + echo "juhu someone won:$win
"; + + save_status(); + } + echo "
"; + + $tmp = explode(":",$history[sizeof($history)-1]); + + echo sizeof($tmp)." tmp ;;".strlen($tmp[0])." len tmp0
"; + + if(sizeof($tmp)==5) + { + ?> +
+ + + player1 + player2 + player3 + player4 + + + +
+"; + } + if($hash[$next]==$me) + { + + echo "ITS YOUR TURN
"; + $allcards = $player[$me]["cards"]; + $mycards = explode(";",$allcards); + + sort($mycards); + echo "your cards are
"; + foreach($mycards as $card) + { + display_link_card($card,$me); + } + echo "
\n"; + } + echo "
"; + } } } - -} /* is this the last player that needs to accept? */ + + } /* is this the last player that needs to accept? */ /* yes, figure out who starts, send out email to first player */ /* no, email the rest to cancel game */