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 display_card($card)
17 if( $card/2 - (int)($card/2) == 0.5)
18 echo "<img src=\"cards/".$card.".png\" height=\"100\">";
20 echo "<img src=\"cards/".($card-1).".png\" height=\"100\">";
23 function display_link_card($card,$me)
25 if( $card/2 - (int)($card/2) == 0.5)
26 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".$card.".png\" height=\"100\"></a>";
28 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".($card-1).".png\" height=\"100\"></a>";
32 function save_status()
34 global $player,$game,$hash,$history;
36 $output = fopen("status.txt","w");
39 foreach($hash as $key)
42 if( ereg("i",$player[$key]["option"]) )
44 if( ereg("s",$player[$key]["option"]) )
46 if( ereg("t",$player[$key]["option"]) )
48 if( ereg("c",$player[$key]["option"]) )
50 $player[$key]["option"]=$tmp;
52 fwrite($output,"".$player[$key]["hash"].":" );
53 fwrite($output,"".$player[$key]["name"].":" );
54 fwrite($output,"".$player[$key]["email"].":" );
55 fwrite($output,"".$player[$key]["option"].":" );
56 fwrite($output,"".$player[$key]["cards"] .":");
60 foreach($history as $line)
61 fwrite($output,$line);
67 echo "can't open file for writing, please inform the admin.";
74 /* check for status file and read it, if possible */
76 if(file_exists("status.txt"))
77 $lines = file("status.txt");
81 /* check if we want to start a new game */
82 if( isset($_REQUEST["PlayerA"]) &&
83 isset($_REQUEST["PlayerB"]) &&
84 isset($_REQUEST["PlayerC"]) &&
85 isset($_REQUEST["PlayerD"]) &&
86 isset($_REQUEST["EmailA"]) &&
87 isset($_REQUEST["EmailB"]) &&
88 isset($_REQUEST["EmailC"]) &&
89 isset($_REQUEST["EmailD"]) )
91 $PlayerA = $_REQUEST["PlayerA"];
92 $PlayerB = $_REQUEST["PlayerB"];
93 $PlayerC = $_REQUEST["PlayerC"];
94 $PlayerD = $_REQUEST["PlayerD"];
95 $EmailA = $_REQUEST["EmailA"] ;
96 $EmailB = $_REQUEST["EmailB"] ;
97 $EmailC = $_REQUEST["EmailC"] ;
98 $EmailD = $_REQUEST["EmailD"] ;
100 /* send out email, check for error with email */
101 echo "send out emails to everyone, asking if they want to join";
102 echo "use link <br>";
103 echo "<a href=\"index.php?a=hash1\"> player 1</a> <br />";
104 echo "<a href=\"index.php?a=hash2\"> player 2</a> <br />";
105 echo "<a href=\"index.php?a=hash3\"> player 3</a> <br />";
106 echo "<a href=\"index.php?a=hash4\"> player 4</a> <br />";
108 /* read in random.txt */
109 if(file_exists("random.txt"))
110 $random = file("random.txt");
112 die("no random file");
114 $randomNR = explode( ":", $random[1] );
116 /* write initial status into file */
117 $output = fopen("status.txt","w");
120 fwrite($output, "hash1:".$PlayerA.":".$EmailA."::" );
122 fwrite($output,"$randomNR[$i];" );
123 fwrite($output,"$randomNR[11]:" ); $i++;
124 fwrite($output,"\n");
126 fwrite($output, "hash2:$PlayerB:$EmailB::" );
128 fwrite($output,"$randomNR[$i];" );
129 fwrite($output,"$randomNR[23]:" ); $i++;
130 fwrite($output,"\n");
132 fwrite($output, "hash3:$PlayerC:$EmailC::" );
134 fwrite($output,"$randomNR[$i];" );
135 fwrite($output,"$randomNR[35]:" ); $i++;
136 fwrite($output,"\n");
138 fwrite($output, "hash4:$PlayerD:$EmailD::");
140 fwrite($output,"$randomNR[$i];" );
141 fwrite($output,"$randomNR[47]:" );
142 fwrite($output,"\n");
147 echo "can't open file for writing";
150 /* test if a game is running, else output everything for a new game */
154 <p> no game in progress, please input 4 names and email addresses </p>
155 <form action="index.php" method="post">
156 Name: <input name="PlayerA" type="text" size="10" maxlength="20" />
157 Email: <input name="EmailA" type="text" size="10" maxlength="20" /> <br />
159 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
160 Email: <input name="EmailB" type="text" size="10" maxlength="20" /> <br />
162 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
163 Email: <input name="EmailC" type="text" size="10" maxlength="20" /> <br />
165 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
166 Email: <input name="EmailD" type="text" size="10" maxlength="20" /> <br />
168 <input type="submit" value="start game" />
173 { /* load game status */
176 $tmp = explode( ":",$lines[0]);
178 $player[$tmp[0]]["number"] = 0;
179 $player[$tmp[0]]["hash"] = $tmp[0];
180 $player[$tmp[0]]["name"] = $tmp[1];
181 $player[$tmp[0]]["email"] = $tmp[2];
182 $player[$tmp[0]]["option"] = $tmp[3];
183 $player[$tmp[0]]["cards"] = $tmp[4];
184 if(ereg("s",$tmp[3])) $game["init"]++;
186 $tmp = explode( ":",$lines[1]);
188 $player[$tmp[0]]["number"] = 1;
189 $player[$tmp[0]]["hash"] = $tmp[0];
190 $player[$tmp[0]]["name"] = $tmp[1];
191 $player[$tmp[0]]["email"] = $tmp[2];
192 $player[$tmp[0]]["option"] = $tmp[3];
193 $player[$tmp[0]]["cards"] = $tmp[4];
194 if(ereg("s",$tmp[3])) $game["init"]++;
196 $tmp = explode( ":",$lines[2]);
198 $player[$tmp[0]]["number"] = 2;
199 $player[$tmp[0]]["hash"] = $tmp[0];
200 $player[$tmp[0]]["name"] = $tmp[1];
201 $player[$tmp[0]]["email"] = $tmp[2];
202 $player[$tmp[0]]["option"] = $tmp[3];
203 $player[$tmp[0]]["cards"] = $tmp[4];
204 if(ereg("s",$tmp[3])) $game["init"]++;
206 $tmp = explode( ":",$lines[3]);
208 $player[$tmp[0]]["number"] = 3;
209 $player[$tmp[0]]["hash"] = $tmp[0];
210 $player[$tmp[0]]["name"] = $tmp[1];
211 $player[$tmp[0]]["email"] = $tmp[2];
212 $player[$tmp[0]]["option"] = $tmp[3];
213 $player[$tmp[0]]["cards"] = $tmp[4];
214 if(ereg("s",$tmp[3])) $game["init"]++;
216 /* save the game history */
217 for($i=4;$i<sizeof($lines);$i++)
219 if(!ereg("^[[:space:]]*$",trim($lines[$i])))
221 $history[] = $lines[$i];
224 if(sizeof($history)== 0)
232 * check if a player wants to accept a game
235 if(isset($_REQUEST["a"]))
239 if( ereg("[is]",$player[$a]["option"]) && $game["init"]<4)
241 echo "just wait for the game to start";
243 else if( !ereg("[is]",$player[$a]["option"]) )
247 <form action="index.php" method="post">
248 Do you want to play a game of DoKo?
249 yes<input type="radio" name="in" value="yes" />
250 no<input type="radio" name="in" value="no" /> <br />
252 Do you want to get an email for every card played or only if it your move?
253 every card<input type="radio" name="update" value="card" />
254 only on my turn<input type="radio" name="update" value="turn" /> <br />
256 echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
258 echo "<input type=\"submit\" value=\"count me in\" />\n";
268 * yes? email him his hand, ask for solo, poverty, email every move or every card?
270 if(isset($_REQUEST["b"]))
274 if( ereg("s",$player[$b]["option"]) && $game["init"]<4)
276 echo "just wait for the game to start";
278 else if(!isset($_REQUEST["in"])|| !isset($_REQUEST["update"]) )
281 echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />";
284 { /* show the hand */
285 if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
286 if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
288 $player[$b]["option"].="i";
292 $allcards = $player[$b]["cards"];
293 $mycards = explode(";",$allcards);
296 echo "your cards are <br>";
297 foreach($mycards as $card)
303 <form action="index.php" method="post">
305 do you want to play solo?
306 yes<input type="radio" name="solo" value="yes" />
307 no<input type="radio" name="solo" value="no" /> <br />
309 do you have a wedding?
310 yes<input type="radio" name="wedding" value="yes" />
311 no<input type="radio" name="wedding" value="no" /> <br />
314 yes<input type="radio" name="poverty" value="yes" />
315 no<input type="radio" name="poverty" value="no" /> <br />
318 echo "<input type=\"hidden\" name=\"c\" value=\"$b\" />\n";
319 echo "<input type=\"submit\" value=\"count me in\" />\n";
324 if(isset($_REQUEST["c"]))
328 if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) )
331 echo "<a href=\"index.php?b=$c\"> here and fill out the form </a> <br />";
333 else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
335 echo "just wait for the game to start";
337 else if($game["init"]<4)
339 echo "handle krankheit <br />";
341 echo "email this out: you're in. once everyone has filled out the form,";
342 echo "the game will start and you'll get an eamil about it";
344 $player[$c]["option"].="s";
351 if(!isset($_REQUEST["me"]))
352 echo "a game is in progress, but you are not playing";
355 $me = $_REQUEST["me"];
357 echo "game in progress and you are in it<br>";
358 foreach($history as $play)
362 $trick = explode(":",$play);
365 /* found old trick, display it */
366 for($i=0;$i<sizeof($trick)-1;$i++)
371 $tmp = explode("->",$card);
372 echo $player[$hash[$tmp[0]]]["name"]." played ";
373 display_card($tmp[1]);
384 $next=$history[sizeof($history)-1][0];
388 if(isset($_REQUEST["card"]))
390 if($hash[$next]==$me)
392 $card=$_REQUEST["card"];
393 echo "EMAIL: you played $card ";
394 $mycards = explode(";",$player[$me]["cards"]);
395 if(in_array($card,$mycards))
399 foreach($mycards as $m)
404 echo "adding card $m <br>";
408 for($i=0;$i<sizeof($tmp)-1;$i++)
411 echo "adding card $tmp2 at $i <br>";
414 echo "adding card $tmp2 at $i *<br>";
415 $player[$me]["cards"]=$tmp2;
419 $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n";
423 $tmp = explode(":",$history[sizeof($history)-1]);
424 $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
425 $history[sizeof($history)-1]=join(":",$tmp);
432 echo "seems like you don't have that card<br>";
437 else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
439 $win=$_REQUEST["win"];
440 $history[]=$win.":\n";
441 echo "juhu someone won:$win <br>";
447 $tmp = explode(":",$history[sizeof($history)-1]);
449 echo sizeof($tmp)." tmp ;;".strlen($tmp[0])." len tmp0 <br>";
454 <form action="index.php" method="post">
457 player1<input type="radio" name="win" value="0" />
458 player2<input type="radio" name="win" value="1" />
459 player3<input type="radio" name="win" value="2" />
460 player4<input type="radio" name="win" value="3" />
461 <input type="hidden" name="me" value="hash1" />
462 <input type="submit" value="who will win?" />
467 else if(sizeof($tmp)<5 && 1<sizeof($tmp) && !isset($_REQUEST["card"]))
469 if(sizeof($tmp)==2 && strlen($tmp[0])==1)
472 echo "found the start of a new trick at $next<br>";
474 if($hash[$next]==$me)
477 echo "ITS YOUR TURN<br>";
478 $allcards = $player[$me]["cards"];
479 $mycards = explode(";",$allcards);
482 echo "your cards are <br>";
483 foreach($mycards as $card)
485 display_link_card($card,$me);
495 } /* is this the last player that needs to accept? */
496 /* yes, figure out who starts, send out email to first player */
497 /* no, email the rest to cancel game */
499 /* player wants to make a move? */
500 /* check if it is this players turn it is (if it's the players turn, convert cards into links) */
501 /* if it is the last card played*/
502 /* add checkbox for who one the trick */
503 /* email next player */
504 /* last card played? */
505 /* count score for each player */