Dateigrösse: 10.51 kb
<style type="text/css">
article { padding: 5px 0 0 20px; }
h2.head { letter-spacing:1px; margin:1em 0 1em 0; font-size: 2em; }
.wahr { letter-spacing:2px; color:green; border:1pt solid green; padding:10pt; margin-top:20pt; font-weight:bold; }
.tab { float:left; margin-right:140px; margin-bottom:0px; }
.clear { clear:both; }
table { color:black; font-size:14px; font-family:verdana,sans-serif; margin-left: -8px; }
td { width:32px; height:30px; text-align:center; border:1pt solid gray; background:#fff; }
.treffer { font-weight: bold; color: #000; background: #ff9; }
.tomato { font-weight: bold; color: tomato; }
.volltreffer { font-weight: bold; }
.tom { color: #fff; background: tomato; }
.lime { color: #fff; background: limegreen; }
td.treffer { background: limegreen !important; }
td.noborder { color: transparent; background: transparent; border: 0pt none !important; }
h4 { font-size: 12pt; margin-top: 0pt; padding-top: 0pt; }
a img { border: 1px solid transparent; }
a:hover img { border: 1px solid transparent; }
a.eurolotto, a.eurolotto:link { font-size:11pt; font-weight:bold; color:#fff; text-decoration:none; padding:2pt 5pt 3pt 5pt; }
a.black { color:#fff; background:#000; padding:1pt 4pt 2pt 4pt; border:1px solid black; }
a.black:hover { box-shadow: 2px 2px 4px black; border:1px solid white; }
a.green { color:#fff; background:green; border:1px solid green; }
a.green:hover { box-shadow: 2px 2px 4px green; border:1px solid white; }
#lotto { float:left; border:1pt solid gray; text-align:center; width:34px; height:28px; margin:0 8px 8px 0; background:#fff; }
#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; }
#board { }
form { padding:0; margin:-2px 1pt 0 0; }
select { background:#ff7373; border:1pt solid #858585; border-radius:3pt; box-shadow:2pt 2pt 3pt #000; font-family:verdana,sans-serif; font-size: 16px; }
select:hover { background:transparent; border:1pt solid #f5f5f5; }
.probability { float:left; padding:0 1pt; padding-top:8pt; margin:0 1pt; font-size:16px; }
.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; }
span.generator { cursor:default; text-decoration:none; color: #f5f5ff; }
</style>
<script type="text/javascript">
function $(int) {
return document.getElementById(int);
}
var myZufall=Array(45).fill().map((_, i) => ++i);
var myGame=new Array();
var abstand;
function memorize(int) {
if(myGame.length < 6 && in_array(int,myGame)==false) {
$('td_'+int).style.color='#f5f5f5';
$('td_'+int).style.fontWeight='bold';
$('td_'+int).style.background='tomato';
myGame.push(int);
abstand=myGame.length >1 ? ' - ' : '';
$('choosen').innerHTML+=abstand+myGame[(myGame.length)-1];
$('choosen').style.visibility='visible';
if(myGame.length==6) {
$('board').style.visibility='visible';
document.cookie="lottozahlen="+myGame;
}
}
}
function choice() {
var r=shuffleArray(myZufall);
myZufall=r.slice(0,6);
document.cookie="lottozahlen="+myZufall;
myZufall.sort(function(a, b) {
return a - b;
});
console.log(myZufall);
while (i < myZufall.length) {
$('td_'+ myZufall[i]).style.backgroundColor='tomato';
$('td_'+ myZufall[i]).style.fontColor='white';
$('td_'+ myZufall[i]).style.fontWeight='bolder';
/***************************************************/
abstand=i==6 || i==0 ? '' : ' - ';
$('choosen').innerHTML+=abstand+myZufall[i]+"";
i++;
}
$('choosen').style.visibility='visible';
$('board').style.visibility='visible';
}
function shuffleArray(arr){
for (var i = arr.length; i--;){
var sIndex = Math.floor(Math.random() * (i + 1));
var h = arr[i];
arr[i] = arr[sIndex];
arr[sIndex] = h;
}
return arr;
}
function in_array (needle, haystack) {
var key='';
for (key in haystack) {
if (haystack[key]==needle) {
return true;
}
}
return false;
}
/*** Cookies auslesen: https://www.mediaevent.de/javascript/cookie-read.html ***/
var cookieList = (document.cookie) ? document.cookie.split(';') : [];
var cookieValues = {};
for (var i = 0, n = cookieList.length; i != n; ++i) {
var cookie = cookieList[i];
var f = cookie.indexOf('=');
if (f >= 0) {
var cookieName = cookie.substring(0, f);
var cookieValue = cookie.substring(f + 1);
console.log ("cookieName + " + cookieName + " cookieValue " + cookieValue);
if (!cookieValues.hasOwnProperty(cookieName)) {
cookieValues[cookieName] = cookieValue;
}
}
}
</script>
<?php
/********************************************************
* in_array() zugriff via $key vom array. *
* vorteil: reihen koennen besser abgefuellt werden. *
********************************************************/
$range = range(1, 45);
$arrandKeys = array_rand($range, 6);
//print_r($arrandKeys);
$arrand = rebuild($arrandKeys);
//print_r($arrand);
$anz_nebeneinander = 6;
$myTipp = array();
$treffer = array();
$whileLoop = '';
$statistics = '';
function rebuild($arrandKeys) {
foreach($arrandKeys as $v) {
$arrand[] .= ++$v;
}
return $arrand;
}
/*** $_cookie auslesen ***/
if( isset($_GET['game']) ) {
/* echo '<pre>';
print_r($arrandKeys);
print_r($arrand);
//print($_COOKIE['lottozahlen']);
echo '</pre>'; */
$myTipp = explode(",", $_COOKIE['lottozahlen']);
foreach ($myTipp as $zahl)
{
if (in_array($zahl, $arrand)) {
$treffer[] .= $zahl;
}
}
if(isset($_POST['sel'])) {
$ctr = 0;
while( count($treffer) < $_POST['sel'] && $ctr < 100000 ) {
$ctr++;
$treffer = array();
$arrandKeys = array_rand($range, 6);
$arrand = rebuild($arrandKeys);
foreach ($myTipp as $zahl) {
if (in_array($zahl, $arrand)) {
$treffer[] = $zahl;
}
}
//echo 'im '. $ctr. '. Spiel: '.count($treffer).' richtige<br />';
}
$whileLoop = 'im '. $ctr .'. Spiel';
$mio = $ctr==100000 ? 'unter ' : '';
$statistics = '<div style=""><span class="wahr">Die Wahrscheinlichkeit von '. $_POST['sel'] .' richtigen liegt bei '. $mio .''. round((100/$ctr), $_POST['sel']) .'%</span></div>';
}
}
echo '<article>';
echo '<h2 class="head">Eurolotto 6 aus 45</h2>';
$tipp = '<h4 id="tipp">Wähle 6 Zahlen: <span class="generator" onclick="choice();">oder per Glücksrad</span></h4>';
$wahl = '<h4 id="tipp">Dein Zahlentipp 6 aus 45:</h4>';
echo '<div class="tab">';
echo isset($_GET['game']) ? $wahl : $tipp;
echo '<table cellspacing="10" cellpadding="1">';
foreach ($range as $i => $number)
{
if(in_array($number, $myTipp)) {
$class = 'class="tomato"';
if(in_array($number, $treffer)) {
$class = count($treffer) <=2 ? 'class="volltreffer tom"' : 'class="volltreffer lime"';
//echo count($treffer);
}
} else { $class = ''; }
if ($i % $anz_nebeneinander == 0) { echo '<tr>'; }
echo '<td onclick="memorize('. $number .');" style="cursor:pointer;" title="Die '. $number .' auswählen" id="td_'. $number .'" '. $class .'>'. $number .'</td>';
if (($i+1) % $anz_nebeneinander == 0) { echo '</tr>'; }
}
if ($i+1 % $anz_nebeneinander > 0) {
for ($j = $i % $anz_nebeneinander; $j < ($anz_nebeneinander-1); $j++) {
echo '<td class="noborder">¤</td>';
}
echo '</tr>'."\n";
}
echo '</table></div>';
/************************************************************************
* in_array() Zugriff via $value *
* bei Anordnung mit DIV werden die $keys des Array nicht benoetigt. *
************************************************************************/
$style = isset($_GET['game']) ? 'visible' : 'hidden';
$showWhat = isset($_GET['game']) ? 1 : 0;
$bgCss = count($treffer) <=2 ? 'background:tomato; color:white;' : 'background:limegreen; color:white;';
$bgCss = $showWhat ? $bgCss : '';
echo '<div id="ziehung" style="visibility:'. $style .'; float:left; width:270px; border:0pt dashed gray; margin-left:50px;">';
echo '<h4 style="padding-bottom:5pt;">Die Lottozahlen sind:</h4>';
foreach ($range as $number)
{
echo '<div id="lotto">';
if (in_array($number, $arrand) && isset($_GET['game']))
{
$farbe = in_array($number, $myTipp) ? 'treffer': 'treffer';
echo '<div style="line-height:28px;" class="'. $farbe .'">' . $number . '</div>';
}
else
{
echo '<div style="line-height:28px;">' . $number . '</div>';
}
echo '</div>';
}
echo '</div>';
echo '<div style="clear:both;"></div>';
$msg = $showWhat ? 'Deine Trefferquote: '. count($treffer) .' richtige !' : 'Dein Zahlentipp: ';
echo '<div id="choosen" style="visibility:'. $style .';'. $bgCss .'">'. $msg .'</div>';
/*
if($mio=='') {
if(isset($_GET['game']) && $mio=='') {
echo '<div id="choosen" style="display:block;">Deine Trefferquote: '. count($treffer) .' richtige '. $whileLoop .'</div>';
} else {
echo '<div id="choosen" style="display:none;">Dein Zahlentipp: </div>';
}
}
echo $statistics;
$select ='<form action="' . $_SERVER['PHP_SELF'] . '?game=on&nid=nine&probability" method="post">';
$select .='<select name="sel" onchange="this.form.submit();">';
$select .='<option value="0">...</option>';
$select .='<option value="3">3</option>';
$select .='<option value="4">4</option>';
$select .='<option value="5">5</option>';
$select .='<option value="6">6</option>';
$select .='</select>';
$select .='</form>';
$select = isset($_POST['sel']) ? $_POST['sel'] : $select;
*/
//print_r($_REQUEST);
$rahmen = '';
$ziehung = '';
$newLotto = '';
$wahrscheinlichkeit = '';
$ziehung .= '<div id="board" style="margin:40px 0 40px 0; visibility:'. $style .';">';
$ziehung .= '<a class="eurolotto green" href="' . $_SERVER['PHP_SELF'] . '?game=on&nid=nine">Lottozahlen ziehen</a>';
$ziehung .= '</div>';
$wahrscheinlichkeit .= '<div style="margin:1em 0; border-top:2pt dotted #555; padding-top:1em;">';
$wahrscheinlichkeit .= '<div class="probability">Wahrscheinlichkeit für </div><div class="probability"> '. $select .' </div><div class="probability"> richtige berechnen</div>';
$wahrscheinlichkeit .= '<div style="clear:left;"></div>';
$wahrscheinlichkeit .= '</div>';
//$wahrscheinlichkeit = isset($_GET['probability']) ? '' : $wahrscheinlichkeit;
$newLotto .= '<div style="margin:40px 0 40px 0;">';
$newLotto .= '<a class="eurolotto black" href="' . $_SERVER['PHP_SELF'] . '?nid=nine">neues Lotto starten</a>';
$newLotto .= '</div>';
print $showWhat ? $newLotto : $ziehung;
echo '</article>';
?>