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">
7 <link rel="stylesheet" type="text/css" href="standard.css"/>
10 <h1> Welcome to E-Doko </h1>
17 $host = "http://doko.nubati.net/index.php";
26 function mymail($To,$Subject,$message)
32 str_replace("\n","<br />",$message);
33 echo "<br>To: $To<br>Subject: $Subject <br>$message<br>";
36 mail($To,$Subject,$message);
40 function parse_status()
42 global $game,$history,$player,$hash,$lines;
45 $game["solo-who"] = -1;
46 $game["solo-what"] = "todo";
47 $game["wedding"] = -1;
48 $game["poverty"] = -1;
50 $game["startplayer"] = 0;
54 $tmp = explode( ":",$lines[$i]);
56 $player[$tmp[0]]["number"] = $i;
57 $player[$tmp[0]]["hash"] = $tmp[0];
58 $player[$tmp[0]]["name"] = $tmp[1];
59 $player[$tmp[0]]["email"] = $tmp[2];
60 $player[$tmp[0]]["option"] = $tmp[3];
61 $player[$tmp[0]]["points"] = $tmp[4];
62 $player[$tmp[0]]["cards"] = $tmp[5];
63 if(ereg("s",$tmp[3])) $game["init"]++;
64 if(ereg("P",$tmp[3])) $game["poverty"] = $i;
65 if(ereg("N",$tmp[3])) $game["nines"] = $i;
66 if(ereg("W",$tmp[3])) $game["wedding"] = $i;
67 if(ereg("[OSQJCAH]",$tmp[3]) && ($game["solo-who"]<0) )
69 $game["solo-who"] = $i;
70 $game["startplayer"] = $i;
74 /* save the game history */
75 for($i=4;$i<sizeof($lines);$i++)
77 if(!ereg("^[[:space:]]*$",trim($lines[$i])))
79 $history[] = $lines[$i];
83 if(sizeof($history)==0 || (sizeof($history)==1 && strlen($history[0])==3 ))
84 $history[0] = $game["startplayer"].":";
89 function count_nines($cards)
91 $card = explode(";",$cards);
97 if($c == "25" || $c == "26") $nines++;
98 else if($c == "33" || $c == "34") $nines++;
99 else if($c == "41" || $c == "42") $nines++;
100 else if($c == "47" || $c == "48") $nines++;
106 function check_wedding($cards)
108 $card = explode(";",$cards);
112 if( in_array("3",$card) && in_array("2",$card) )
118 function count_trump($cards)
120 $card = explode(";",$cards);
124 /* count each trump */
127 if( (int)($c) <27) $trump++;
130 /* subtract one, in case player has both foxes */
131 if( in_array("19",$card) && in_array("20",$card) )
139 function card_to_name($card)
145 return "ten of hearts";
148 return "queen of clubs";
151 return "queen of spades";
154 return "queen of hearts";
157 return "queen of diamonds";
160 return "jack of clubs";
163 return "jack of spades";
166 return "jack of hearts";
169 return "jack of diamonds";
172 return "ace of diamonds";
175 return "ten of diamonds";
178 return "king of diamonds";
181 return "nine of diamonds";;
184 return "ace of clubs";
187 return "ten of clubs";
190 return "king of clubs";
193 return "nine of clubs";
196 return "ace of spades";
199 return "ten of spades";
202 return "king of spades";
205 return "nine of spades";
208 return "ace of hearts";
211 return "ace of diamonds";
214 return "nine of diamonds";
216 return "something went wrong, please contact the admin";
220 function card_value($card)
291 echo "something went wrong, please contact the admin <br>";
296 function display_card($card)
298 if( $card/2 - (int)($card/2) == 0.5)
299 echo "<img src=\"cards/".$card.".png\" height=\"100\">";
301 echo "<img src=\"cards/".($card-1).".png\" height=\"100\">";
304 function display_link_card($card,$me)
306 if( $card/2 - (int)($card/2) == 0.5)
307 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".$card.".png\" height=\"100\"></a>";
309 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".($card-1).".png\" height=\"100\"></a>";
313 function save_status()
315 global $player,$game,$hash,$history;
317 $output = fopen("status.txt","w");
320 foreach($hash as $key)
322 /* sorting the options, not sure why I do that actually */
324 if( ereg("i",$player[$key]["option"]) )
326 if( ereg("s",$player[$key]["option"]) )
328 if( ereg("t",$player[$key]["option"]) )
330 if( ereg("c",$player[$key]["option"]) )
332 if( ereg("N",$player[$key]["option"]) )
334 if( ereg("W",$player[$key]["option"]) )
336 if( ereg("P",$player[$key]["option"]) )
338 if( ereg("O",$player[$key]["option"]) )
340 if( ereg("S",$player[$key]["option"]) )
342 if( ereg("Q",$player[$key]["option"]) )
344 if( ereg("J",$player[$key]["option"]) )
346 if( ereg("C",$player[$key]["option"]) )
348 if( ereg("A",$player[$key]["option"]) )
350 if( ereg("H",$player[$key]["option"]) )
352 $player[$key]["option"]=$tmp;
354 /* saving the player stats */
355 fwrite($output,"".$player[$key]["hash"].":" );
356 fwrite($output,"".$player[$key]["name"].":" );
357 fwrite($output,"".$player[$key]["email"].":" );
358 fwrite($output,"".$player[$key]["option"].":" );
359 fwrite($output,"".$player[$key]["points"].":" );
360 fwrite($output,"".$player[$key]["cards"] .":");
361 fwrite($output,"\n");
363 fwrite($output,"\n");
364 foreach($history as $line)
365 fwrite($output,$line);
367 fwrite($output,"\n");
371 echo "can't open file for writing, please inform the admin.";
378 /* check for status file and read it, if possible */
380 if(file_exists("status.txt"))
381 $lines = file("status.txt");
385 /* check if we want to start a new game */
386 if( isset($_REQUEST["PlayerA"]) &&
387 isset($_REQUEST["PlayerB"]) &&
388 isset($_REQUEST["PlayerC"]) &&
389 isset($_REQUEST["PlayerD"]) &&
390 isset($_REQUEST["EmailA"]) &&
391 isset($_REQUEST["EmailB"]) &&
392 isset($_REQUEST["EmailC"]) &&
393 isset($_REQUEST["EmailD"]) && sizeof($lines<2))
395 $PlayerA = $_REQUEST["PlayerA"];
396 $PlayerB = $_REQUEST["PlayerB"];
397 $PlayerC = $_REQUEST["PlayerC"];
398 $PlayerD = $_REQUEST["PlayerD"];
399 $EmailA = $_REQUEST["EmailA"] ;
400 $EmailB = $_REQUEST["EmailB"] ;
401 $EmailC = $_REQUEST["EmailC"] ;
402 $EmailD = $_REQUEST["EmailD"] ;
404 $hashA = md5("AGameOfDoko".$PlayerA.$EmailA);
405 $hashB = md5("AGameOfDoko".$PlayerB.$EmailB);
406 $hashC = md5("AGameOfDoko".$PlayerC.$EmailC);
407 $hashD = md5("AGameOfDoko".$PlayerD.$EmailD);
409 /* send out email, check for error with email */
412 "you are invited to play a game of DoKo.\n".
413 "The whole round would consist of the following players:\n".
418 "If you want to join this game, please follow this link:\n\n".
421 mymail($EmailA,"Invite for a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
422 mymail($EmailB,"Invite for a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
423 mymail($EmailC,"Invite for a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
424 mymail($EmailD,"Invite for a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
426 /* read in random.txt */
427 if(file_exists("random.txt"))
428 $random = file("random.txt");
430 die("no random file");
432 $randomNR = explode( ":", $random[1] );
434 /* write initial status into file */
435 $output = fopen("status.txt","w");
438 fwrite($output, "$hashA:$PlayerA:$EmailA:::" );
440 fwrite($output,"$randomNR[$i];" );
441 fwrite($output,"$randomNR[11]:" ); $i++;
442 fwrite($output,"\n");
444 fwrite($output, "$hashB:$PlayerB:$EmailB:::" );
446 fwrite($output,"$randomNR[$i];" );
447 fwrite($output,"$randomNR[23]:" ); $i++;
448 fwrite($output,"\n");
450 fwrite($output, "$hashC:$PlayerC:$EmailC:::" );
452 fwrite($output,"$randomNR[$i];" );
453 fwrite($output,"$randomNR[35]:" ); $i++;
454 fwrite($output,"\n");
456 fwrite($output, "$hashD:$PlayerD:$EmailD:::");
458 fwrite($output,"$randomNR[$i];" );
459 fwrite($output,"$randomNR[47]:" );
460 fwrite($output,"\n");
465 echo "can't open file for writing";
468 /* test if a game is running, else output everything for a new game */
472 <p> no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct! </p>
473 <form action="index.php" method="post">
474 Name: <input name="PlayerA" type="text" size="10" maxlength="20" />
475 Email: <input name="EmailA" type="text" size="10" maxlength="20" /> <br />
477 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
478 Email: <input name="EmailB" type="text" size="10" maxlength="20" /> <br />
480 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
481 Email: <input name="EmailC" type="text" size="10" maxlength="20" /> <br />
483 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
484 Email: <input name="EmailD" type="text" size="10" maxlength="20" /> <br />
486 <input type="submit" value="start game" />
491 { /* load game status */
498 * check if a player wants to accept a game
501 if(isset($_REQUEST["a"]))
505 if( ereg("[is]",$player[$a]["option"]) && $game["init"]<4)
507 echo "just wait for the game to start";
509 else if( !ereg("[is]",$player[$a]["option"]) )
513 <form action="index.php" method="post">
514 Do you want to play a game of DoKo?
515 yes<input type="radio" name="in" value="yes" />
516 no<input type="radio" name="in" value="no" /> <br />
518 Do you want to get an email for every card played or only if it your move?
519 every card<input type="radio" name="update" value="card" />
520 only on my turn<input type="radio" name="update" value="turn" /> <br />
522 echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
524 echo "<input type=\"submit\" value=\"count me in\" />\n";
534 * yes? email him his hand, ask for solo, poverty, email every move or every card?
536 if(isset($_REQUEST["b"]))
540 if( ereg("s",$player[$b]["option"]) && $game["init"]<4)
542 echo "just wait for the game to start";
544 else if( (!isset($_REQUEST["in"])|| !isset($_REQUEST["update"])) && !ereg("i",$player[$b]["option"]))
547 echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />";
550 { /* show the hand */
551 if($_REQUEST["in"]=="no")
555 $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
556 "the game has been cancled due to the request of one of the players.\n";
557 mymail($player[$hash[$i]]["email"],"[DoKo] the game has been cancled",$message);
559 $output = fopen("status.txt","w");
563 echo "problem opening file";
567 if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
568 if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
570 $player[$b]["option"].="i";
574 $allcards = $player[$b]["cards"];
575 $mycards = explode(";",$allcards);
578 echo "your cards are <br>";
579 foreach($mycards as $card)
585 <p>aehm... at the moment please just answer everything with no, still need to implement this</p>
586 <form action="index.php" method="post">
588 do you want to play solo?
589 <select name="solo" size="1">
591 <option>No trump</option>
592 <option>Normal solo</option>
593 <option>Queen solo</option>
594 <option>Jack solo</option>
595 <option>Club solo</option>
596 <option>Spade solo</option>
597 <option>Heart solo</option>
604 if(check_wedding($player[$b]["cards"]))
606 echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" />";
607 echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />";
611 echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />";
614 echo "do you have poverty?";
615 if(count_trump($player[$b]["cards"])<4)
617 echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" />";
618 echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />";
622 echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />";
625 echo "do you have too many nines?";
626 if(count_nines($player[$b]["cards"])>4)
628 echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" />";
629 echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />";
633 echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />";
636 echo "<input type=\"hidden\" name=\"c\" value=\"$b\" />\n";
637 echo "<input type=\"submit\" value=\"count me in\" />\n";
643 if(isset($_REQUEST["c"]))
647 if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) || !isset($_REQUEST["nines"]) )
650 echo "<a href=\"index.php?b=$c\"> here and fill out the form </a> <br />";
652 else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
654 echo "just wait for the game to start";
656 else if($game["init"]<4)
658 if( $_REQUEST["solo"]!="No")
660 switch($_REQUEST["solo"])
663 $player[$c]["option"].="O";
666 $player[$c]["option"].="S";
669 $player[$c]["option"].="Q";
672 $player[$c]["option"].="J";
675 $player[$c]["option"].="C";
678 $player[$c]["option"].="A";
681 $player[$c]["option"].="H";
685 else if($_REQUEST["wedding"] == "yes")
687 echo "wedding was chosen<br>";
688 $player[$c]["option"].="W";
690 else if($_REQUEST["poverty"] == "yes")
692 echo "poverty was chosen<br>";
693 $player[$c]["option"].="P";
695 else if($_REQUEST["nines"] == "yes")
697 echo "nines was chosen<br>";
698 $player[$c]["option"].="N";
701 $message = "you're in. once everyone has filled out the form,".
702 "the game will start and you'll get an eamil on your turn\n";
703 mymail($player[$c]["email"],"[DoKo] the game will start soon",$message);
705 $player[$c]["option"].="s";
707 if(file_exists("status.txt"))
708 $lines = file("status.txt");
715 $message = "The game can start now, it's your turn, please use this link to play a card:\n".
716 $host."?me=".$hash[$game["startplayer"]]."\n";
717 mymail($player[$hash[$game["startplayer"]]]["email"],"[DoKo] let's go",$message);
724 /* check for sickness*/
725 /***** someone has 5 nines and no one is playing solo=> cancel game */
726 if($game["nines"]>=0 && $game["solo-who"]<0)
728 $message = $player[$hash[$game["poverty"]]]["nines"]." has more than 4 nines. Game aborted!\n";
731 mymail($player[$hash[$i]]["email"],"[DoKo] the game has been canceled",$message);
733 $output = fopen("status.txt","w");
737 echo "problem opening file";
740 /* who is requesting this*/
741 if(!isset($_REQUEST["me"]))
742 echo "a game is in progress, but you are not playing";
745 $me = $_REQUEST["me"];
747 echo "game in progress and you are in it<br />";
748 if($game["solo-who"]>=0)
749 echo $player[$hash[$game["solo-who"]]]["name"]." is playing a ".$game["solo-what"]." solo!<br />";
750 else if($game["wedding"]>=0)
751 echo $player[$hash[$game["wedding"]]]["name"]." is playing a wedding!<br />";
753 foreach($history as $play)
757 $trick = explode(":",$play);
760 /* found old trick, display it */
761 for($i=0;$i<sizeof($trick)-1;$i++)
766 $tmp = explode("->",$card);
767 echo $player[$hash[$tmp[0]]]["name"]." played ";
768 display_card($tmp[1]);
779 $next=$history[sizeof($history)-1][0];
783 if(isset($_REQUEST["card"]))
785 if($hash[$next]==$me)
787 $card=$_REQUEST["card"];
788 $mycards = explode(";",$player[$me]["cards"]);
789 if(in_array($card,$mycards))
792 foreach($mycards as $m)
796 for($i=0;$i<sizeof($tmp)-1;$i++)
801 $player[$me]["cards"]=$tmp2;
805 $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n";
809 $tmp = explode(":",$history[sizeof($history)-1]);
810 $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
811 $history[sizeof($history)-1]=join(":",$tmp);
817 /* send out email to players who want/need to get informed */
820 $mynext=$next+1; if($mynext>3)$mynext-=4;
821 if((ereg("c",$player[$hash[$i]]["option"]) || $i==$mynext) && $hash[$i]!=$me)
823 $message = " Hello ".$player[$hash[$i]]["name"].",\n\n";
826 $message .= "it's your turn now.\n";
827 $message .= $player[$me]["name"]. "has played the following card ".card_to_name($card)."\n";
829 if($game["solo-who"]<=0)
830 $message.= $player[$hash[$game["solo-who"]]]." is playing a ".$game["solo-what"]." solo!\n";
832 mymail($player[$hash[$i]]["email"],"[DoKo] a card has been played",$message);
833 echo "<a href=\"index.php?me=".$hash[$mynext]."\"> next player </a> <br />";
838 echo "seems like you don't have that card<br>";
843 else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
845 $win=$_REQUEST["win"];
846 $history[]=$win.":\n";
847 /* count points of the last trick */
850 $tmp = explode(":",$history[sizeof($history)-2]);
853 $tmp2 = explode("->",$tmp[$i]);
855 $points += card_value($c);
857 $player[$hash[$win]]["points"]+=$points;
858 echo "<br> ".$player[$hash[$win]]["name"]." won: $points Points <br>";
864 $tmp = explode(":",$history[sizeof($history)-1]);
869 <form action="index.php" method="post">
873 echo $player[$hash[$i]]["name"]." <input type=\"radio\" name=\"win\" value=\"$i\" />";
874 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />";
876 <input type="submit" value="submit" />
881 else if(sizeof($tmp)<5 && 1<sizeof($tmp) && !isset($_REQUEST["card"]))
883 if(sizeof($tmp)==2 && strlen($tmp[0])==1)
888 echo "DEBUG: the next move is for <a href=\"index.php?me=".$hash[$next]."\">the next player</a><br>";
890 if(strlen(trim($player[$me]["cards"]))==0)
892 echo "<br> game over, count points <br>";
895 echo $player[$hash[$i]]["name"]." got ".$player[$hash[$i]]["points"]."<br>";
899 if($hash[$next]==$me && strlen(trim($player[$me]["cards"]))>0 )
902 echo "ITS YOUR TURN<br>";
903 $allcards = trim($player[$me]["cards"]);
904 $mycards = explode(";",$allcards);
907 echo "your cards are <br>";
908 foreach($mycards as $card)
910 display_link_card($card,$me);