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>
15 function card_to_name($card)
21 return "ten of hearts";
24 return "queen of clubs";
27 return "queen of spades";
30 return "queen of hearts";
33 return "queen of diamonds";
36 return "jack of clubs";
39 return "jack of spades";
42 return "jack of hearts";
45 return "jack of diamonds";
48 return "ace of diamonds";
51 return "ten of diamonds";
54 return "king of diamonds";
57 return "nine of diamonds";;
60 return "ace of clubs";
63 return "ten of clubs";
66 return "king of clubs";
69 return "nine of clubs";
72 return "ace of spades";
75 return "ten of spades";
78 return "king of spades";
81 return "nine of spades";
84 return "ace of hearts";
87 return "ace of diamonds";
90 return "nine of diamonds";
92 return "something went wrong, please contact the admin";
96 function card_value($card)
167 echo "something went wrong, please contact the admin <br>";
172 function display_card($card)
174 if( $card/2 - (int)($card/2) == 0.5)
175 echo "<img src=\"cards/".$card.".png\" height=\"100\">";
177 echo "<img src=\"cards/".($card-1).".png\" height=\"100\">";
180 function display_link_card($card,$me)
182 if( $card/2 - (int)($card/2) == 0.5)
183 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".$card.".png\" height=\"100\"></a>";
185 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".($card-1).".png\" height=\"100\"></a>";
189 function save_status()
191 global $player,$game,$hash,$history;
193 $output = fopen("status.txt","w");
196 foreach($hash as $key)
199 if( ereg("i",$player[$key]["option"]) )
201 if( ereg("s",$player[$key]["option"]) )
203 if( ereg("t",$player[$key]["option"]) )
205 if( ereg("c",$player[$key]["option"]) )
207 $player[$key]["option"]=$tmp;
209 fwrite($output,"".$player[$key]["hash"].":" );
210 fwrite($output,"".$player[$key]["name"].":" );
211 fwrite($output,"".$player[$key]["email"].":" );
212 fwrite($output,"".$player[$key]["option"].":" );
213 fwrite($output,"".$player[$key]["points"].":" );
214 fwrite($output,"".$player[$key]["cards"] .":");
215 fwrite($output,"\n");
217 fwrite($output,"\n");
218 foreach($history as $line)
219 fwrite($output,$line);
221 fwrite($output,"\n");
225 echo "can't open file for writing, please inform the admin.";
232 /* check for status file and read it, if possible */
234 if(file_exists("status.txt"))
235 $lines = file("status.txt");
239 /* check if we want to start a new game */
240 if( isset($_REQUEST["PlayerA"]) &&
241 isset($_REQUEST["PlayerB"]) &&
242 isset($_REQUEST["PlayerC"]) &&
243 isset($_REQUEST["PlayerD"]) &&
244 isset($_REQUEST["EmailA"]) &&
245 isset($_REQUEST["EmailB"]) &&
246 isset($_REQUEST["EmailC"]) &&
247 isset($_REQUEST["EmailD"]) )
249 $PlayerA = $_REQUEST["PlayerA"];
250 $PlayerB = $_REQUEST["PlayerB"];
251 $PlayerC = $_REQUEST["PlayerC"];
252 $PlayerD = $_REQUEST["PlayerD"];
253 $EmailA = $_REQUEST["EmailA"] ;
254 $EmailB = $_REQUEST["EmailB"] ;
255 $EmailC = $_REQUEST["EmailC"] ;
256 $EmailD = $_REQUEST["EmailD"] ;
258 /* send out email, check for error with email */
261 "you are invited to play a game of DoKo.\n".
262 "The whole round would consist of the following players:\n".
267 "If you want to join this game, please follow this link:\n\n".
268 " http://doko.nubati.net/index.php?a=hash";
270 mail($EmailA,"Invite for a game of DoKo","Hello $PlayerA,\n".$message."1");
271 mail($EmailB,"Invite for a game of DoKo","Hello $PlayerB,\n".$message."2");
272 mail($EmailC,"Invite for a game of DoKo","Hello $PlayerC,\n".$message."3");
273 mail($EmailD,"Invite for a game of DoKo","Hello $PlayerD,\n".$message."4");
275 /* read in random.txt */
276 if(file_exists("random.txt"))
277 $random = file("random.txt");
279 die("no random file");
281 $randomNR = explode( ":", $random[1] );
283 /* write initial status into file */
284 $output = fopen("status.txt","w");
287 fwrite($output, "hash1:$PlayerA:$EmailA:::" );
289 fwrite($output,"$randomNR[$i];" );
290 fwrite($output,"$randomNR[11]:" ); $i++;
291 fwrite($output,"\n");
293 fwrite($output, "hash2:$PlayerB:$EmailB:::" );
295 fwrite($output,"$randomNR[$i];" );
296 fwrite($output,"$randomNR[23]:" ); $i++;
297 fwrite($output,"\n");
299 fwrite($output, "hash3:$PlayerC:$EmailC:::" );
301 fwrite($output,"$randomNR[$i];" );
302 fwrite($output,"$randomNR[35]:" ); $i++;
303 fwrite($output,"\n");
305 fwrite($output, "hash4:$PlayerD:$EmailD:::");
307 fwrite($output,"$randomNR[$i];" );
308 fwrite($output,"$randomNR[47]:" );
309 fwrite($output,"\n");
314 echo "can't open file for writing";
317 /* test if a game is running, else output everything for a new game */
321 <p> no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct! </p>
322 <form action="index.php" method="post">
323 Name: <input name="PlayerA" type="text" size="10" maxlength="20" />
324 Email: <input name="EmailA" type="text" size="10" maxlength="20" /> <br />
326 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
327 Email: <input name="EmailB" type="text" size="10" maxlength="20" /> <br />
329 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
330 Email: <input name="EmailC" type="text" size="10" maxlength="20" /> <br />
332 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
333 Email: <input name="EmailD" type="text" size="10" maxlength="20" /> <br />
335 <input type="submit" value="start game" />
340 { /* load game status */
343 $tmp = explode( ":",$lines[0]);
345 $player[$tmp[0]]["number"] = 0;
346 $player[$tmp[0]]["hash"] = $tmp[0];
347 $player[$tmp[0]]["name"] = $tmp[1];
348 $player[$tmp[0]]["email"] = $tmp[2];
349 $player[$tmp[0]]["option"] = $tmp[3];
350 $player[$tmp[0]]["points"] = $tmp[4];
351 $player[$tmp[0]]["cards"] = $tmp[5];
352 if(ereg("s",$tmp[3])) $game["init"]++;
354 $tmp = explode( ":",$lines[1]);
356 $player[$tmp[0]]["number"] = 1;
357 $player[$tmp[0]]["hash"] = $tmp[0];
358 $player[$tmp[0]]["name"] = $tmp[1];
359 $player[$tmp[0]]["email"] = $tmp[2];
360 $player[$tmp[0]]["option"] = $tmp[3];
361 $player[$tmp[0]]["points"] = $tmp[4];
362 $player[$tmp[0]]["cards"] = $tmp[5];
363 if(ereg("s",$tmp[3])) $game["init"]++;
365 $tmp = explode( ":",$lines[2]);
367 $player[$tmp[0]]["number"] = 2;
368 $player[$tmp[0]]["hash"] = $tmp[0];
369 $player[$tmp[0]]["name"] = $tmp[1];
370 $player[$tmp[0]]["email"] = $tmp[2];
371 $player[$tmp[0]]["option"] = $tmp[3];
372 $player[$tmp[0]]["points"] = $tmp[4];
373 $player[$tmp[0]]["cards"] = $tmp[5];
374 if(ereg("s",$tmp[3])) $game["init"]++;
376 $tmp = explode( ":",$lines[3]);
378 $player[$tmp[0]]["number"] = 3;
379 $player[$tmp[0]]["hash"] = $tmp[0];
380 $player[$tmp[0]]["name"] = $tmp[1];
381 $player[$tmp[0]]["email"] = $tmp[2];
382 $player[$tmp[0]]["option"] = $tmp[3];
383 $player[$tmp[0]]["points"] = $tmp[4];
384 $player[$tmp[0]]["cards"] = $tmp[5];
385 if(ereg("s",$tmp[3])) $game["init"]++;
387 /* save the game history */
388 for($i=4;$i<sizeof($lines);$i++)
390 if(!ereg("^[[:space:]]*$",trim($lines[$i])))
392 $history[] = $lines[$i];
395 if(sizeof($history)== 0)
403 * check if a player wants to accept a game
406 if(isset($_REQUEST["a"]))
410 if( ereg("[is]",$player[$a]["option"]) && $game["init"]<4)
412 echo "just wait for the game to start";
414 else if( !ereg("[is]",$player[$a]["option"]) )
418 <form action="index.php" method="post">
419 Do you want to play a game of DoKo?
420 yes<input type="radio" name="in" value="yes" />
421 no<input type="radio" name="in" value="no" /> <br />
423 Do you want to get an email for every card played or only if it your move?
424 every card<input type="radio" name="update" value="card" />
425 only on my turn<input type="radio" name="update" value="turn" /> <br />
427 echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
429 echo "<input type=\"submit\" value=\"count me in\" />\n";
439 * yes? email him his hand, ask for solo, poverty, email every move or every card?
441 if(isset($_REQUEST["b"]))
445 if( ereg("s",$player[$b]["option"]) && $game["init"]<4)
447 echo "just wait for the game to start";
449 else if(!isset($_REQUEST["in"])|| !isset($_REQUEST["update"]) )
452 echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />";
455 { /* show the hand */
456 if($_REQUEST["in"]=="no")
460 echo "Hello ".$player[$hash[$i]]["name"].",\n";
462 echo "the game has been cancled due to the request of one of the players.\n";
464 $output = fopen("status.txt","w");
468 echo "problem opening file";
472 if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
473 if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
475 $player[$b]["option"].="i";
479 $allcards = $player[$b]["cards"];
480 $mycards = explode(";",$allcards);
483 echo "your cards are <br>";
484 foreach($mycards as $card)
490 <form action="index.php" method="post">
492 do you want to play solo?
493 yes<input type="radio" name="solo" value="yes" />
494 no<input type="radio" name="solo" value="no" /> <br />
496 do you have a wedding?
497 yes<input type="radio" name="wedding" value="yes" />
498 no<input type="radio" name="wedding" value="no" /> <br />
501 yes<input type="radio" name="poverty" value="yes" />
502 no<input type="radio" name="poverty" value="no" /> <br />
505 echo "<input type=\"hidden\" name=\"c\" value=\"$b\" />\n";
506 echo "<input type=\"submit\" value=\"count me in\" />\n";
512 if(isset($_REQUEST["c"]))
516 if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) )
519 echo "<a href=\"index.php?b=$c\"> here and fill out the form </a> <br />";
521 else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
523 echo "just wait for the game to start";
525 else if($game["init"]<4)
527 echo "handle krankheit <br />";
529 echo "email this out: you're in. once everyone has filled out the form,";
530 echo "the game will start and you'll get an eamil about it";
532 $player[$c]["option"].="s";
539 if(!isset($_REQUEST["me"]))
540 echo "a game is in progress, but you are not playing";
543 $me = $_REQUEST["me"];
545 echo "game in progress and you are in it<br>";
546 foreach($history as $play)
550 $trick = explode(":",$play);
553 /* found old trick, display it */
554 for($i=0;$i<sizeof($trick)-1;$i++)
559 $tmp = explode("->",$card);
560 echo $player[$hash[$tmp[0]]]["name"]." played ";
561 display_card($tmp[1]);
572 $next=$history[sizeof($history)-1][0];
576 if(isset($_REQUEST["card"]))
578 if($hash[$next]==$me)
580 $card=$_REQUEST["card"];
581 $mycards = explode(";",$player[$me]["cards"]);
582 if(in_array($card,$mycards))
585 foreach($mycards as $m)
589 for($i=0;$i<sizeof($tmp)-1;$i++)
594 $player[$me]["cards"]=$tmp2;
598 $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n";
602 $tmp = explode(":",$history[sizeof($history)-1]);
603 $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
604 $history[sizeof($history)-1]=join(":",$tmp);
610 /* send out email to players who want/need to get informed */
613 $mynext=$next+1; if($mynext>3)$mynext-=4;
614 if((ereg("c",$player[$hash[$i]]["option"]) || $i==$mynext) && $hash[$i]!=$me)
616 echo " <br> ** $next** \n Hello ".$player[$hash[$i]]["name"].",\n";
619 echo "it's your turn now.\n";
620 echo $player[$me]["name"]. "has played the following card ".card_to_name($card)."\n";
622 echo "<a href=\"index.php?me=hash1\"> player 1</a> <br />";
623 echo "<a href=\"index.php?me=hash2\"> player 2</a> <br />";
624 echo "<a href=\"index.php?me=hash3\"> player 3</a> <br />";
625 echo "<a href=\"index.php?me=hash4\"> player 4</a> <br />";
631 echo "seems like you don't have that card<br>";
636 else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
638 $win=$_REQUEST["win"];
639 $history[]=$win.":\n";
640 /* count points of the last trick */
642 echo "<br>".$history[sizeof($history)-2]."is the last trick played<br>";
643 $tmp = explode(":",$history[sizeof($history)-2]);
646 $tmp2 = explode("->",$tmp[$i]);
648 $points += card_value($c);
649 echo "adding card value ".card_value($c)."<br>";
651 $player[$hash[$win]]["points"]+=$points;
652 echo "<br> ".$player[$hash[$win]]["name"]." won: $points Points <br>";
658 $tmp = explode(":",$history[sizeof($history)-1]);
663 <form action="index.php" method="post">
667 echo $player[$hash[$i]]["name"]." <input type=\"radio\" name=\"win\" value=\"$i\" />";
668 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />";
670 <input type="submit" value="who will win?" />
675 else if(sizeof($tmp)<5 && 1<sizeof($tmp) && !isset($_REQUEST["card"]))
677 if(sizeof($tmp)==2 && strlen($tmp[0])==1)
680 echo "found the start of a new trick at $next<br>";
681 if(strlen(trim($player[$me]["cards"]))==0)
683 echo "<br> game over, count points <br>";
686 echo $player[$hash[$i]]["name"]." got ".$player[$hash[$i]]["points"]."<br>";
690 if($hash[$next]==$me && strlen(trim($player[$me]["cards"]))>0 )
693 echo "ITS YOUR TURN<br>";
694 $allcards = trim($player[$me]["cards"]);
695 $mycards = explode(";",$allcards);
698 echo "your cards are <br>";
699 foreach($mycards as $card)
701 display_link_card($card,$me);