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.";
73 /* check for status file and read it, if possible */
75 if(file_exists("status.txt"))
76 $lines = file("status.txt");
80 /* check if we want to start a new game */
81 if( isset($_REQUEST["PlayerA"]) &&
82 isset($_REQUEST["PlayerB"]) &&
83 isset($_REQUEST["PlayerC"]) &&
84 isset($_REQUEST["PlayerD"]) &&
85 isset($_REQUEST["EmailA"]) &&
86 isset($_REQUEST["EmailB"]) &&
87 isset($_REQUEST["EmailC"]) &&
88 isset($_REQUEST["EmailD"]) )
90 $PlayerA = $_REQUEST["PlayerA"];
91 $PlayerB = $_REQUEST["PlayerB"];
92 $PlayerC = $_REQUEST["PlayerC"];
93 $PlayerD = $_REQUEST["PlayerD"];
94 $EmailA = $_REQUEST["EmailA"] ;
95 $EmailB = $_REQUEST["EmailB"] ;
96 $EmailC = $_REQUEST["EmailC"] ;
97 $EmailD = $_REQUEST["EmailD"] ;
99 /* send out email, check for error with email */
100 echo "send out emails to everyone, asking if they want to join";
101 echo "use link <br>";
102 echo "<a href=\"index.php?a=hash1\"> player 1</a> <br />";
103 echo "<a href=\"index.php?a=hash2\"> player 2</a> <br />";
104 echo "<a href=\"index.php?a=hash3\"> player 3</a> <br />";
105 echo "<a href=\"index.php?a=hash4\"> player 4</a> <br />";
107 /* read in random.txt */
108 if(file_exists("random.txt"))
109 $random = file("random.txt");
111 die("no random file");
113 $randomNR = explode( ":", $random[1] );
115 /* write initial status into file */
116 $output = fopen("status.txt","w");
119 fwrite($output, "hash1:".$PlayerA.":".$EmailA."::" );
121 fwrite($output,"$randomNR[$i];" );
122 fwrite($output,"$randomNR[11]:" ); $i++;
123 fwrite($output,"\n");
125 fwrite($output, "hash2:$PlayerB:$EmailB::" );
127 fwrite($output,"$randomNR[$i];" );
128 fwrite($output,"$randomNR[23]:" ); $i++;
129 fwrite($output,"\n");
131 fwrite($output, "hash3:$PlayerC:$EmailC::" );
133 fwrite($output,"$randomNR[$i];" );
134 fwrite($output,"$randomNR[35]:" ); $i++;
135 fwrite($output,"\n");
137 fwrite($output, "hash4:$PlayerD:$EmailD::");
139 fwrite($output,"$randomNR[$i];" );
140 fwrite($output,"$randomNR[47]:" );
141 fwrite($output,"\n");
146 echo "can't open file for writing";
149 /* test if a game is running, else output everything for a new game */
153 <p> no game in progress, please input 4 names and email addresses </p>
154 <form action="index.php" method="post">
155 Name: <input name="PlayerA" type="text" size="10" maxlength="20" />
156 Email: <input name="EmailA" type="text" size="10" maxlength="20" /> <br />
158 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
159 Email: <input name="EmailB" type="text" size="10" maxlength="20" /> <br />
161 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
162 Email: <input name="EmailC" type="text" size="10" maxlength="20" /> <br />
164 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
165 Email: <input name="EmailD" type="text" size="10" maxlength="20" /> <br />
167 <input type="submit" value="start game" />
172 { /* load game status */
175 $tmp = explode( ":",$lines[0]);
177 $player[$tmp[0]]["number"] = 0;
178 $player[$tmp[0]]["hash"] = $tmp[0];
179 $player[$tmp[0]]["name"] = $tmp[1];
180 $player[$tmp[0]]["email"] = $tmp[2];
181 $player[$tmp[0]]["option"] = $tmp[3];
182 $player[$tmp[0]]["cards"] = $tmp[4];
183 if(ereg("s",$tmp[3])) $game["init"]++;
185 $tmp = explode( ":",$lines[1]);
187 $player[$tmp[0]]["number"] = 1;
188 $player[$tmp[0]]["hash"] = $tmp[0];
189 $player[$tmp[0]]["name"] = $tmp[1];
190 $player[$tmp[0]]["email"] = $tmp[2];
191 $player[$tmp[0]]["option"] = $tmp[3];
192 $player[$tmp[0]]["cards"] = $tmp[4];
193 if(ereg("s",$tmp[3])) $game["init"]++;
195 $tmp = explode( ":",$lines[2]);
197 $player[$tmp[0]]["number"] = 2;
198 $player[$tmp[0]]["hash"] = $tmp[0];
199 $player[$tmp[0]]["name"] = $tmp[1];
200 $player[$tmp[0]]["email"] = $tmp[2];
201 $player[$tmp[0]]["option"] = $tmp[3];
202 $player[$tmp[0]]["cards"] = $tmp[4];
203 if(ereg("s",$tmp[3])) $game["init"]++;
205 $tmp = explode( ":",$lines[3]);
207 $player[$tmp[0]]["number"] = 3;
208 $player[$tmp[0]]["hash"] = $tmp[0];
209 $player[$tmp[0]]["name"] = $tmp[1];
210 $player[$tmp[0]]["email"] = $tmp[2];
211 $player[$tmp[0]]["option"] = $tmp[3];
212 $player[$tmp[0]]["cards"] = $tmp[4];
213 if(ereg("s",$tmp[3])) $game["init"]++;
215 /* save the game history */
216 for($i=4;$i<sizeof($lines);$i++)
219 $history[]=$lines[$i];
227 * check if a player wants to accept a game
230 if(isset($_REQUEST["a"]))
234 if( ereg("[is]",$player[$a]["option"]) && $game["init"]<4)
236 echo "just wait for the game to start";
242 <form action="index.php" method="post">
243 Do you want to play a game of DoKo?
244 yes<input type="radio" name="in" value="yes" />
245 no<input type="radio" name="in" value="no" /> <br />
247 Do you want to get an email for every card played or only if it your move?
248 every card<input type="radio" name="update" value="card" />
249 only on my turn<input type="radio" name="update" value="turn" /> <br />
251 echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
253 echo "<input type=\"submit\" value=\"count me in\" />\n";
263 * yes? email him his hand, ask for solo, poverty, email every move or every card?
265 if(isset($_REQUEST["b"]))
269 if( ereg("[is]",$player[$b]["option"]) && $game["init"]<4)
271 echo "just wait for the game to start";
273 else if(!isset($_REQUEST["in"])|| !isset($_REQUEST["update"]) )
276 echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />";
279 { /* show the hand */
280 if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
281 if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
283 $player[$b]["option"].="i";
287 $allcards = $player[$b]["cards"];
288 $mycards = explode(";",$allcards);
291 echo "your cards are <br>";
292 foreach($mycards as $card)
298 <form action="index.php" method="post">
300 do you want to play solo?
301 yes<input type="radio" name="solo" value="yes" />
302 no<input type="radio" name="solo" value="no" /> <br />
304 do you have a wedding?
305 yes<input type="radio" name="wedding" value="yes" />
306 no<input type="radio" name="wedding" value="no" /> <br />
309 yes<input type="radio" name="poverty" value="yes" />
310 no<input type="radio" name="poverty" value="no" /> <br />
313 echo "<input type=\"hidden\" name=\"c\" value=\"$b\" />\n";
314 echo "<input type=\"submit\" value=\"count me in\" />\n";
319 if(isset($_REQUEST["c"]))
323 if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) )
326 echo "<a href=\"index.php?b=$c\"> here and fill out the form </a> <br />";
328 else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
330 echo "just wait for the game to start";
332 else if($game["init"]<4)
334 echo "handle krankheit <br />";
336 echo "email this out: you're in. once everyone has filled out the form,";
337 echo "the game will start and you'll get an eamil about it";
339 $player[$c]["option"].="s";
346 if(!isset($_REQUEST["me"]))
347 echo "a game is in progress, but you are not playing";
350 $me = $_REQUEST["me"];
351 if(isset($_REQUEST["card"]))
353 $card=$_REQUEST["card"];
354 echo "EMAIL: you played $card <br>";
355 echo "check,if card correct remove card from deck <br>";
358 $tmp = explode(":",$history[sizeof($history)-1]);
359 $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
360 $history[sizeof($history)-1]=join(":",$tmp);
364 echo "game in progress and you are in it<br>";
365 foreach($history as $play)
367 $trick = explode(":",$play);
370 /* found old trick, display it */
371 for($i=0;$i<sizeof($trick)-1;$i++)
374 $tmp = explode("->",$card);
375 echo $player[$hash[$tmp[0]]]["name"]." played ";
376 display_card($tmp[1]);
386 switch(sizeof($trick))
389 echo "new trick , next player ".$trick[0]." <br>";
392 echo "figure out who will win<br>";
395 echo "some played $next";
396 if($hash[$next]==$me)
399 echo "ITS YOUR TURN<br>";
400 $allcards = $player[$me]["cards"];
401 $mycards = explode(";",$allcards);
404 echo "your cards are <br>";
405 foreach($mycards as $card)
407 display_link_card($card,$me);
420 } /* is this the last player that needs to accept? */
421 /* yes, figure out who starts, send out email to first player */
422 /* no, email the rest to cancel game */
424 /* player wants to make a move? */
425 /* check if it is this players turn it is (if it's the players turn, convert cards into links) */
426 /* if it is the last card played*/
427 /* add checkbox for who one the trick */
428 /* email next player */
429 /* last card played? */
430 /* count score for each player */