Quelltext der Datei: http://www.michaelster.ch/lernen/__new__lotto.php

Dateigrösse: 10.51 kb

[Anzeige ohne Zeilennummern]


  1 
  2 <style type="text/css">
  3 article { padding: 5px 0 0 20px; }
  4 h2.head    { letter-spacing:1px; margin:1em 0 1em 0; font-size: 2em; }
  5 .wahr    { letter-spacing:2px; color:green; border:1pt solid green; padding:10pt; margin-top:20pt; font-weight:bold; }
  6 .tab    { float:left; margin-right:140px; margin-bottom:0px; }
  7 .clear    { clear:both; }
  8 table    { color:black; font-size:14px; font-family:verdana,sans-serif; margin-left: -8px; }
  9 td        { width:32px; height:30px; text-align:center; border:1pt solid gray; background:#fff; }
 10 .treffer     { font-weight: bold; color: #000; background: #ff9; }
 11 .tomato         { font-weight: bold; color: tomato; }
 12 .volltreffer { font-weight: bold; }
 13 .tom         { color: #fff; background: tomato; }
 14 .lime         { color: #fff; background: limegreen; }
 15 td.treffer     { background: limegreen !important; }
 16 td.noborder     { color: transparent; background: transparent; border: 0pt none !important; }
 17 h4             { font-size: 12pt; margin-top: 0pt; padding-top: 0pt; }
 18 a img         { border: 1px solid transparent; }
 19 a:hover img     { border: 1px solid transparent; }
 20 a.eurolotto, a.eurolotto:link      { font-size:11pt; font-weight:bold; color:#fff; text-decoration:none; padding:2pt 5pt 3pt 5pt; }
 21 a.black      { color:#fff; background:#000; padding:1pt 4pt 2pt 4pt; border:1px solid black;  }
 22 a.black:hover     { box-shadow: 2px 2px 4px black; border:1px solid white; }
 23 a.green      { color:#fff; background:green; border:1px solid green;  }
 24 a.green:hover    { box-shadow: 2px 2px 4px green; border:1px solid white; }
 25 #lotto          { float:left; border:1pt solid gray; text-align:center; width:34px; height:28px; margin:0 8px 8px 0; background:#fff; }
 26 #choosen      { font-size:11pt; font-weight:bold; display:inline; line-height:30px; margin-bottom:10px; padding: 5px 10px; background:#fff; border: 1pt dashed gray; clear: both; }
 27 #board         {  }
 28 form         { padding:0; margin:-2px 1pt 0 0; }
 29 select         { background:#ff7373; border:1pt solid #858585; border-radius:3pt; box-shadow:2pt 2pt 3pt #000; font-family:verdana,sans-serif; font-size: 16px; }
 30 select:hover { background:transparent; border:1pt solid #f5f5f5;  }
 31 .probability { float:left; padding:0 1pt; padding-top:8pt; margin:0 1pt; font-size:16px; }
 32 .coral         { position:absolute; right:2em; width:100pt; border:1pt solid #858585; border-radius:10px; box-shadow:2pt 2pt 4pt #858585; margin-right:20pt; padding:15pt 10pt; }
 33 span.generator    { cursor:default; text-decoration:none; color: #f5f5ff; }
 34 </style>
 35 
 36 <script type="text/javascript">
 37 function $(int) {
 38     return document.getElementById(int);
 39 }
 40 var myZufall=Array(45).fill().map((_, i) => ++i);
 41 var myGame=new Array();
 42 var abstand;
 43 function memorize(int) {
 44   if(myGame.length < 6 && in_array(int,myGame)==false) {
 45     $('td_'+int).style.color='#f5f5f5';
 46     $('td_'+int).style.fontWeight='bold';
 47     $('td_'+int).style.background='tomato';
 48     myGame.push(int);
 49     abstand=myGame.length >1 ? ' - ' : '';
 50     $('choosen').innerHTML+=abstand+myGame[(myGame.length)-1];
 51     $('choosen').style.visibility='visible';
 52       if(myGame.length==6) {
 53       $('board').style.visibility='visible';
 54       document.cookie="lottozahlen="+myGame;
 55     }
 56   }
 57 }
 58 function choice() {
 59     var r=shuffleArray(myZufall);
 60     myZufall=r.slice(0,6);
 61     document.cookie="lottozahlen="+myZufall;
 62     myZufall.sort(function(a, b) {
 63           return a - b;
 64     });
 65     console.log(myZufall);
 66     while (i < myZufall.length) {
 67           $('td_'+ myZufall[i]).style.backgroundColor='tomato';
 68         $('td_'+ myZufall[i]).style.fontColor='white';
 69         $('td_'+ myZufall[i]).style.fontWeight='bolder';
 70         /***************************************************/
 71         abstand=i==6 || i==0 ? '' : ' - ';
 72         $('choosen').innerHTML+=abstand+myZufall[i]+"";
 73         i++;
 74     }
 75     $('choosen').style.visibility='visible';
 76     $('board').style.visibility='visible';
 77 }
 78 function shuffleArray(arr){
 79             for (var i = arr.length; i--;){
 80                 var sIndex = Math.floor(Math.random() * (i + 1));
 81                 var h = arr[i];
 82                 arr[i] = arr[sIndex];
 83                 arr[sIndex] = h;
 84             }
 85             return arr;
 86 }
 87 function in_array (needle, haystack) {
 88     var key=''; 
 89     for (key in haystack) {
 90         if (haystack[key]==needle) {
 91             return true;
 92         }
 93     }
 94     return false;
 95 }
 96 /*** Cookies auslesen: https://www.mediaevent.de/javascript/cookie-read.html ***/
 97 var cookieList = (document.cookie) ? document.cookie.split(';') : [];
 98 var cookieValues = {};
 99 for (var i = 0, n = cookieList.length; i != n; ++i) {
100   var cookie = cookieList[i];
101   var f = cookie.indexOf('=');
102   if (f >= 0) {
103     var cookieName = cookie.substring(0, f);
104     var cookieValue = cookie.substring(f + 1);
105     
106     console.log ("cookieName + " + cookieName + " cookieValue " + cookieValue);
107     
108     if (!cookieValues.hasOwnProperty(cookieName)) {
109       cookieValues[cookieName] = cookieValue;
110     }
111   }
112 }
113 </script>
114 
115 <?php
116 /********************************************************
117  * in_array() zugriff via $key vom array.                 *
118  * vorteil: reihen koennen besser abgefuellt werden.    *
119 ********************************************************/
120 $range  = range(1, 45);
121 $arrandKeys = array_rand($range, 6);    
122 //print_r($arrandKeys);
123 $arrand = rebuild($arrandKeys);        
124 //print_r($arrand);
125 $anz_nebeneinander = 6;                                     
126 $myTipp  = array();
127 $treffer = array();
128 $whileLoop  = '';
129 $statistics = '';
130 
131 function rebuild($arrandKeys) {
132     foreach($arrandKeys as $v) {
133         $arrand[] .= ++$v;
134     }
135     return $arrand;
136 }
137 
138 /*** $_cookie auslesen ***/
139 if( isset($_GET['game']) ) {
140   /* echo '<pre>';
141   print_r($arrandKeys);
142   print_r($arrand);
143   //print($_COOKIE['lottozahlen']);
144   echo '</pre>'; */
145   $myTipp = explode(",", $_COOKIE['lottozahlen']);
146   foreach ($myTipp as $zahl)
147   {
148       if (in_array($zahl, $arrand)) {
149       $treffer[] .= $zahl;
150       }
151   }
152   
153   if(isset($_POST['sel'])) {
154       $ctr = 0;
155     while( count($treffer) < $_POST['sel'] && $ctr < 100000 ) {
156       $ctr++;
157       $treffer = array();
158       $arrandKeys = array_rand($range, 6);
159       $arrand = rebuild($arrandKeys);
160       foreach ($myTipp as $zahl) {
161         if (in_array($zahl, $arrand)) {
162             $treffer[] = $zahl;
163         }
164       }
165       //echo 'im '. $ctr. '. Spiel: '.count($treffer).' richtige<br />';
166       }
167     $whileLoop  = 'im '. $ctr .'. Spiel';
168     $mio = $ctr==100000 ? 'unter ' : ''; 
169     $statistics = '<div style=""><span class="wahr">Die Wahrscheinlichkeit von '. $_POST['sel'] .' richtigen liegt bei '. $mio .''. round((100/$ctr), $_POST['sel']) .'%</span></div>';
170   }
171 }
172 
173 echo '<article>';
174 
175 echo '<h2 class="head">Eurolotto 6 aus 45</h2>';
176 
177 $tipp = '<h4 id="tipp">W&auml;hle 6 Zahlen: <span class="generator" onclick="choice();">oder per Gl&uuml;cksrad</span></h4>';
178 $wahl = '<h4 id="tipp">Dein Zahlentipp 6 aus 45:</h4>';
179 
180 echo '<div class="tab">';
181 echo isset($_GET['game']) ? $wahl : $tipp;
182 echo '<table cellspacing="10" cellpadding="1">';
183 foreach ($range as $i => $number)
184 {
185     if(in_array($number, $myTipp)) {
186         $class = 'class="tomato"';
187         if(in_array($number, $treffer)) {
188             $class = count($treffer) <=2 ? 'class="volltreffer tom"' : 'class="volltreffer lime"';
189             //echo count($treffer);
190         }
191     } else { $class = ''; }
192     if ($i % $anz_nebeneinander == 0) { echo '<tr>'; }
193        echo '<td onclick="memorize('. $number .');" style="cursor:pointer;" title="Die '. $number .' ausw&auml;hlen" id="td_'. $number .'" '. $class .'>'. $number .'</td>';
194     if (($i+1) % $anz_nebeneinander == 0) { echo '</tr>'; }
195 }
196 if ($i+1 % $anz_nebeneinander > 0) {
197     for ($j = $i % $anz_nebeneinander; $j < ($anz_nebeneinander-1); $j++) {
198         echo '<td class="noborder">&curren;</td>';
199     }
200     echo '</tr>'."\n";
201 }
202 echo '</table></div>';
203 
204   /************************************************************************
205   * in_array() Zugriff via $value                                          *
206  * bei Anordnung mit DIV werden die $keys des Array nicht benoetigt.    *
207 ************************************************************************/
208 
209 $style         = isset($_GET['game'])     ? 'visible' : 'hidden';
210 $showWhat     = isset($_GET['game'])     ? 1 : 0;
211 $bgCss        = count($treffer) <=2   ? 'background:tomato; color:white;' : 'background:limegreen; color:white;';
212 $bgCss        = $showWhat             ? $bgCss : '';
213 
214 echo '<div id="ziehung" style="visibility:'. $style .'; float:left; width:270px; border:0pt dashed gray; margin-left:50px;">';
215 echo '<h4 style="padding-bottom:5pt;">Die Lottozahlen sind:</h4>';
216   foreach ($range as $number)
217   {
218     echo '<div id="lotto">';
219     if (in_array($number, $arrand) && isset($_GET['game']))
220     {
221            $farbe = in_array($number, $myTipp) ? 'treffer': 'treffer';
222         echo '<div style="line-height:28px;" class="'. $farbe .'">' . $number . '</div>';
223     }
224     else
225     {
226         echo '<div style="line-height:28px;">' . $number . '</div>';
227     }
228     echo '</div>';
229   }
230 echo '</div>';
231 
232 echo '<div style="clear:both;"></div>';
233 
234 $msg = $showWhat ? 'Deine Trefferquote: '. count($treffer) .' richtige !' : 'Dein Zahlentipp: ';
235 echo '<div id="choosen" style="visibility:'. $style .';'. $bgCss .'">'. $msg .'</div>';
236 
237 /*
238 if($mio=='') {
239    if(isset($_GET['game']) && $mio=='') {
240     echo '<div id="choosen" style="display:block;">Deine Trefferquote: '. count($treffer) .' richtige '. $whileLoop .'</div>';
241    } else {
242     echo '<div id="choosen" style="display:none;">Dein Zahlentipp: </div>';
243    }
244 }
245 echo $statistics;
246 
247 $select  ='<form action="' . $_SERVER['PHP_SELF'] . '?game=on&amp;nid=nine&amp;probability" method="post">';
248 $select .='<select name="sel" onchange="this.form.submit();">';
249 $select .='<option value="0">...</option>';
250 $select .='<option value="3">3</option>';
251 $select .='<option value="4">4</option>';
252 $select .='<option value="5">5</option>';
253 $select .='<option value="6">6</option>';
254 $select .='</select>';
255 $select .='</form>';
256 $select  = isset($_POST['sel']) ? $_POST['sel'] : $select; 
257 */
258 
259 //print_r($_REQUEST);
260 
261 $rahmen        = '';
262 $ziehung      = '';
263 $newLotto     = '';
264 $wahrscheinlichkeit = '';
265 
266 $ziehung .= '<div id="board" style="margin:40px 0 40px 0; visibility:'. $style .';">';
267 $ziehung .= '<a class="eurolotto green" href="' . $_SERVER['PHP_SELF'] . '?game=on&amp;nid=nine">Lottozahlen ziehen</a>';
268 $ziehung .= '</div>';
269 
270 $wahrscheinlichkeit .= '<div style="margin:1em 0; border-top:2pt dotted #555; padding-top:1em;">';
271 $wahrscheinlichkeit .= '<div class="probability">Wahrscheinlichkeit f&uuml;r </div><div class="probability"> '. $select .' </div><div class="probability"> richtige berechnen</div>';
272 $wahrscheinlichkeit .= '<div style="clear:left;"></div>';
273 $wahrscheinlichkeit .= '</div>';
274 //$wahrscheinlichkeit = isset($_GET['probability']) ? '' : $wahrscheinlichkeit;
275 
276 $newLotto .= '<div style="margin:40px 0 40px 0;">';
277 $newLotto .= '<a class="eurolotto black" href="' . $_SERVER['PHP_SELF'] . '?nid=nine">neues Lotto starten</a>';
278 $newLotto .= '</div>';
279 
280 print $showWhat ? $newLotto : $ziehung;
281 
282 echo '</article>';
283 ?>
284