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 */
259 echo "send out emails to everyone, asking if they want to join";
260 echo "use link <br>";
261 echo "<a href=\"index.php?a=hash1\"> player 1</a> <br />";
262 echo "<a href=\"index.php?a=hash2\"> player 2</a> <br />";
263 echo "<a href=\"index.php?a=hash3\"> player 3</a> <br />";
264 echo "<a href=\"index.php?a=hash4\"> player 4</a> <br />";
266 /* read in random.txt */
267 if(file_exists("random.txt"))
268 $random = file("random.txt");
270 die("no random file");
272 $randomNR = explode( ":", $random[1] );
274 /* write initial status into file */
275 $output = fopen("status.txt","w");
278 fwrite($output, "hash1:$PlayerA:$EmailA:::" );
280 fwrite($output,"$randomNR[$i];" );
281 fwrite($output,"$randomNR[11]:" ); $i++;
282 fwrite($output,"\n");
284 fwrite($output, "hash2:$PlayerB:$EmailB:::" );
286 fwrite($output,"$randomNR[$i];" );
287 fwrite($output,"$randomNR[23]:" ); $i++;
288 fwrite($output,"\n");
290 fwrite($output, "hash3:$PlayerC:$EmailC:::" );
292 fwrite($output,"$randomNR[$i];" );
293 fwrite($output,"$randomNR[35]:" ); $i++;
294 fwrite($output,"\n");
296 fwrite($output, "hash4:$PlayerD:$EmailD:::");
298 fwrite($output,"$randomNR[$i];" );
299 fwrite($output,"$randomNR[47]:" );
300 fwrite($output,"\n");
305 echo "can't open file for writing";
308 /* test if a game is running, else output everything for a new game */
312 <p> no game in progress, please input 4 names and email addresses </p>
313 <form action="index.php" method="post">
314 Name: <input name="PlayerA" type="text" size="10" maxlength="20" />
315 Email: <input name="EmailA" type="text" size="10" maxlength="20" /> <br />
317 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
318 Email: <input name="EmailB" type="text" size="10" maxlength="20" /> <br />
320 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
321 Email: <input name="EmailC" type="text" size="10" maxlength="20" /> <br />
323 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
324 Email: <input name="EmailD" type="text" size="10" maxlength="20" /> <br />
326 <input type="submit" value="start game" />
331 { /* load game status */
334 $tmp = explode( ":",$lines[0]);
336 $player[$tmp[0]]["number"] = 0;
337 $player[$tmp[0]]["hash"] = $tmp[0];
338 $player[$tmp[0]]["name"] = $tmp[1];
339 $player[$tmp[0]]["email"] = $tmp[2];
340 $player[$tmp[0]]["option"] = $tmp[3];
341 $player[$tmp[0]]["points"] = $tmp[4];
342 $player[$tmp[0]]["cards"] = $tmp[5];
343 if(ereg("s",$tmp[3])) $game["init"]++;
345 $tmp = explode( ":",$lines[1]);
347 $player[$tmp[0]]["number"] = 1;
348 $player[$tmp[0]]["hash"] = $tmp[0];
349 $player[$tmp[0]]["name"] = $tmp[1];
350 $player[$tmp[0]]["email"] = $tmp[2];
351 $player[$tmp[0]]["option"] = $tmp[3];
352 $player[$tmp[0]]["points"] = $tmp[4];
353 $player[$tmp[0]]["cards"] = $tmp[5];
354 if(ereg("s",$tmp[3])) $game["init"]++;
356 $tmp = explode( ":",$lines[2]);
358 $player[$tmp[0]]["number"] = 2;
359 $player[$tmp[0]]["hash"] = $tmp[0];
360 $player[$tmp[0]]["name"] = $tmp[1];
361 $player[$tmp[0]]["email"] = $tmp[2];
362 $player[$tmp[0]]["option"] = $tmp[3];
363 $player[$tmp[0]]["points"] = $tmp[4];
364 $player[$tmp[0]]["cards"] = $tmp[5];
365 if(ereg("s",$tmp[3])) $game["init"]++;
367 $tmp = explode( ":",$lines[3]);
369 $player[$tmp[0]]["number"] = 3;
370 $player[$tmp[0]]["hash"] = $tmp[0];
371 $player[$tmp[0]]["name"] = $tmp[1];
372 $player[$tmp[0]]["email"] = $tmp[2];
373 $player[$tmp[0]]["option"] = $tmp[3];
374 $player[$tmp[0]]["points"] = $tmp[4];
375 $player[$tmp[0]]["cards"] = $tmp[5];
376 if(ereg("s",$tmp[3])) $game["init"]++;
378 /* save the game history */
379 for($i=4;$i<sizeof($lines);$i++)
381 if(!ereg("^[[:space:]]*$",trim($lines[$i])))
383 $history[] = $lines[$i];
386 if(sizeof($history)== 0)
394 * check if a player wants to accept a game
397 if(isset($_REQUEST["a"]))
401 if( ereg("[is]",$player[$a]["option"]) && $game["init"]<4)
403 echo "just wait for the game to start";
405 else if( !ereg("[is]",$player[$a]["option"]) )
409 <form action="index.php" method="post">
410 Do you want to play a game of DoKo?
411 yes<input type="radio" name="in" value="yes" />
412 no<input type="radio" name="in" value="no" /> <br />
414 Do you want to get an email for every card played or only if it your move?
415 every card<input type="radio" name="update" value="card" />
416 only on my turn<input type="radio" name="update" value="turn" /> <br />
418 echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
420 echo "<input type=\"submit\" value=\"count me in\" />\n";
430 * yes? email him his hand, ask for solo, poverty, email every move or every card?
432 if(isset($_REQUEST["b"]))
436 if( ereg("s",$player[$b]["option"]) && $game["init"]<4)
438 echo "just wait for the game to start";
440 else if(!isset($_REQUEST["in"])|| !isset($_REQUEST["update"]) )
443 echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />";
446 { /* show the hand */
447 if($_REQUEST["in"]=="no")
451 echo "Hello ".$player[$hash[$i]]["name"].",\n";
453 echo "the game has been cancled due to the request of one of the players.\n";
455 $output = fopen("status.txt","w");
459 echo "problem opening file";
463 if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
464 if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
466 $player[$b]["option"].="i";
470 $allcards = $player[$b]["cards"];
471 $mycards = explode(";",$allcards);
474 echo "your cards are <br>";
475 foreach($mycards as $card)
481 <form action="index.php" method="post">
483 do you want to play solo?
484 yes<input type="radio" name="solo" value="yes" />
485 no<input type="radio" name="solo" value="no" /> <br />
487 do you have a wedding?
488 yes<input type="radio" name="wedding" value="yes" />
489 no<input type="radio" name="wedding" value="no" /> <br />
492 yes<input type="radio" name="poverty" value="yes" />
493 no<input type="radio" name="poverty" value="no" /> <br />
496 echo "<input type=\"hidden\" name=\"c\" value=\"$b\" />\n";
497 echo "<input type=\"submit\" value=\"count me in\" />\n";
503 if(isset($_REQUEST["c"]))
507 if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) )
510 echo "<a href=\"index.php?b=$c\"> here and fill out the form </a> <br />";
512 else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
514 echo "just wait for the game to start";
516 else if($game["init"]<4)
518 echo "handle krankheit <br />";
520 echo "email this out: you're in. once everyone has filled out the form,";
521 echo "the game will start and you'll get an eamil about it";
523 $player[$c]["option"].="s";
530 if(!isset($_REQUEST["me"]))
531 echo "a game is in progress, but you are not playing";
534 $me = $_REQUEST["me"];
536 echo "game in progress and you are in it<br>";
537 foreach($history as $play)
541 $trick = explode(":",$play);
544 /* found old trick, display it */
545 for($i=0;$i<sizeof($trick)-1;$i++)
550 $tmp = explode("->",$card);
551 echo $player[$hash[$tmp[0]]]["name"]." played ";
552 display_card($tmp[1]);
563 $next=$history[sizeof($history)-1][0];
567 if(isset($_REQUEST["card"]))
569 if($hash[$next]==$me)
571 $card=$_REQUEST["card"];
572 $mycards = explode(";",$player[$me]["cards"]);
573 if(in_array($card,$mycards))
576 foreach($mycards as $m)
580 for($i=0;$i<sizeof($tmp)-1;$i++)
585 $player[$me]["cards"]=$tmp2;
589 $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n";
593 $tmp = explode(":",$history[sizeof($history)-1]);
594 $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
595 $history[sizeof($history)-1]=join(":",$tmp);
601 /* send out email to players who want/need to get informed */
604 $mynext=$next+1; if($mynext>3)$mynext-=4;
605 if((ereg("c",$player[$hash[$i]]["option"]) || $i==$mynext) && $hash[$i]!=$me)
607 echo " <br> ** $next** \n Hello ".$player[$hash[$i]]["name"].",\n";
610 echo "it's your turn now.\n";
611 echo $player[$me]["name"]. "has played the following card ".card_to_name($card)."\n";
613 echo "<a href=\"index.php?me=hash1\"> player 1</a> <br />";
614 echo "<a href=\"index.php?me=hash2\"> player 2</a> <br />";
615 echo "<a href=\"index.php?me=hash3\"> player 3</a> <br />";
616 echo "<a href=\"index.php?me=hash4\"> player 4</a> <br />";
622 echo "seems like you don't have that card<br>";
627 else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
629 $win=$_REQUEST["win"];
630 $history[]=$win.":\n";
631 /* count points of the last trick */
633 echo "<br>".$history[sizeof($history)-2]."is the last trick played<br>";
634 $tmp = explode(":",$history[sizeof($history)-2]);
637 $tmp2 = explode("->",$tmp[$i]);
639 $points += card_value($c);
640 echo "adding card value ".card_value($c)."<br>";
642 $player[$hash[$win]]["points"]+=$points;
643 echo "<br> ".$player[$hash[$win]]["name"]." won: $points Points <br>";
649 $tmp = explode(":",$history[sizeof($history)-1]);
654 <form action="index.php" method="post">
658 echo $player[$hash[$i]]["name"]." <input type=\"radio\" name=\"win\" value=\"$i\" />";
659 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />";
661 <input type="submit" value="who will win?" />
666 else if(sizeof($tmp)<5 && 1<sizeof($tmp) && !isset($_REQUEST["card"]))
668 if(sizeof($tmp)==2 && strlen($tmp[0])==1)
671 echo "found the start of a new trick at $next<br>";
672 if(strlen(trim($player[$me]["cards"]))==0)
674 echo "<br> game over, count points <br>";
677 echo $player[$hash[$i]]["name"]." got ".$player[$hash[$i]]["points"]."<br>";
681 if($hash[$next]==$me && strlen(trim($player[$me]["cards"]))>0 )
684 echo "ITS YOUR TURN<br>";
685 $allcards = trim($player[$me]["cards"]);
686 $mycards = explode(";",$allcards);
689 echo "your cards are <br>";
690 foreach($mycards as $card)
692 display_link_card($card,$me);