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">
6 <title>Doko via email</title>
7 <link rel="stylesheet" type="text/css" href="standard.css"/>
10 <h1> Welcome to E-Doko </h1>
14 function mymail($To,$Subject,$message)
18 echo "<br>To: $To<br>Subject: $Subject <br>$message<br>";
20 mail($To,$Subject,$message);
24 function card_to_name($card)
30 return "ten of hearts";
33 return "queen of clubs";
36 return "queen of spades";
39 return "queen of hearts";
42 return "queen of diamonds";
45 return "jack of clubs";
48 return "jack of spades";
51 return "jack of hearts";
54 return "jack of diamonds";
57 return "ace of diamonds";
60 return "ten of diamonds";
63 return "king of diamonds";
66 return "nine of diamonds";;
69 return "ace of clubs";
72 return "ten of clubs";
75 return "king of clubs";
78 return "nine of clubs";
81 return "ace of spades";
84 return "ten of spades";
87 return "king of spades";
90 return "nine of spades";
93 return "ace of hearts";
96 return "ace of diamonds";
99 return "nine of diamonds";
101 return "something went wrong, please contact the admin";
105 function card_value($card)
176 echo "something went wrong, please contact the admin <br>";
181 function display_card($card)
183 if( $card/2 - (int)($card/2) == 0.5)
184 echo "<img src=\"cards/".$card.".png\" height=\"100\">";
186 echo "<img src=\"cards/".($card-1).".png\" height=\"100\">";
189 function display_link_card($card,$me)
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>";
194 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".($card-1).".png\" height=\"100\"></a>";
198 function save_status()
200 global $player,$game,$hash,$history;
202 $output = fopen("status.txt","w");
205 foreach($hash as $key)
207 /* sorting the options, not sure why I do that actually */
209 if( ereg("i",$player[$key]["option"]) )
211 if( ereg("s",$player[$key]["option"]) )
213 if( ereg("t",$player[$key]["option"]) )
215 if( ereg("c",$player[$key]["option"]) )
217 if( ereg("N",$player[$key]["option"]) )
219 if( ereg("W",$player[$key]["option"]) )
221 if( ereg("P",$player[$key]["option"]) )
223 if( ereg("O",$player[$key]["option"]) )
225 if( ereg("S",$player[$key]["option"]) )
227 if( ereg("Q",$player[$key]["option"]) )
229 if( ereg("J",$player[$key]["option"]) )
231 if( ereg("C",$player[$key]["option"]) )
233 if( ereg("A",$player[$key]["option"]) )
235 if( ereg("H",$player[$key]["option"]) )
237 $player[$key]["option"]=$tmp;
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");
248 fwrite($output,"\n");
249 foreach($history as $line)
250 fwrite($output,$line);
252 fwrite($output,"\n");
256 echo "can't open file for writing, please inform the admin.";
263 /* check for status file and read it, if possible */
265 if(file_exists("status.txt"))
266 $lines = file("status.txt");
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))
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"] ;
289 $hashA = md5("AGameOfDoko".$PlayerA.$EmailA);
290 $hashB = md5("AGameOfDoko".$PlayerB.$EmailB);
291 $hashC = md5("AGameOfDoko".$PlayerC.$EmailC);
292 $hashD = md5("AGameOfDoko".$PlayerD.$EmailD);
294 /* send out email, check for error with email */
297 "you are invited to play a game of DoKo.\n".
298 "The whole round would consist of the following players:\n".
303 "If you want to join this game, please follow this link:\n\n".
304 " http://doko.nubati.net/index.php?a=";
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);
311 /* read in random.txt */
312 if(file_exists("random.txt"))
313 $random = file("random.txt");
315 die("no random file");
317 $randomNR = explode( ":", $random[1] );
319 /* write initial status into file */
320 $output = fopen("status.txt","w");
323 fwrite($output, "$hashA:$PlayerA:$EmailA:::" );
325 fwrite($output,"$randomNR[$i];" );
326 fwrite($output,"$randomNR[11]:" ); $i++;
327 fwrite($output,"\n");
329 fwrite($output, "$hashB:$PlayerB:$EmailB:::" );
331 fwrite($output,"$randomNR[$i];" );
332 fwrite($output,"$randomNR[23]:" ); $i++;
333 fwrite($output,"\n");
335 fwrite($output, "$hashC:$PlayerC:$EmailC:::" );
337 fwrite($output,"$randomNR[$i];" );
338 fwrite($output,"$randomNR[35]:" ); $i++;
339 fwrite($output,"\n");
341 fwrite($output, "$hashD:$PlayerD:$EmailD:::");
343 fwrite($output,"$randomNR[$i];" );
344 fwrite($output,"$randomNR[47]:" );
345 fwrite($output,"\n");
350 echo "can't open file for writing";
353 /* test if a game is running, else output everything for a new game */
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 />
362 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
363 Email: <input name="EmailB" type="text" size="10" maxlength="20" /> <br />
365 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
366 Email: <input name="EmailC" type="text" size="10" maxlength="20" /> <br />
368 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
369 Email: <input name="EmailD" type="text" size="10" maxlength="20" /> <br />
371 <input type="submit" value="start game" />
376 { /* load game status */
378 $game["solo-who"]=-1;
379 $game["solo-what"]="";
384 $tmp = explode( ":",$lines[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"]++;
395 $tmp = explode( ":",$lines[1]);
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"]++;
406 $tmp = explode( ":",$lines[2]);
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"]++;
417 $tmp = explode( ":",$lines[3]);
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"]++;
428 /* save the game history */
429 for($i=4;$i<sizeof($lines);$i++)
431 if(!ereg("^[[:space:]]*$",trim($lines[$i])))
433 $history[] = $lines[$i];
436 if(sizeof($history)== 0)
444 * check if a player wants to accept a game
447 if(isset($_REQUEST["a"]))
451 if( ereg("[is]",$player[$a]["option"]) && $game["init"]<4)
453 echo "just wait for the game to start";
455 else if( !ereg("[is]",$player[$a]["option"]) )
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 />
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 />
468 echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
470 echo "<input type=\"submit\" value=\"count me in\" />\n";
480 * yes? email him his hand, ask for solo, poverty, email every move or every card?
482 if(isset($_REQUEST["b"]))
486 if( ereg("s",$player[$b]["option"]) && $game["init"]<4)
488 echo "just wait for the game to start";
490 else if(!isset($_REQUEST["in"])|| !isset($_REQUEST["update"]) )
493 echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />";
496 { /* show the hand */
497 if($_REQUEST["in"]=="no")
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);
505 $output = fopen("status.txt","w");
509 echo "problem opening file";
513 if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
514 if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
516 $player[$b]["option"].="i";
520 $allcards = $player[$b]["cards"];
521 $mycards = explode(";",$allcards);
524 echo "your cards are <br>";
525 foreach($mycards as $card)
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">
534 do you want to play solo?
535 <select name="solo" size="1">
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>
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 />
552 yes<input type="radio" name="poverty" value="yes" />
553 no<input type="radio" name="poverty" value="no" /> <br />
556 yes<input type="radio" name="nines" value="yes" />
557 no<input type="radio" name="nines" value="no" /> <br />
560 echo "<input type=\"hidden\" name=\"c\" value=\"$b\" />\n";
561 echo "<input type=\"submit\" value=\"count me in\" />\n";
567 if(isset($_REQUEST["c"]))
571 if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) || !isset($_REQUEST["nines"]) )
574 echo "<a href=\"index.php?b=$c\"> here and fill out the form </a> <br />";
576 else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
578 echo "just wait for the game to start";
580 else if($game["init"]<4)
582 echo "handle krankheit <br />";
583 if( $_REQUEST["solo"]!="No")
585 switch($_REQUEST["solo"])
588 $player[$c]["option"].="O";
591 $player[$c]["option"].="S";
594 $player[$c]["option"].="Q";
597 $player[$c]["option"].="J";
600 $player[$c]["option"].="C";
603 $player[$c]["option"].="A";
606 $player[$c]["option"].="H";
610 else if($_REQUEST["wedding"] == "yes")
612 echo "wedding was chosen<br>";
613 $player[$c]["option"].="W";
615 else if($_REQUEST["poverty"] == "yes")
617 echo "poverty was chosen<br>";
618 $player[$c]["option"].="P";
620 else if($_REQUEST["nines"] == "yes")
622 echo "nines was chosen<br>";
623 $player[$c]["option"].="N";
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);
629 $player[$c]["option"].="s";
636 if(!isset($_REQUEST["me"]))
637 echo "a game is in progress, but you are not playing";
640 $me = $_REQUEST["me"];
642 echo "game in progress and you are in it<br>";
643 foreach($history as $play)
647 $trick = explode(":",$play);
650 /* found old trick, display it */
651 for($i=0;$i<sizeof($trick)-1;$i++)
656 $tmp = explode("->",$card);
657 echo $player[$hash[$tmp[0]]]["name"]." played ";
658 display_card($tmp[1]);
669 $next=$history[sizeof($history)-1][0];
673 if(isset($_REQUEST["card"]))
675 if($hash[$next]==$me)
677 $card=$_REQUEST["card"];
678 $mycards = explode(";",$player[$me]["cards"]);
679 if(in_array($card,$mycards))
682 foreach($mycards as $m)
686 for($i=0;$i<sizeof($tmp)-1;$i++)
691 $player[$me]["cards"]=$tmp2;
695 $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n";
699 $tmp = explode(":",$history[sizeof($history)-1]);
700 $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
701 $history[sizeof($history)-1]=join(":",$tmp);
707 /* send out email to players who want/need to get informed */
710 $mynext=$next+1; if($mynext>3)$mynext-=4;
711 if((ereg("c",$player[$hash[$i]]["option"]) || $i==$mynext) && $hash[$i]!=$me)
713 $message = " Hello ".$player[$hash[$i]]["name"].",\n\n";
716 $message .= "it's your turn now.\n";
717 $message .= $player[$me]["name"]. "has played the following card ".card_to_name($card)."\n";
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 />";
725 echo "seems like you don't have that card<br>";
730 else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
732 $win=$_REQUEST["win"];
733 $history[]=$win.":\n";
734 /* count points of the last trick */
737 $tmp = explode(":",$history[sizeof($history)-2]);
740 $tmp2 = explode("->",$tmp[$i]);
742 $points += card_value($c);
744 $player[$hash[$win]]["points"]+=$points;
745 echo "<br> ".$player[$hash[$win]]["name"]." won: $points Points <br>";
751 $tmp = explode(":",$history[sizeof($history)-1]);
756 <form action="index.php" method="post">
760 echo $player[$hash[$i]]["name"]." <input type=\"radio\" name=\"win\" value=\"$i\" />";
761 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />";
763 <input type="submit" value="who will win?" />
768 else if(sizeof($tmp)<5 && 1<sizeof($tmp) && !isset($_REQUEST["card"]))
770 if(sizeof($tmp)==2 && strlen($tmp[0])==1)
775 * echo "DEBUG: the next move is for <a href=\"index.php?me=".$hash[$next]."\">the next player</a><br>";
777 if(strlen(trim($player[$me]["cards"]))==0)
779 echo "<br> game over, count points <br>";
782 echo $player[$hash[$i]]["name"]." got ".$player[$hash[$i]]["points"]."<br>";
786 if($hash[$next]==$me && strlen(trim($player[$me]["cards"]))>0 )
789 echo "ITS YOUR TURN<br>";
790 $allcards = trim($player[$me]["cards"]);
791 $mycards = explode(";",$allcards);
794 echo "your cards are <br>";
795 foreach($mycards as $card)
797 display_link_card($card,$me);