7 $host = "http://doko.nubati.net/database/index.php";
8 $wiki = "http://wiki.nubati.net/index.php?title=EmailDoko";
19 function mymail($To,$Subject,$message)
25 $message = str_replace("\n","<br />",$message);
26 echo "<br />To: $To<br />Subject: $Subject <br />$message<br />\n";
29 mail($To,$Subject,$message);
33 function is_trump($c) { return (($c<27) ? 1:0);}
34 function is_club($c) { return (in_array($c,array('27','28','29','30','31','32','33','34')));}
35 function is_spade($c) { return (in_array($c,array('35','36','37','38','39','40','41','42')));}
36 function is_heart($c) { return (in_array($c,array('43','44','45','46','47','48')));}
38 function compare_cards($a,$b)
40 /* if a is higher than b return 1, else 0, a being the card first played */
42 /* first map all cards to the odd number */
43 if( $a/2 - (int)($a/2) != 0.5)
45 if( $b/2 - (int)($b/2) != 0.5)
48 if(is_trump($a) && $a<=$b)
50 else if(is_trump($a) && $a>$b)
53 { /*$a is not a trump */
59 if( is_club($a) && is_club($b))
65 if( is_spade($a) && is_spade($b))
71 if( is_heart($a) && is_heart($b))
82 function get_winner($p)
84 /* get all 4 cards played in a trick */
90 /* find out who won */
91 if( compare_cards($c1,$c2) && compare_cards($c1,$c3) && compare_cards($c1,$c4) )
93 if( compare_cards($c2,$c3) && compare_cards($c2,$c4) )
95 if( compare_cards($c3,$c4) )
100 function count_nines($cards)
104 foreach($cards as $c)
106 if($c == "25" || $c == "26") $nines++;
107 else if($c == "33" || $c == "34") $nines++;
108 else if($c == "41" || $c == "42") $nines++;
109 else if($c == "47" || $c == "48") $nines++;
115 function check_wedding($cards)
118 if( in_array("3",$cards) && in_array("2",$cards) )
124 function count_trump($cards)
128 /* count each trump */
129 foreach($cards as $c)
134 if( in_array("19",$cards))
136 if( in_array("20",$cards) )
138 /* add one, in case the player has both foxes (schweinchen) */
139 if( in_array("19",$cards) && in_array("20",$cards) )
145 function card_to_name($card)
151 return "ten of hearts";
154 return "queen of clubs";
157 return "queen of spades";
160 return "queen of hearts";
163 return "queen of diamonds";
166 return "jack of clubs";
169 return "jack of spades";
172 return "jack of hearts";
175 return "jack of diamonds";
178 return "ace of diamonds";
181 return "ten of diamonds";
184 return "king of diamonds";
187 return "nine of diamonds";;
190 return "ace of clubs";
193 return "ten of clubs";
196 return "king of clubs";
199 return "nine of clubs";
202 return "ace of spades";
205 return "ten of spades";
208 return "king of spades";
211 return "nine of spades";
214 return "ace of hearts";
217 return "king of hearts";
220 return "nine of hearts";
222 return "something went wrong, please contact the admin. Error: code1.";
226 function card_value($card)
239 case 9: /* diamonds */
242 case 11: /* clubes */
244 case 13: /* spades */
246 case 15: /* hearts */
248 case 17: /* diamonds */
251 case 19: /* diamonds */
255 case 35: /* spades */
257 case 43: /* hearts */
260 case 21: /* diamonds */
264 case 37: /* spades */
267 case 23: /* diamonds */
271 case 39: /* spades */
273 case 45: /* hearts */
276 case 25: /* diamonds */
280 case 41: /* spades */
282 case 47: /* hearts */
286 echo "something went wrong, please contact the admin. ErrorCode: 2<br>";
291 function display_card($card)
293 /* cards are only availabl for the odd values, e.g. 1.png, 3.png, ...
294 * convert even cards to the matching odd value */
296 if( $card/2 - (int)($card/2) == 0.5)
297 echo "<img src=\"cards/".$card.".png\" alt=\"".card_to_name($card)."\" />\n";
299 echo "<img src=\"cards/".($card-1).".png\" alt=\"".card_to_name($card-1)."\" />\n";
304 function display_link_card($card)
306 if( $card/2 - (int)($card/2) == 0.5)
307 echo "<input type=\"radio\" name=\"card\" value=\"".$card."\" /><img src=\"cards/".$card.".png\" alt=\"\" />\n";
309 echo "<input type=\"radio\" name=\"card\" value=\"".$card."\" /><img src=\"cards/".($card-1).".png\" alt=\"\" />\n";
313 function create_array_of_random_numbers()
321 $r = array_rand($a,48);
326 function check_want_to_play($me)
329 <form action="index.php" method="post">
330 Do you want to play a game of DoKo?
331 yes<input type="radio" name="in" value="yes" />
332 no<input type="radio" name="in" value="no" /> <br />
334 Do you want to get an email for every card played or only if it your move?
335 every card<input type="radio" name="update" value="card" />
336 only on my turn<input type="radio" name="update" value="turn" /> <br />
338 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
340 echo "<input type=\"submit\" value=\"count me in\" />\n";
346 function check_for_sickness($me,$mycards)
349 <p> nothing implemented so far, but give it a try anyway ;) </p>
351 <form action="index.php" method="post">
353 do you want to play solo?
354 <select name="solo" size="1">
356 <option>trumpless</option>
357 <option>trump</option>
358 <option>queen</option>
359 <option>jack</option>
360 <option>club</option>
361 <option>spade</option>
362 <option>heart</option>
369 if(check_wedding($mycards))
371 echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" />";
372 echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
376 echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
379 echo "do you have poverty?";
380 if(count_trump($mycards)<4)
382 echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" />";
383 echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
387 echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
390 echo "do you have too many nines?";
391 if(count_nines($mycards)>4)
393 echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" />";
394 echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
398 echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
401 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
402 echo "<input type=\"submit\" value=\"count me in\" />\n";
409 function display_status()
411 echo "<div class=\"info\">";
412 echo " is someone playing solo, etc?";
418 function display_news()
421 echo "<div class=\"bug\"> ".
422 "Please hit shift+reload.<br /><hr />".
423 "New Database backend, lost a few features on the way.<br /><hr />".
424 "If you find more bugs, please list them in the <a href=\"".$wiki.
425 "\">wiki</a>.</div>\n";
429 function display_cards($me,$myturn)