99ef80560c89f40acc78e60c71bd6a7f9352ebe7
[e-DoKo.git] / index.php
1 <!DOCTYPE html PUBLIC
2     "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
3     "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
5   <head>
6      <title>Doko via email</title>
7      <link rel="stylesheet" type="text/css" href="standard.css"/>       
8   </head>
9 <body>
10 <h1> Welcome to E-Doko </h1>
11
12 <?php
13 /* helper function */
14 function mymail($To,$Subject,$message)
15 {  
16   $debug = 1;
17   if($debug)
18     echo "<br>To: $To<br>Subject: $Subject <br>$message<br>";
19   else
20     mail($To,$Subject,$message);
21   return;
22 }
23
24 function card_to_name($card)
25 {
26   switch($card)
27     {
28       case 1:
29       case 2:
30         return "ten of hearts";
31       case 3:
32       case 4:
33       return "queen of clubs";
34       case 5:
35       case 6:
36       return "queen of spades";
37       case 7:
38       case 8:
39       return "queen of hearts";
40       case 9:
41       case 10:
42       return "queen of diamonds";
43       case 11:
44       case 12:
45       return "jack of clubs";
46       case 13:
47       case 14:
48       return "jack of spades";
49       case 15:
50       case 16:
51       return "jack of hearts";
52       case 17:
53       case 18:
54       return "jack of diamonds";
55       case 19:
56       case 20:
57       return "ace of diamonds";
58       case 21:
59       case 22:
60       return "ten of diamonds";
61       case 23:
62       case 24:
63       return "king of diamonds";
64       case 25:
65       case 26:
66       return "nine of diamonds";;
67       case 27:
68       case 28:
69       return "ace of clubs";
70       case 29:
71       case 30:
72       return "ten of clubs";
73       case 31:
74       case 32:
75       return "king of clubs";
76       case 33:
77       case 34:
78       return "nine of clubs";
79       case 35:
80       case 36:
81       return "ace of spades";
82       case 37:
83       case 38:
84       return "ten of spades";
85       case 39:
86       case 40:
87       return "king of spades";
88       case 41:
89       case 42:
90       return "nine of spades";
91       case 43:
92       case 44:
93       return "ace of hearts";
94       case 45:
95       case 46:
96       return "ace of diamonds";
97       case 47:
98       case 48:
99       return "nine of diamonds";
100       default:
101       return "something went wrong, please contact the admin";
102     }
103 }
104
105 function card_value($card)
106 {
107   switch($card-1)
108     {
109       case 0:
110       case 1:
111         return 10;
112       case 2:
113       case 3:
114       case 4:
115       case 5:
116       case 6:
117       case 7:
118       case 8:
119       case 9:
120         return 3;
121       case 10:
122       case 11:
123       case 12:
124       case 13:
125       case 14:
126       case 15:
127       case 16:
128       case 17:
129         return 2;
130       case 18:
131       case 19:
132         return 11;
133       case 20:
134       case 21:
135         return 10;
136       case 22:
137       case 23:
138         return 4;
139       case 24:
140       case 25:
141       return 0;
142       case 26:
143       case 27:
144       return 11;
145       case 28:
146       case 29:
147       return 10;
148       case 30:
149       case 31:
150       return 4;
151       case 32:
152       case 33:
153       return 0;
154       case 34:
155       case 35:
156       return 11;
157       case 36:
158       case 37:
159       return 10;
160       case 38:
161       case 39:
162       return 4;
163       case 40:
164       case 41:
165       return 0;
166       case 42:
167       case 43:
168       return 11;
169       case 44:
170       case 45:
171       return 4;
172       case 46:
173       case 47:
174       return 0;
175       default:
176       echo "something went wrong, please contact the admin <br>";
177       return 0;
178     }
179 }
180
181 function display_card($card)
182 {
183   if( $card/2 - (int)($card/2) == 0.5)
184     echo "<img src=\"cards/".$card.".png\" height=\"100\">";
185   else
186     echo "<img src=\"cards/".($card-1).".png\" height=\"100\">";
187   return;
188 }
189    function display_link_card($card,$me)
190 {
191   if( $card/2 - (int)($card/2) == 0.5)
192     echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".$card.".png\" height=\"100\"></a>";
193   else
194     echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".($card-1).".png\" height=\"100\"></a>";
195   return;
196 }
197
198 function save_status()
199 {
200   global $player,$game,$hash,$history;
201
202   $output = fopen("status.txt","w");
203   if ($output)
204     {
205       foreach($hash as $key)
206         {
207           /* sorting the options, not sure why I do that actually */
208           $tmp="";
209           if( ereg("i",$player[$key]["option"]) )
210             $tmp.="i";
211           if( ereg("s",$player[$key]["option"]) )
212             $tmp.="s";
213           if( ereg("t",$player[$key]["option"]) )
214             $tmp.="t";
215           if( ereg("c",$player[$key]["option"]) )
216             $tmp.="c";
217           if( ereg("N",$player[$key]["option"]) )
218             $tmp.="N";
219           if( ereg("W",$player[$key]["option"]) )
220             $tmp.="W";
221           if( ereg("P",$player[$key]["option"]) )
222             $tmp.="P";
223           if( ereg("O",$player[$key]["option"]) )
224             $tmp.="O";
225           if( ereg("S",$player[$key]["option"]) )
226             $tmp.="S";
227           if( ereg("Q",$player[$key]["option"]) )
228             $tmp.="Q";
229           if( ereg("J",$player[$key]["option"]) )
230             $tmp.="J";
231           if( ereg("C",$player[$key]["option"]) )
232             $tmp.="C";
233           if( ereg("A",$player[$key]["option"]) )
234             $tmp.="A";
235           if( ereg("H",$player[$key]["option"]) )
236             $tmp.="H";
237           $player[$key]["option"]=$tmp;
238
239           /* saving the player stats */
240           fwrite($output,"".$player[$key]["hash"].":" );
241           fwrite($output,"".$player[$key]["name"].":" );
242           fwrite($output,"".$player[$key]["email"].":" );
243           fwrite($output,"".$player[$key]["option"].":" );
244           fwrite($output,"".$player[$key]["points"].":" );
245           fwrite($output,"".$player[$key]["cards"] .":");
246           fwrite($output,"\n");
247         }
248       fwrite($output,"\n");
249       foreach($history as $line)
250         fwrite($output,$line);
251
252       fwrite($output,"\n");
253       fclose($output);
254     }
255   else
256     echo "can't open file for writing, please inform the admin.";
257   
258   return;
259 }
260
261 $history=array();
262
263 /* check for status file and read it, if possible */
264
265 if(file_exists("status.txt"))
266   $lines = file("status.txt");
267  else
268    die("no file");
269
270 /* check if we want to start a new game */
271 if( isset($_REQUEST["PlayerA"]) && 
272     isset($_REQUEST["PlayerB"]) && 
273     isset($_REQUEST["PlayerC"]) && 
274     isset($_REQUEST["PlayerD"]) && 
275     isset($_REQUEST["EmailA"]) && 
276     isset($_REQUEST["EmailB"]) && 
277     isset($_REQUEST["EmailC"]) && 
278     isset($_REQUEST["EmailD"]) && sizeof($lines<2))
279   {
280     $PlayerA = $_REQUEST["PlayerA"];
281     $PlayerB = $_REQUEST["PlayerB"];
282     $PlayerC = $_REQUEST["PlayerC"];
283     $PlayerD = $_REQUEST["PlayerD"];
284     $EmailA  = $_REQUEST["EmailA"] ;
285     $EmailB  = $_REQUEST["EmailB"] ;
286     $EmailC  = $_REQUEST["EmailC"] ;
287     $EmailD  = $_REQUEST["EmailD"] ;
288     
289     $hashA = md5("AGameOfDoko".$PlayerA.$EmailA);
290     $hashB = md5("AGameOfDoko".$PlayerB.$EmailB);
291     $hashC = md5("AGameOfDoko".$PlayerC.$EmailC);
292     $hashD = md5("AGameOfDoko".$PlayerD.$EmailD);
293
294     /* send out email, check for error with email */
295
296     $message = "\n".
297       "you are invited to play a game of DoKo.\n".
298       "The whole round would consist of the following players:\n".
299       "$PlayerA\n".
300       "$PlayerB\n".
301       "$PlayerC\n".
302       "$PlayerD\n\n".
303       "If you want to join this game, please follow this link:\n\n".
304       " http://doko.nubati.net/index.php?a=";
305     
306     mymail($EmailA,"Invite for a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
307     mymail($EmailB,"Invite for a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
308     mymail($EmailC,"Invite for a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
309     mymail($EmailD,"Invite for a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
310     
311     /* read in random.txt */
312     if(file_exists("random.txt"))
313       $random = file("random.txt");
314     else
315       die("no random file");
316  
317     $randomNR = explode( ":", $random[1] );
318     
319     /* write initial status into file */
320     $output = fopen("status.txt","w");
321     if ($output)
322       {
323         fwrite($output, "$hashA:$PlayerA:$EmailA:::" );
324         for($i=0;$i<11;$i++)
325           fwrite($output,"$randomNR[$i];" );
326         fwrite($output,"$randomNR[11]:" ); $i++;
327         fwrite($output,"\n");
328         
329         fwrite($output, "$hashB:$PlayerB:$EmailB:::" );
330         for(;$i<23;$i++)
331           fwrite($output,"$randomNR[$i];" );
332         fwrite($output,"$randomNR[23]:" ); $i++;
333         fwrite($output,"\n");
334         
335         fwrite($output, "$hashC:$PlayerC:$EmailC:::" );
336         for(;$i<35;$i++)
337           fwrite($output,"$randomNR[$i];" );
338         fwrite($output,"$randomNR[35]:" ); $i++;
339         fwrite($output,"\n");
340         
341         fwrite($output, "$hashD:$PlayerD:$EmailD:::");
342         for(;$i<47;$i++)
343           fwrite($output,"$randomNR[$i];" );
344         fwrite($output,"$randomNR[47]:" );
345         fwrite($output,"\n");
346         
347         fclose($output);
348       }
349     else
350       echo "can't open file for writing";
351   };
352
353 /* test if a game is running, else output everything for a new game */
354 if(sizeof($lines)<2)
355   {
356 ?>
357     <p> no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct! </p>
358  <form action="index.php" method="post">
359    Name:  <input name="PlayerA" type="text" size="10" maxlength="20" /> 
360    Email: <input name="EmailA"  type="text" size="10" maxlength="20" /> <br />
361
362    Name:  <input name="PlayerB" type="text" size="10" maxlength="20" /> 
363    Email: <input name="EmailB"  type="text" size="10" maxlength="20" /> <br />
364
365    Name:  <input name="PlayerC" type="text" size="10" maxlength="20" /> 
366    Email: <input name="EmailC"  type="text" size="10" maxlength="20" /> <br />
367
368    Name:  <input name="PlayerD" type="text" size="10" maxlength="20" /> 
369    Email: <input name="EmailD"  type="text" size="10" maxlength="20" /> <br />
370
371    <input type="submit" value="start game" />
372  </form>
373 <?php
374    }
375  else
376    { /* load game status */
377      $game["init"]=0;
378      $game["solo-who"]=-1;
379      $game["solo-what"]="";
380      $game["wedding"]=0;
381      $game["poverty"]=0;
382      $game["nines"]=0;
383      
384      $tmp = explode( ":",$lines[0]);
385      $hash[0]   = $tmp[0];
386      $player[$tmp[0]]["number"] = 0;
387      $player[$tmp[0]]["hash"]   = $tmp[0];
388      $player[$tmp[0]]["name"]   = $tmp[1];
389      $player[$tmp[0]]["email"]  = $tmp[2];
390      $player[$tmp[0]]["option"] = $tmp[3];
391      $player[$tmp[0]]["points"] = $tmp[4];
392      $player[$tmp[0]]["cards"]  = $tmp[5];
393      if(ereg("s",$tmp[3])) $game["init"]++;
394
395      $tmp = explode( ":",$lines[1]);
396      $hash[1]   = $tmp[0];
397      $player[$tmp[0]]["number"] = 1;
398      $player[$tmp[0]]["hash"]   = $tmp[0];
399      $player[$tmp[0]]["name"]   = $tmp[1];
400      $player[$tmp[0]]["email"]  = $tmp[2];
401      $player[$tmp[0]]["option"] = $tmp[3];
402      $player[$tmp[0]]["points"] = $tmp[4]; 
403      $player[$tmp[0]]["cards"]  = $tmp[5];
404      if(ereg("s",$tmp[3])) $game["init"]++;
405      
406      $tmp = explode( ":",$lines[2]);
407      $hash[2]   = $tmp[0];
408      $player[$tmp[0]]["number"] = 2;
409      $player[$tmp[0]]["hash"]   = $tmp[0];
410      $player[$tmp[0]]["name"]   = $tmp[1];
411      $player[$tmp[0]]["email"]  = $tmp[2];
412      $player[$tmp[0]]["option"] = $tmp[3];
413      $player[$tmp[0]]["points"] = $tmp[4];
414      $player[$tmp[0]]["cards"]  = $tmp[5];
415      if(ereg("s",$tmp[3])) $game["init"]++;
416      
417      $tmp = explode( ":",$lines[3]);
418      $hash[3]   = $tmp[0];
419      $player[$tmp[0]]["number"] = 3;
420      $player[$tmp[0]]["hash"]   = $tmp[0];
421      $player[$tmp[0]]["name"]   = $tmp[1];
422      $player[$tmp[0]]["email"]  = $tmp[2];
423      $player[$tmp[0]]["option"] = $tmp[3];
424      $player[$tmp[0]]["points"] = $tmp[4];
425      $player[$tmp[0]]["cards"]  = $tmp[5];
426      if(ereg("s",$tmp[3])) $game["init"]++;
427
428      /* save the game history */
429      for($i=4;$i<sizeof($lines);$i++)
430        {
431          if(!ereg("^[[:space:]]*$",trim($lines[$i])))
432            {
433              $history[] = $lines[$i];
434            }
435        }
436      if(sizeof($history)== 0)
437        $history[] = "0:";
438
439 /*     **
440  *    *  *
441  *    ****
442  *    *  *
443  *
444  * check if a player wants to accept a game 
445  */
446      
447      if(isset($_REQUEST["a"]))
448        {
449          $a=$_REQUEST["a"];
450          
451          if( ereg("[is]",$player[$a]["option"]) &&  $game["init"]<4)
452            {
453              echo "just wait for the game to start";
454            }
455          else  if( !ereg("[is]",$player[$a]["option"]) )
456            {
457
458  ?>
459  <form action="index.php" method="post">
460    Do you want to play a game of DoKo?
461    yes<input type="radio" name="in" value="yes" />
462    no<input type="radio" name="in" value="no" /> <br />
463
464    Do you want to get an email for every card played or only if it your move?
465    every card<input type="radio" name="update" value="card" />
466    only on my turn<input type="radio" name="update" value="turn" /> <br />
467 <?php   
468              echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
469              echo "\n";
470              echo "<input type=\"submit\" value=\"count me in\" />\n";
471              echo " </form>\n";
472            }
473        }
474
475 /*   ***
476  *   *  *
477  *   ***
478  *   *  *
479  *   ***
480  * yes? email him his hand, ask for solo, poverty, email every move or every card? 
481  */
482      if(isset($_REQUEST["b"]))
483        {
484          $b=$_REQUEST["b"];
485          
486          if( ereg("s",$player[$b]["option"])  && $game["init"]<4)
487            {
488              echo "just wait for the game to start";
489            }
490          else if(!isset($_REQUEST["in"])|| !isset($_REQUEST["update"]) )
491            {
492              echo "go back to ";
493              echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />";
494            }
495          else
496            { /* show the hand */
497              if($_REQUEST["in"]=="no")
498                {
499                  for($i=0;$i<4;$i++)
500                    {
501                      $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
502                        "the game has been cancled due to the request of one of the players.\n";
503                      mymail($player[$hash[$i]]["email"],"[DoKo] the game has been cancled",$message); 
504                    }
505                    $output = fopen("status.txt","w");
506                    if($output)
507                      fclose($output);
508                    else
509                      echo "problem opening file";
510                }
511              else
512                {
513                  if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
514                  if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
515                  
516                  $player[$b]["option"].="i";
517                  
518                  save_status();
519                  
520                  $allcards = $player[$b]["cards"];
521                  $mycards = explode(";",$allcards);
522                  
523                  sort($mycards);
524                  echo "your cards are <br>";
525                  foreach($mycards as $card) 
526                    {
527                      display_card($card);
528                    }
529                  echo "<br />\n";   
530  ?>
531  <p>aehm... at the moment please just answer everything with no, still need to implement this</p>                 
532  <form action="index.php" method="post">
533    
534    do you want to play solo? 
535    <select name="solo" size="1">
536      <option>No</option>
537      <option>No trump</option>
538      <option>Normal solo</option>
539      <option>Queen solo</option>
540      <option>Jack solo</option>
541      <option>Club solo</option>
542      <option>Spade solo</option>
543      <option>Heart solo</option>
544    </select>     
545    <br />
546
547    do you have a wedding?
548    yes<input type="radio" name="wedding" value="yes" />
549    no<input type="radio" name="wedding" value="no" /> <br />
550
551    do you have poverty?
552    yes<input type="radio" name="poverty" value="yes" />
553    no<input type="radio" name="poverty" value="no" /> <br />
554
555    do too many nines?
556    yes<input type="radio" name="nines" value="yes" />
557    no<input type="radio" name="nines" value="no" /> <br />
558    
559 <?php   
560                  echo "<input type=\"hidden\" name=\"c\" value=\"$b\" />\n";
561                  echo "<input type=\"submit\" value=\"count me in\" />\n";
562                  
563                  echo "</form>\n";
564                }
565            }
566        }
567      if(isset($_REQUEST["c"]))
568        {
569          $c=$_REQUEST["c"];
570          
571          if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) || !isset($_REQUEST["nines"]) )
572            {
573              echo "go back to ";
574              echo "<a href=\"index.php?b=$c\"> here and fill out the form </a> <br />";
575            }
576          else if(  ereg("s",$player[$c]["option"]) && $game["init"]<4 )
577            {
578              echo "just wait for the game to start";
579            }
580          else if($game["init"]<4)
581            { 
582              echo "handle krankheit <br />";
583              if( $_REQUEST["solo"]!="No")
584                {
585                  switch($_REQUEST["solo"])
586                    {
587                    case "No trump":
588                      $player[$c]["option"].="O";
589                      break;
590                    case "Normal solo":
591                      $player[$c]["option"].="S";
592                      break;
593                    case "Queen solo":
594                      $player[$c]["option"].="Q";
595                      break;
596                    case "Jack solo":
597                      $player[$c]["option"].="J";
598                      break;
599                    case "Club solo":
600                      $player[$c]["option"].="C";
601                      break;
602                    case "Spade solo":
603                      $player[$c]["option"].="A";
604                      break;
605                    case "Hear solo":
606                      $player[$c]["option"].="H";
607                      break;
608                    }
609                }
610              else if($_REQUEST["wedding"] == "yes")
611                {
612                  echo "wedding was chosen<br>";
613                  $player[$c]["option"].="W";
614                }
615              else if($_REQUEST["poverty"] == "yes")
616                {
617                  echo "poverty was chosen<br>";
618                  $player[$c]["option"].="P"; 
619                }
620              else if($_REQUEST["nines"] == "yes")
621                {
622                  echo "nines was chosen<br>";
623                  $player[$c]["option"].="N";
624                }
625              $message = "you're in. once everyone has filled out the form,".
626                "the game will start and you'll get an eamil on your turn\n";
627              mymail($player[$c]["email"],"[DoKo] the game will start soon",$message); 
628              
629              $player[$c]["option"].="s";
630
631              save_status();
632            }
633        }
634      if($game["init"]==4)
635        {
636          if(!isset($_REQUEST["me"]))
637            echo "a game is in progress, but you are not playing";
638          else
639            {
640              $me = $_REQUEST["me"];
641
642              echo "game in progress and you are in it<br>";
643              foreach($history as $play)
644                {
645                  echo "<br />";
646
647                  $trick = explode(":",$play);
648                  
649                  $last=-2;
650                  /* found old trick, display it */
651                  for($i=0;$i<sizeof($trick)-1;$i++)
652                    {
653                      $card=$trick[$i];
654                      if(ereg("->",$card))
655                        {
656                          $tmp = explode("->",$card);
657                          echo $player[$hash[$tmp[0]]]["name"]." played ";
658                          display_card($tmp[1]);
659                          $last=$tmp[0];
660                        }
661                    }
662                }
663              
664              $next = $last + 1;
665              if ($next>=4) 
666                $next -= 4 ;
667              if($last<0)
668                {
669                  $next=$history[sizeof($history)-1][0];
670                }
671
672
673              if(isset($_REQUEST["card"]))
674                {
675                  if($hash[$next]==$me)
676                    {
677                      $card=$_REQUEST["card"];
678                      $mycards = explode(";",$player[$me]["cards"]);
679                      if(in_array($card,$mycards))
680                        {
681                          $tmp=array();
682                          foreach($mycards as $m)
683                            if($m!=$card)
684                              $tmp[]=$m;
685                          $tmp2="";
686                          for($i=0;$i<sizeof($tmp)-1;$i++)
687                            {
688                              $tmp2.=$tmp[$i].";";
689                            }
690                          $tmp2.=$tmp[$i];
691                          $player[$me]["cards"]=$tmp2;
692                          
693                          if($last<0)
694                            {
695                              $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n";
696                            }
697                          else
698                            {
699                              $tmp = explode(":",$history[sizeof($history)-1]);
700                              $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
701                              $history[sizeof($history)-1]=join(":",$tmp);
702                            }
703                          save_status();
704
705                          echo " you played ";
706                          display_card($card);
707                          /* send out email to players who want/need to get informed */
708                          for($i=0;$i<4;$i++)
709                            {
710                              $mynext=$next+1; if($mynext>3)$mynext-=4;
711                              if((ereg("c",$player[$hash[$i]]["option"]) || $i==$mynext) && $hash[$i]!=$me)
712                                {
713                                  $message = " Hello ".$player[$hash[$i]]["name"].",\n\n";
714                                    
715                                  if($i==$mynext)
716                                    $message .= "it's your turn  now.\n";
717                                  $message .= $player[$me]["name"]. "has played the following card ".card_to_name($card)."\n";
718                                  
719                                  mymail($player[$hash[$i]]["email"],"[DoKo] a card has been played",$message);
720                                  echo "<a href=\"index.php?me=".$hash[$mynext]."\"> next player </a> <br />";
721                                }
722                            }
723                        }
724                      else
725                        echo "seems like you don't have that card<br>";
726                           
727                    }
728                  
729                }
730              else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
731                {
732                  $win=$_REQUEST["win"];
733                  $history[]=$win.":\n";
734                  /* count points of the last trick */
735                  $points=0;
736
737                  $tmp = explode(":",$history[sizeof($history)-2]);
738                  for($i=0;$i<4;$i++)
739                    {
740                      $tmp2 = explode("->",$tmp[$i]);
741                      $c = $tmp2[1];
742                      $points += card_value($c);
743                    }
744                  $player[$hash[$win]]["points"]+=$points;
745                  echo "<br> ".$player[$hash[$win]]["name"]." won: $points Points <br>";
746
747                  save_status();
748                }
749              echo "<br />";
750
751              $tmp = explode(":",$history[sizeof($history)-1]);
752
753              if(sizeof($tmp)==5)
754                {
755                  ?>
756 <form action="index.php" method="post">
757                           
758 <?php 
759    for($i=0;$i<4;$i++)
760      echo $player[$hash[$i]]["name"]." <input type=\"radio\" name=\"win\" value=\"$i\" />";
761    echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />";
762 ?>
763 <input type="submit" value="who will win?" />
764
765 </form>
766 <?php
767                }
768              else if(sizeof($tmp)<5 && 1<sizeof($tmp) && !isset($_REQUEST["card"]))
769                {                 
770                  if(sizeof($tmp)==2 && strlen($tmp[0])==1)
771                    {
772                      $next=$tmp[0];
773
774                      /*
775                       * echo "DEBUG: the next move is for <a href=\"index.php?me=".$hash[$next]."\">the next player</a><br>";
776                       */
777                      if(strlen(trim($player[$me]["cards"]))==0)
778                        {
779                          echo "<br> game over, count points <br>";
780                          for($i=0;$i<4;$i++)
781                            {
782                              echo $player[$hash[$i]]["name"]." got ".$player[$hash[$i]]["points"]."<br>";
783                            }
784                        }
785                    }
786                  if($hash[$next]==$me && strlen(trim($player[$me]["cards"]))>0 )
787                    {
788                      
789                      echo "ITS YOUR TURN<br>";
790                      $allcards = trim($player[$me]["cards"]);
791                      $mycards = explode(";",$allcards);
792                      
793                      sort($mycards);
794                      echo "your cards are <br>";
795                      foreach($mycards as $card) 
796                        {
797                          display_link_card($card,$me);
798                        }
799                      echo "<br />\n";   
800                    }
801                  echo "<br />";
802                  
803                }
804            }
805        }
806
807  } 
808
809 ?>
810
811 </body>
812 </html>