OSdata.com: holistic issues 

OSdata.com

example source code
game.php

    Building a game — open source code This is the actual source code from a new web game. See the game at thissideofsanity.com and read how this was built starting at example code.

    This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.

    Copyright 2013 Milo (for software), Distribution and website handled by Strazbick.com

    Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

    This narrative uses anchor links so that you can follow the building of this software in chronological order. Go to software explanation to start reading. Go to thissideofsanity.com to see the working software.

Google

example source code
game.php

    This is example code from the SlamZee project and This Side of Sanity, released under Apache License 2.0.

slot machine
first pass

    The first version of this file only runs the slot machine effect. Later we will fold in all of the other game elements here.

    The owners wanted a slot machine effect. The visual presentation is based on the “little CSS3 experiment” by Jonathan Shook, located at http://snook.ca/technical/slots/. Please compare the original to see how easy it is to avoid reinventing the wheel. There are many great examples of starter code that you can use to expand into real projects. Look for things that are published as examples or tutorials and follow the license restrictions imposed by the original author. And always give appropriate credit, as I have done in this case.

    The code for the picture used in this slot machine effect is located at makepicture.php.

<?php

/* FILE: /game.php */

// include function files for this application
   require_once('./php/accounts.php');
   require_once('./php/databasefunctions.php');
   require_once('./php/gamefunctions.php');
   require_once('./php/gameobject.php');

/******************************/
/* GLOBALS                                                  */
/******************************/
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

/******************************/
/* FUNCTIONS                                                */
/******************************/

function Spin0()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part1.'&part2='.$part2.'&part3='.$part3.'&part4='.$part4.'&part5='.$part5.'&part6='.$part6.'&part7='.$part7.'&part8='.$part8;

  return $picturl;

} /* END function Spin0 */

function Spin1()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part2.'&part2='.$part3.'&part3='.$part4.'&part4='.$part5.'&part5='.$part6.'&part6='.$part7.'&part7='.$part8.'&part8='.$part1;

  return $picturl;

} /* END function Spin1 */

function Spin2()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part3.'&part2='.$part4.'&part3='.$part5.'&part4='.$part6.'&part5='.$part7.'&part6='.$part8.'&part7='.$part1.'&part8='.$part2;

  return $picturl;

} /* END function Spin2 */

function Spin3()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part4.'&part2='.$part5.'&part3='.$part6.'&part4='.$part7.'&part5='.$part8.'&part6='.$part1.'&part7='.$part2.'&part8='.$part3;

  return $picturl;

} /* END function Spin3 */

function Spin4()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part5.'&part2='.$part6.'&part3='.$part7.'&part4='.$part8.'&part5='.$part1.'&part6='.$part2.'&part7='.$part3.'&part8='.$part4;

  return $picturl;

} /* END function Spin4 */

function Spin5()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part6.'&part2='.$part7.'&part3='.$part8.'&part4='.$part1.'&part5='.$part2.'&part6='.$part3.'&part7='.$part4.'&part8='.$part5;

  return $picturl;

} /* END function Spin5 */

function Spin6()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part7.'&part2='.$part8.'&part3='.$part1.'&part4='.$part2.'&part5='.$part3.'&part6='.$part4.'&part7='.$part5.'&part8='.$part6;

  return $picturl;

} /* END function Spin6 */

function Spin7()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part8.'&part2='.$part1.'&part3='.$part2.'&part4='.$part3.'&part5='.$part4.'&part6='.$part5.'&part7='.$part6.'&part8='.$part7;

  return $picturl;

} /* END function Spin7 */

function SpinByNumber($spinnumber)
{

  if ( $spinnumber == 0 )
    return Spin0();
  elseif ( $spinnumber == 1 )
    return Spin1();
  elseif ( $spinnumber == 2 )
    return Spin2();
  elseif ( $spinnumber == 3 )
    return Spin3();
  elseif ( $spinnumber == 4 )
    return Spin4();
  elseif ( $spinnumber == 5 )
    return Spin5();
  elseif ( $spinnumber == 6 )
    return Spin6();
  else /* should be case of 7 */
    return Spin7();

} /* END function SpinByNumber */


function ErrorReporting()
{

/* this function was used during construction and is no longer needed */

} /* END FUNCTION ErrorReporting */

/******************************/
/* Main Page                                                 */
/* serve various game functions                   */
/******************************/

/* create celebrity numbers */

$part1 = GetCelebrity();

$part2 = GetCelebrity();

while ($part2 == $part1)
  {
    $part2 = GetCelebrity();
  } /* END WHILE $part2 */

$part3 = GetCelebrity();

while ( ($part3 == $part1) OR ($part3 == $part2) )
  {
    $part3 = GetCelebrity();
  } /* END WHILE $part3 */

/* part 4 is the winner */
$part4 = GetCelebrity();

while ( ($part4 == $part1) OR ($part4 == $part2) OR ($part4 == $part3) )
  {
    $part4 = GetCelebrity();
  } /* END WHILE $part4 */

$part5 = GetCelebrity();

while ( ($part5 == $part1) OR ($part5 == $part2) OR ($part5 == $part3) OR ($part5 == $part4) )
  {
    $part5 = GetCelebrity();
  } /* END WHILE $part5 */

$part6 = GetCelebrity();

while ( ($part6 == $part1) OR ($part6 == $part2) OR ($part6 == $part3) OR ($part6 == $part4) OR ($part6 == $part5) )
  {
    $part6 = GetCelebrity();
  } /* END WHILE $part6 */

$part7 = GetCelebrity();

while ( ($part7 == $part1) OR ($part7 == $part2) OR ($part7 == $part3) OR ($part7 == $part4) OR ($part7 == $part5) OR ($part7 == $part6) )
  {
    $part7 = GetCelebrity();
  } /* END WHILE $part7 */

$part8 = GetCelebrity();

while ( ($part8 == $part1) OR ($part8 == $part2) OR ($part8 == $part3) OR ($part8 == $part4) OR ($part8 == $part5) OR ($part8 == $part6) OR ($part8 == $part7) )
  {
    $part8 = GetCelebrity();
  } /* END WHILE $part7 */

/* determine winning conditions */
$randomnumber = rand(0,7);

if ($randomnumber == 0)
  { /* have a three way winner */
    $spinresult = 1;
  } /* END three way winner */
elseif ($randomnumber == 3)
  { /* have a two way winner */
    $tempnumber = rand(0,2);
    If ($tempnumber == 0)
      $spinresult = 2;
    elseIf ($tempnumber == 1)
      $spinresult = 3;
    else
      $spinresult = 4;
  } /* END two way winner */
else
  { /* have a loser */
    $tempnumber = rand(0,3);
    If ($tempnumber == 0)
      $spinresult = 5;
    elseIf ($tempnumber == 1)
      $spinresult = 6;
    elseIf ($tempnumber == 1)
      $spinresult = 7;
    else
      $spinresult = 8;
  } /* END loser */

/* set picture options */
/* amount of shift = a = any other than 0 or match */
/* 1 = 0 0 0 */
/* 2 = 0 a 0 */
/* 3 = 0 0 a */
/* 4 = a 0 0 */
/* 5 = 0 a a */
/* 6 = a 0 a */
/* 7 = a a 0 */
/* 8 = a a a */

if ( $spinresult == 1 )
  {
    $scrollpict1url = 'makepicture.php?part1='.Spin0();
    $scrollpict2url = 'makepicture.php?part1='.Spin0();
    $scrollpict3url = 'makepicture.php?part1='.Spin0();
  }
elseif ( $spinresult == 2 )
  {
    $randomchoice = rand(1,7);
    $scrollpict1url = 'makepicture.php?part1='.Spin0();
    $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice);
    $scrollpict3url = 'makepicture.php?part1='.Spin0();
  }
elseif ( $spinresult == 3 )
  {
    $randomchoice = rand(1,7);
    $scrollpict1url = 'makepicture.php?part1='.Spin0();
    $scrollpict2url = 'makepicture.php?part1='.Spin0();
    $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice);
  }
elseif ( $spinresult == 4 )
  {
    $randomchoice = rand(1,7);
    $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice);
    $scrollpict2url = 'makepicture.php?part1='.Spin0();
    $scrollpict3url = 'makepicture.php?part1='.Spin0();
  }
elseif ( $spinresult == 5 )
  {
    $randomchoice1 = rand(1,7);
    $randomchoice2 = rand(1,7);
    while ($randomchoice1 == $randomchoice2)
      {
        $randomchoice2 = rand(1,7);
      }
    $scrollpict1url = 'makepicture.php?part1='.Spin0();
    $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice1);
    $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice2);
  }
elseif ( $spinresult == 6 )
  {
    $randomchoice1 = rand(1,7);
    $randomchoice2 = rand(1,7);
    while ($randomchoice1 == $randomchoice2)
      {
        $randomchoice2 = rand(1,7);
      }
    $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice1);
    $scrollpict2url = 'makepicture.php?part1='.Spin0();
    $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice2);
  }
elseif ( $spinresult == 7 )
  {
    $randomchoice1 = rand(1,7);
    $randomchoice2 = rand(1,7);
    while ($randomchoice1 == $randomchoice2)
      {
        $randomchoice2 = rand(1,7);
      }
    $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice1);
    $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice2);
    $scrollpict3url = 'makepicture.php?part1='.Spin0();
  }
else /* should be case of 8 */
  {
    $randomchoice1 = rand(1,7);
    $randomchoice2 = rand(1,7);
    while ($randomchoice1 == $randomchoice2)
      {
        $randomchoice2 = rand(1,7);
      }
    $randomchoice3 = rand(1,7);
    while ( ($randomchoice1 == $randomchoice3) OR ($randomchoice2 == $randomchoice3) )
      {
        $randomchoice3 = rand(1,7);
      }
    $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice1);
    $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice2);
    $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice3);
  }




?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html lang="en" dir="ltr">
<head>
<head><title>SlamZee slot machine</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=ISO-8859-1"></meta>
<meta name="revisit-after" content="15 days"></meta>
<meta name="robots" content="all"></meta>
<meta name="description" content="SlamZee -- slot machine."></meta>
<meta name="keywords" content="SlamZee slot machine"></meta>
<meta name="creation" content="2013-09-11"></meta>
<meta name="last-modified" content="2013-12-05"></meta>
<meta name="MSSmartTagsPreventParsing" content="TRUE"></meta>

<!--CSS style-->
    <style type="text/css">
        @-webkit-keyframes spin {
          0%  { background-position:0, 0 -640px; }
          100%   { background-position:0, 0 0; }
        }

        body {
            font-family: Arial, Helvetica, sans-serif; 
        }
        
        #machine { 
            width: 360px; 
            margin:auto; 
            padding:20px; 
            overflow:hidden; 
            background-color:#333; 
            background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#666666), to(#666666), color-stop(.6,#333)); 
            border-radius:10px; 
            }
        #machine > div { 
            float:left; 
            width:100px; 
            margin:10px; 
            height:160px; 
            background-color:#FFF; 
            background-position:0;
            -webkit-border-radius:5px; border-radius:5px; 
            -webkit-box-shadow:0 0 5px #000 inset; 
            
            }
        #a {
                        background-image: 
                -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,.6)), to(rgba(0,0,0,.6)), color-stop(.3,rgba(0,0,0,0)), color-stop(.7,rgba(0,0,0,0))), 
                url("<?php echo $scrollpict1url; ?>");
            -webkit-animation: spin 0.7s infinite linear;
            }
        #b {
                        background-image: 
                -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,.6)), to(rgba(0,0,0,.6)), color-stop(.3,rgba(0,0,0,0)), color-stop(.7,rgba(0,0,0,0))), 
                url("<?php echo $scrollpict2url; ?>");
            -webkit-animation: spin 1.2s infinite linear;
            }
        #c {
                        background-image: 
                -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,.6)), to(rgba(0,0,0,.6)), color-stop(.3,rgba(0,0,0,0)), color-stop(.7,rgba(0,0,0,0))), 
                url("<?php echo $scrollpict3url; ?>");
            -webkit-animation: spin 2.0s infinite linear;
            }
            
    </style>

<!--JavaScript-->
<script type="text/javascript">
<!--

/* GLOBALS (property of window object) */
var spincounter = 0;

<?php

/* REPORTING RESULTS */
if ($spinresult >= 5)
  { /* loser */
    echo 'var resultstring = '."'".'<span style="color:green">You win one credit!</span>'."';";
    echo 'var creditstring = '."'".'Tokens: 1       Credits: 6       Cash: $0.01'."';";
  } /* END IF loser */
elseif ($spinresult == 1)
  { /* 3-way winner */
    echo 'var resultstring = '."'".'<span style="color:green">You win six credits!</span>'."';";
    echo 'var creditstring = '."'".'Tokens: 1       Credits: <span style="color:green">11</span>       Cash: $0.01'."';";
  } /* END IF 3-way winner */
else
  { /* 2-way winner */
    echo 'var resultstring = '."'".'<span style="color:green">You win two credits!</span>'."';";
    echo 'var creditstring = '."'".'Tokens: 1       Credits: <span style="color:green">7</span>       Cash: $0.01'."';";
  } /* END IF 2-way winner */


?>


function runslotmachine() {

spincounter = 200 + 160;
//document.getElementById("threebutton").style.visibility = "hidden";
document.getElementById("results").innerHTML='<h1 align="center" style="color:green;">playing</h1>';
document.getElementById("results").style.visibility = "visible";

} /* END FUNCTION runslotmachine */

function stopslotmachine() {

//document.getElementById("a").style.setProperty("-webkit-transition", "background-position .7s");
//document.getElementById("a").style['webkit-transition'] =  'background-position .7s';
//document.getElementById("a").style.webkit-transition = 'background-position .7s';

document.getElementById("a").style.webkitAnimation =  'none';
document.getElementById("a").style.backgroundPosition =  '0, 0 840px';
document.getElementById("a").style.webkitTransition =  'background-position .7s';

document.getElementById("b").style.webkitAnimation =  'none';
document.getElementById("b").style.backgroundPosition =  '0, 0 840px';
document.getElementById("b").style.webkitTransition =  'background-position 1.2s';

document.getElementById("c").style.webkitAnimation =  'none';
document.getElementById("c").style.backgroundPosition =  '0, 0 840px';
document.getElementById("c").style.webkitTransition =  'background-position 1.6s';



//document.getElementById("results").style.visibility = "visible";

} /* END FUNCTION stopslotmachine */

function showresults() {

document.getElementById("results").style.visibility = "visible";
document.getElementById("results").innerHTML='<h1 align="center">'+ resultstring + '</h1>';
document.getElementById("credits").innerHTML='<h1 align="center">'+ creditstring + '</h1>';

} /* END FUNCTION stopslotmachine */

function spin() {

runslotmachine();

return false;
} /* END FUNCTION spin */

function redbuttonaction() {

if (gamemode == 'trivia' ) {

  return 0; /* prevent wiping out trivia question */

} /* END IF */

//document.getElementById("triviaanswer").innerHTML='<h1 align="center" style="color:red;">Red</h1>';

return false;
} /* END FUNCTION redbuttonaction */

function greenbuttonaction() {

if (gamemode == 'trivia' ) {

  return 0; /* prevent wiping out trivia question */

} /* END IF */

//document.getElementById("triviaanswer").innerHTML='<h1 align="center" style="color:green;">Green</h1>';

return false;
} /* END FUNCTION greenbuttonaction */

/* GLOBALS (property of window object) */
<!-- this javascript snippet draws the temptation box -->
var temptationdelaytime = 6000; /* 6 second delay */
var intervalhandle;

var temptingswitch = false;

var hourcounter = 0;
var minutecounter = 0;
var secondcounter = 0;
var tenthsecondcounter = 0;
var hundredthsecondcounter = 0;

function checktimedispatcher() {

/* TIMER COUNT DOWN AFTER A SPIN */
if ( spincounter > 0 ) {

  spincounter = spincounter - 1 ; /* decrement */
  if ( spincounter == 200 ) {
    stopslotmachine();
  } /* END IF */
  if ( spincounter <= 0 ) {
    showresults();
  } /* END IF */

} /* END IF */

//document.getElementById("slamcounterelement").innerHTML= slamcounter; /* DEBUG */

var currentdate=new Date();
var currenttime= currentdate.toLocaleTimeString();
/*document.getElementById("timerelement").innerHTML= currenttime;*/

/* knocked out so that we look better - restore for debugging */
/* hundredthsecondcounter = hundredthsecondcounter +1;
document.getElementById("hundredthelement").innerHTML= hundredthsecondcounter;
if ( (hundredthsecondcounter%10) == 0 ) {
  tenthsecondcounter = tenthsecondcounter +1;
  document.getElementById("tenthelement").innerHTML= tenthsecondcounter;
  if ( (tenthsecondcounter%10) == 0) {
    secondcounter = secondcounter + 1;
    document.getElementById("secondelement").innerHTML= secondcounter;
    if ( (secondcounter%60) == 0) {
      minutecounter = minutecounter + 1;
      document.getElementById("minuteelement").innerHTML= minutecounter;
      if ( (minutecounter%60) == 0) {
        hourcounter = hourcounter + 1;
        document.getElementById("hourelement").innerHTML= hourcounter;
      } /* END hour check */
/*    } /* END minute check */
/*  } /* END second check */
/*} /* END tenth second check */

} /* END FUNCTION checktimedispatcher */

//-->
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>

<!--main HTML-->
<body text="#ffffff" bgcolor="#000000" onload="intervalhandle=window.setInterval(function() {checktimedispatcher() },10);">

<?php ErrorReporting(); ?>
    
<h1 align="center" style="width:320px;background-color:black;margin-left:auto; margin-right:auto;text-align:center;font-family:Geneva,sanserif;font-size:48px"><span style="color:red">Slam</span><span style="color:yellow">Z</span><span style="color:green">ee</span></h1>

    <div id="navigation" style="display:block; text-align:center;">
        <?php DisplaySpinner(); ?>
    </div>
    <div id="machine">
        <div id="a"></div>
        <div id="b"></div>
        <div id="c"></div>
    </div>

<div id="results" style="visibility:hidden;"></div>
<div id="credits"><h1 align="center">Tokens: 2       Credits: 5       Cash: $0.01</h1></div>

combining slot machine into whole game
partial merger
second pass

    Partial merger of the two files (the slot machine and the trivia game). In particular, make sure that the two sets of JavaScript are compatible (which took some work).

<?php

/* FILE: /game.php */

// include function files for this application
   require_once('./php/accounts.php');
   require_once('./php/databasefunctions.php');
   require_once('./php/datavalidation.php');
   require_once('./php/gamefunctions.php');
   require_once('./php/gameobject.php');
   require_once('./php/newregistration.php');
   require_once('./php/login.php');

/******************************/
/* GLOBALS                                                  */
/******************************/
global $errorcondition;
$errorcondition = FALSE;

global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

global $spinresult;
global $scrollpict1url;
global $scrollpict2url;
global $scrollpict3url;
global $randomchoice1;
global $randomchoice2;
global $randomchoice3;

/******************************/
/* FUNCTIONS                                                */
/******************************/

function Spin0()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part1.'&part2='.$part2.'&part3='.$part3.'&part4='.$part4.'&part5='.$part5.'&part6='.$part6.'&part7='.$part7.'&part8='.$part8;

  return $picturl;

} /* END function Spin0 */

function Spin1()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part2.'&part2='.$part3.'&part3='.$part4.'&part4='.$part5.'&part5='.$part6.'&part6='.$part7.'&part7='.$part8.'&part8='.$part1;

  return $picturl;

} /* END function Spin1 */

function Spin2()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part3.'&part2='.$part4.'&part3='.$part5.'&part4='.$part6.'&part5='.$part7.'&part6='.$part8.'&part7='.$part1.'&part8='.$part2;

  return $picturl;

} /* END function Spin2 */

function Spin3()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part4.'&part2='.$part5.'&part3='.$part6.'&part4='.$part7.'&part5='.$part8.'&part6='.$part1.'&part7='.$part2.'&part8='.$part3;

  return $picturl;

} /* END function Spin3 */

function Spin4()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part5.'&part2='.$part6.'&part3='.$part7.'&part4='.$part8.'&part5='.$part1.'&part6='.$part2.'&part7='.$part3.'&part8='.$part4;

  return $picturl;

} /* END function Spin4 */

function Spin5()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part6.'&part2='.$part7.'&part3='.$part8.'&part4='.$part1.'&part5='.$part2.'&part6='.$part3.'&part7='.$part4.'&part8='.$part5;

  return $picturl;

} /* END function Spin5 */

function Spin6()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part7.'&part2='.$part8.'&part3='.$part1.'&part4='.$part2.'&part5='.$part3.'&part6='.$part4.'&part7='.$part5.'&part8='.$part6;

  return $picturl;

} /* END function Spin6 */

function Spin7()
{
global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

  $picturl = $part8.'&part2='.$part1.'&part3='.$part2.'&part4='.$part3.'&part5='.$part4.'&part6='.$part5.'&part7='.$part6.'&part8='.$part7;

  return $picturl;

} /* END function Spin7 */

function SpinByNumber($spinnumber)
{

  if ( $spinnumber == 0 )
    return Spin0();
  elseif ( $spinnumber == 1 )
    return Spin1();
  elseif ( $spinnumber == 2 )
    return Spin2();
  elseif ( $spinnumber == 3 )
    return Spin3();
  elseif ( $spinnumber == 4 )
    return Spin4();
  elseif ( $spinnumber == 5 )
    return Spin5();
  elseif ( $spinnumber == 6 )
    return Spin6();
  else /* should be case of 7 */
    return Spin7();

} /* END function SpinByNumber */


function StartSlots()
{

global $part1;
global $part2;
global $part3;
global $part4;
global $part5;
global $part6;
global $part7;
global $part8;

global $spinresult;
global $scrollpict1url;
global $scrollpict2url;
global $scrollpict3url;
global $randomchoice1;
global $randomchoice2;
global $randomchoice3;

/* create celebrity numbers */

$part1 = GetCelebrity();

$part2 = GetCelebrity();

while ($part2 == $part1)
  {
    $part2 = GetCelebrity();
  } /* END WHILE $part2 */

$part3 = GetCelebrity();

while ( ($part3 == $part1) OR ($part3 == $part2) )
  {
    $part3 = GetCelebrity();
  } /* END WHILE $part3 */

/* part 4 is the winner */
$part4 = GetCelebrity();

while ( ($part4 == $part1) OR ($part4 == $part2) OR ($part4 == $part3) )
  {
    $part4 = GetCelebrity();
  } /* END WHILE $part4 */

$part5 = GetCelebrity();

while ( ($part5 == $part1) OR ($part5 == $part2) OR ($part5 == $part3) OR ($part5 == $part4) )
  {
    $part5 = GetCelebrity();
  } /* END WHILE $part5 */

$part6 = GetCelebrity();

while ( ($part6 == $part1) OR ($part6 == $part2) OR ($part6 == $part3) OR ($part6 == $part4) OR ($part6 == $part5) )
  {
    $part6 = GetCelebrity();
  } /* END WHILE $part6 */

$part7 = GetCelebrity();

while ( ($part7 == $part1) OR ($part7 == $part2) OR ($part7 == $part3) OR ($part7 == $part4) OR ($part7 == $part5) OR ($part7 == $part6) )
  {
    $part7 = GetCelebrity();
  } /* END WHILE $part7 */

$part8 = GetCelebrity();

while ( ($part8 == $part1) OR ($part8 == $part2) OR ($part8 == $part3) OR ($part8 == $part4) OR ($part8 == $part5) OR ($part8 == $part6) OR ($part8 == $part7) )
  {
    $part8 = GetCelebrity();
  } /* END WHILE $part7 */

/* determine winning conditions */
$randomnumber = rand(0,7);

if ($randomnumber == 0)
  { /* have a three way winner */
    $spinresult = 1;
  } /* END three way winner */
elseif ($randomnumber == 3)
  { /* have a two way winner */
    $tempnumber = rand(0,2);
    If ($tempnumber == 0)
      $spinresult = 2;
    elseIf ($tempnumber == 1)
      $spinresult = 3;
    else
      $spinresult = 4;
  } /* END two way winner */
else
  { /* have a loser */
    $tempnumber = rand(0,3);
    If ($tempnumber == 0)
      $spinresult = 5;
    elseIf ($tempnumber == 1)
      $spinresult = 6;
    elseIf ($tempnumber == 1)
      $spinresult = 7;
    else
      $spinresult = 8;
  } /* END loser */

/* set picture options */
/* amount of shift = a = any other than 0 or match */
/* 1 = 0 0 0 */
/* 2 = 0 a 0 */
/* 3 = 0 0 a */
/* 4 = a 0 0 */
/* 5 = 0 a a */
/* 6 = a 0 a */
/* 7 = a a 0 */
/* 8 = a a a */

if ( $spinresult == 1 )
  {
    $scrollpict1url = 'makepicture.php?part1='.Spin0();
    $scrollpict2url = 'makepicture.php?part1='.Spin0();
    $scrollpict3url = 'makepicture.php?part1='.Spin0();
  }
elseif ( $spinresult == 2 )
  {
    $randomchoice = rand(1,7);
    $scrollpict1url = 'makepicture.php?part1='.Spin0();
    $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice);
    $scrollpict3url = 'makepicture.php?part1='.Spin0();
  }
elseif ( $spinresult == 3 )
  {
    $randomchoice = rand(1,7);
    $scrollpict1url = 'makepicture.php?part1='.Spin0();
    $scrollpict2url = 'makepicture.php?part1='.Spin0();
    $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice);
  }
elseif ( $spinresult == 4 )
  {
    $randomchoice = rand(1,7);
    $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice);
    $scrollpict2url = 'makepicture.php?part1='.Spin0();
    $scrollpict3url = 'makepicture.php?part1='.Spin0();
  }
elseif ( $spinresult == 5 )
  {
    $randomchoice1 = rand(1,7);
    $randomchoice2 = rand(1,7);
    while ($randomchoice1 == $randomchoice2)
      {
        $randomchoice2 = rand(1,7);
      }
    $scrollpict1url = 'makepicture.php?part1='.Spin0();
    $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice1);
    $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice2);
  }
elseif ( $spinresult == 6 )
  {
    $randomchoice1 = rand(1,7);
    $randomchoice2 = rand(1,7);
    while ($randomchoice1 == $randomchoice2)
      {
        $randomchoice2 = rand(1,7);
      }
    $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice1);
    $scrollpict2url = 'makepicture.php?part1='.Spin0();
    $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice2);
  }
elseif ( $spinresult == 7 )
  {
    $randomchoice1 = rand(1,7);
    $randomchoice2 = rand(1,7);
    while ($randomchoice1 == $randomchoice2)
      {
        $randomchoice2 = rand(1,7);
      }
    $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice1);
    $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice2);
    $scrollpict3url = 'makepicture.php?part1='.Spin0();
  }
else /* should be case of 8 */
  {
    $randomchoice1 = rand(1,7);
    $randomchoice2 = rand(1,7);
    while ($randomchoice1 == $randomchoice2)
      {
        $randomchoice2 = rand(1,7);
      }
    $randomchoice3 = rand(1,7);
    while ( ($randomchoice1 == $randomchoice3) OR ($randomchoice2 == $randomchoice3) )
      {
        $randomchoice3 = rand(1,7);
      }
    $scrollpict1url = 'makepicture.php?part1='.SpinByNumber($randomchoice1);
    $scrollpict2url = 'makepicture.php?part1='.SpinByNumber($randomchoice2);
    $scrollpict3url = 'makepicture.php?part1='.SpinByNumber($randomchoice3);
  }

} /* END function StartSlots */


function ErrorReporting()
{

/* used for testing */

} /* END FUNCTION ErrorReporting */

function SQLReporting()
{

/* used for testing */

} /* END FUNCTION SQLReporting */

/******************************/
/* Main Page                                                 */
/* serve various game functions                   */
/******************************/

/* SESSION MANAGEMENT */
SessionManagement(); /* located in accounts.php */
$accountemail = CheckValidUser(); /* located in accounts.php */
/* empty string if not signed in, or string holds the official account email */


/* CHOOSE CELEBRITIES FOR SLOTS */
StartSlots();


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html lang="en" dir="ltr">
<head>
<head><title>SlamZee</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=ISO-8859-1"></meta>
<meta name="revisit-after" content="15 days"></meta>
<meta name="robots" content="all"></meta>
<meta name="description" content="SlamZee -- slot machine."></meta>
<meta name="keywords" content="SlamZee slot machine"></meta>
<meta name="creation" content="2013-11-18"></meta>
<meta name="last-modified" content="2013-11-24"></meta>
<meta name="MSSmartTagsPreventParsing" content="TRUE"></meta>
<link rel="stylesheet" type="text/css" href="./style.css">

<!--CSS style-->
    <style type="text/css">

      body {
        margin:0;
        padding:0;
      }
    </style>

    <style type="text/css">
        @-webkit-keyframes spin {
          0%  { background-position:0, 0 -640px; }
          100%   { background-position:0, 0 0; }
        }

        body {
            font-family: Arial, Helvetica, sans-serif; 
        }
        
        #machine { 
            width: 360px; 
            margin:auto; 
            padding:20px; 
            overflow:hidden; 
            background-color:#333; 
            background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#666666), to(#666666), color-stop(.6,#333)); 
            border-radius:10px; 
            }
        #machine > div { 
            float:left; 
            width:100px; 
            margin:10px; 
            height:160px; 
            background-color:#FFF; 
            background-position:0;
            -webkit-border-radius:5px; border-radius:5px; 
            -webkit-box-shadow:0 0 5px #000 inset; 
            
            }
        #a {
                        background-image: 
                -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,.6)), to(rgba(0,0,0,.6)), color-stop(.3,rgba(0,0,0,0)), color-stop(.7,rgba(0,0,0,0))), 
                url("<?php echo $scrollpict1url; ?>");
            -webkit-animation: spin 0.7s infinite linear;
            }
        #b {
                        background-image: 
                -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,.6)), to(rgba(0,0,0,.6)), color-stop(.3,rgba(0,0,0,0)), color-stop(.7,rgba(0,0,0,0))), 
                url("<?php echo $scrollpict2url; ?>");
            -webkit-animation: spin 1.2s infinite linear;
            }
        #c {
                        background-image: 
                -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(0,0,0,.6)), to(rgba(0,0,0,.6)), color-stop(.3,rgba(0,0,0,0)), color-stop(.7,rgba(0,0,0,0))), 
                url("<?php echo $scrollpict3url; ?>");
            -webkit-animation: spin 2.0s infinite linear;
            }
            
    </style>

<!--JavaScript-->
<script type="text/javascript">
<!--

/* GLOBALS (property of window object) */
var gamemode;

var spincounter = 0;

var slamcounter = 0;
var slamchoice;
var lovechoice;
var mastergamenumber;

/* INITIAL GAME MODE */
gamemode = 'slots';

<?php

/* REPORTING RESULTS */
/* this produces some JavaScript that creates variables for filling in slot results */
if ($spinresult >= 5)
  { /* loser */
    echo 'var resultstring = '."'".'<span style="color:green">You win one credit!</span>'."';";
    echo 'var creditstring = '."'".'Tokens: 1       Credits: 6       Cash: $0.01'."';";
  } /* END IF loser */
elseif ($spinresult == 1)
  { /* 3-way winner */
    echo 'var resultstring = '."'".'<span style="color:green">You win six credits!</span>'."';";
    echo 'var creditstring = '."'".'Tokens: 1       Credits: <span style="color:green">11</span>       Cash: $0.01'."';";
  } /* END IF 3-way winner */
else
  { /* 2-way winner */
    echo 'var resultstring = '."'".'<span style="color:green">You win two credits!</span>'."';";
    echo 'var creditstring = '."'".'Tokens: 1       Credits: <span style="color:green">7</span>       Cash: $0.01'."';";
  } /* END IF 2-way winner */


?>


function startgame() {

gamemode = 'trivia';

document.getElementById("targetarea").innerHTML="<p align=\"center\">loading game</p>";

var startgameurlstring = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/gameserver.php?start=villains";
var startgamexmlhttp = new XMLHttpRequest();
startgamexmlhttp.onreadystatechange=function()
  {
  if (startgamexmlhttp.readyState==4 && startgamexmlhttp.status==200)
    {
      document.getElementById("targetarea").innerHTML=startgamexmlhttp.responseText;
      document.getElementById("topstartgamearea").innerHTML="";
    }
else if (startgamexmlhttp.readyState==4) {newstring='code is '+startgamexmlhttp.status; document.getElementById("targetarea").innerHTML=newstring;}
  }
startgamexmlhttp.open("GET",startgameurlstring,true);
startgamexmlhttp.send();

return false;
} /* END FUNCTION startgame */


function makeslam(whichchoice,gamenumber) {

if (gamemode == 'trivia' ) {

/* remind them to answer the trivia question first */
  /*document.getElementById("triviaanswer").innerHTML="<h1 align=\"center\" style=\"color:red;\">Answer the trivia question first! The choice is "+whichchoice+" and the game is "+gamenumber+"</h1>";*/
  document.getElementById("triviaanswer").innerHTML="<h1 align=\"center\" style=\"color:red;\">Answer the trivia question first!</h1>";

  return 0; /* prevent multiple slam attempts during animation delay */

} /* END IF */

if (slamcounter > 0 ) {

  return 0; /* prevent multiple slam attempts during animation delay */

} /* END IF */

slamcounter = 120; /* 1.2 seconds (in hundredths of a second) */
slamchoice = whichchoice; /* store value in a global */
lovechoice = 0; /* clear value in a global */
mastergamenumber = gamenumber; /* store value in a global */

if ( whichchoice == 1 ) {

document.getElementById("broken1").style.visibility = "visible";

} /* END IF */

else {

document.getElementById("broken2").style.visibility = "visible";

} /* END ELSE */


document.getElementById("info1").style.visibility = "hidden";
document.getElementById("info2").style.visibility = "hidden";
document.getElementById("leftinfo").style.visibility = "hidden";
document.getElementById("rightinfo").style.visibility = "hidden";

return false;
} /* END FUNCTION makeslam */


function makelove(whichchoice,gamenumber) {

if (gamemode == 'trivia' ) {

/* remind them to answer the trivia question first */
  /*document.getElementById("triviaanswer").innerHTML="<h1 align=\"center\" style=\"color:red;\">Answer the trivia question first! The choice is "+love+" and the game is "+gamenumber+"</h1>";*/
  document.getElementById("triviaanswer").innerHTML="<h1 align=\"center\" style=\"color:red;\">Answer the trivia question first!</h1>";

  return 0; /* prevent multiple slam attempts during animation delay */

} /* END IF */

if (slamcounter > 0 ) {

  return 0; /* prevent multiple slam attempts during animation delay */

} /* END IF */

slamcounter = 120; /* 1.2 seconds (in hundredths of a second) */
lovechoice = whichchoice; /* store value in a global */
slamchoice = 0; /* clear value in a global */
mastergamenumber = gamenumber; /* store value in a global */

if ( whichchoice == 1 ) {

document.getElementById("kiss1").style.visibility = "visible";

} /* END IF */

else {

document.getElementById("kiss2").style.visibility = "visible";

} /* END ELSE */

document.getElementById("info1").style.visibility = "hidden";
document.getElementById("info2").style.visibility = "hidden";
document.getElementById("leftinfo").style.visibility = "hidden";
document.getElementById("rightinfo").style.visibility = "hidden";

return false;
} /* END FUNCTION makelove */


function maketrivia(whichchoice) {

gamemode = 'slam';

/* fetch game number */
gamenumber = document.getElementById('trivia3').value;

/* delete question (so the answer can't be changed or repeated */
document.getElementById("triviaquestion").innerHTML="";

/* instructions for next step */
/* document.getElementById("triviaanswer").innerHTML="<h1 align=\"center\">Slam or love a celebrity! The choice is "+whichchoice+" and the game is "+gamenumber+"</h1>";*/
document.getElementById("triviaanswer").innerHTML="<h1 align=\"center\">Slam a celebrity!</h1>";

/* show info buttons */
document.getElementById("info1").style.visibility = "visible";
document.getElementById("info2").style.visibility = "visible";

submittrivia(whichchoice,gamenumber);

/* show info boxes */
var windowwidth = window.innerWidth;
var windowheight = window.innerHeight;

if (windowwidth > 965) {

  document.getElementById("leftinfo").style.visibility = "visible";
  document.getElementById("rightinfo").style.visibility = "visible";
  specialmakeinfo1(1,gamenumber);

} /* END IF large window */

} /* END FUNCTION maketrivia */

function makeinfo(whichchoice,gamenumber) {

if (gamemode == 'trivia' ) {

  return 0; /* prevent showing celebrity info during trivia quiz time */

} /* END IF */

infoname = "triviaanswer";

document.getElementById(infoname).innerHTML="<h1 align=\"center\">loading celebrity information</h1>";
document.getElementById(infoname).style.visibility = "visible";

var requestinfourlstring = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/gameserver.php?celebrityinfo="+whichchoice+"&game="+gamenumber;
var requestinfoxmlhttp = new XMLHttpRequest();
requestinfoxmlhttp.onreadystatechange=function()
  {
  if (requestinfoxmlhttp.readyState==4 && requestinfoxmlhttp.status==200)
    {
      document.getElementById(infoname).innerHTML= requestinfoxmlhttp.responseText;
    }
else if (requestinfoxmlhttp.readyState==4) {newstring='code is '+ requestinfoxmlhttp.status; document.getElementById(infoname).innerHTML=newstring;}
  }
requestinfoxmlhttp.open("GET",requestinfourlstring,true);
requestinfoxmlhttp.send();

return false;
} /* END FUNCTION makeinfo */

function specialmakeinfo1(whichchoice,gamenumber) {

if ( whichchoice == 1 ) {

infoname = "leftinfo"

} /* END IF choice 1 */

else {

infoname = "rightinfo"

} /* END ELSE choice 2 */

document.getElementById(infoname).innerHTML="<h1 align=\"center\">loading celebrity information</h1>";
document.getElementById(infoname).style.visibility = "visible";

var requestinfourlstring = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/gameserver.php?celebrityinfo="+whichchoice+"&game="+gamenumber;
var requestinfoxmlhttp = new XMLHttpRequest();
requestinfoxmlhttp.onreadystatechange=function()
  {
  if (requestinfoxmlhttp.readyState==4 && requestinfoxmlhttp.status==200)
    {
      document.getElementById(infoname).innerHTML= requestinfoxmlhttp.responseText;
      specialmakeinfo2(2,gamenumber);
    }
else if (requestinfoxmlhttp.readyState==4) {newstring='code is '+ requestinfoxmlhttp.status; document.getElementById(infoname).innerHTML=newstring;}
  }
requestinfoxmlhttp.open("GET",requestinfourlstring,true);
requestinfoxmlhttp.send();

return false;
} /* END FUNCTION specialmakeinfo1 */

function specialmakeinfo2(whichchoice,gamenumber) {

if ( whichchoice == 1 ) {

infoname = "leftinfo"

} /* END IF choice 1 */

else {

infoname = "rightinfo"

} /* END ELSE choice 2 */

document.getElementById(infoname).innerHTML="<h1 align=\"center\">loading celebrity information</h1>";
document.getElementById(infoname).style.visibility = "visible";

var requestinfourlstring = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/gameserver.php?celebrityinfo="+whichchoice+"&game="+gamenumber;
var requestinfoxmlhttp = new XMLHttpRequest();
requestinfoxmlhttp.onreadystatechange=function()
  {
  if (requestinfoxmlhttp.readyState==4 && requestinfoxmlhttp.status==200)
    {
      document.getElementById(infoname).innerHTML= requestinfoxmlhttp.responseText;
    }
else if (requestinfoxmlhttp.readyState==4) {newstring='code is '+ requestinfoxmlhttp.status; document.getElementById(infoname).innerHTML=newstring;}
  }
requestinfoxmlhttp.open("GET",requestinfourlstring,true);
requestinfoxmlhttp.send();

return false;
} /* END FUNCTION specialmakeinfo2 */




function submitround(slamchoice,lovechoice,gamenumber) {

gamemode = 'trivia';

if (slamchoice > 0)
  choicestring = "slam="+slamchoice;
if (lovechoice > 0)
  choicestring = "love="+lovechoice;

slamchoice= 0;
lovechoice= 0;

document.getElementById("targetarea").innerHTML="<p align=\"center\">loading next round</p>"; 

var submitroundurlstring = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/gameserver.php?"+choicestring+"&game="+gamenumber;
var submitroundxmlhttp = new XMLHttpRequest();
submitroundxmlhttp.onreadystatechange=function()
  {
  if (submitroundxmlhttp.readyState==4 && submitroundxmlhttp.status==200)
    {
      document.getElementById("targetarea").innerHTML=submitroundxmlhttp.responseText;
    }
else if (submitroundxmlhttp.readyState==4) {newstring='code is '+submitroundxmlhttp.status; document.getElementById("targetarea").innerHTML=newstring;}
  }
submitroundxmlhttp.open("GET",submitroundurlstring,true);
submitroundxmlhttp.send();

return false;
} /* END FUNCTION submitround */


function submittrivia(whichchoice,gamenumber) {

var submittriviaurlstring = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/gameserver.php?trivia="+whichchoice+"&game="+gamenumber;
var submittriviaxmlhttp = new XMLHttpRequest();
submittriviaxmlhttp.onreadystatechange=function()
  {
  if (submittriviaxmlhttp.readyState==4 && submittriviaxmlhttp.status==200)
    {
      document.getElementById("triviaanswer").innerHTML= submittriviaxmlhttp.responseText;
    }
else if (submittriviaxmlhttp.readyState==4) {newstring='code is '+ submittriviaxmlhttp.status; document.getElementById("targetarea").innerHTML=newstring;}
  }
submittriviaxmlhttp.open("GET",submittriviaurlstring,true);
submittriviaxmlhttp.send();

return false;
} /* END FUNCTION submittrivia */





function incrementvote(celebritynumber) {
var urlstring = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/addvote.php?celebrity="+celebritynumber;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById('celeb'+celebritynumber).innerHTML=xmlhttp.responseText;
    //document.getElementById("targetarea").innerHTML=xmlhttp.responseText;
    }
else if (xmlhttp.readyState==4) {newstring='code is '+xmlhttp.status; document.getElementById("targetarea").innerHTML=newstring;}
  }
xmlhttp.open("GET",urlstring,true);
xmlhttp.send();
  //document.getElementById("targetarea").innerHTML=celebritynumber;
  //document.getElementById("targetarea").innerHTML=urlstring;
return false;
} /* END FUNCTION incrementvote */



function runslotmachine() {

spincounter = 200 + 160;
//document.getElementById("threebutton").style.visibility = "hidden";
document.getElementById("navigation").innerHTML = "";
document.getElementById("results").innerHTML='<h1 align="center" style="color:green;">playing</h1>';
document.getElementById("results").style.visibility = "visible";

} /* END FUNCTION runslotmachine */

function stopslotmachine() {

//document.getElementById("a").style.setProperty("-webkit-transition", "background-position .7s");
//document.getElementById("a").style['webkit-transition'] =  'background-position .7s';
//document.getElementById("a").style.webkit-transition = 'background-position .7s';

document.getElementById("a").style.webkitAnimation =  'none';
document.getElementById("a").style.backgroundPosition =  '0, 0 840px';
document.getElementById("a").style.webkitTransition =  'background-position .7s';

document.getElementById("b").style.webkitAnimation =  'none';
document.getElementById("b").style.backgroundPosition =  '0, 0 840px';
document.getElementById("b").style.webkitTransition =  'background-position 1.2s';

document.getElementById("c").style.webkitAnimation =  'none';
document.getElementById("c").style.backgroundPosition =  '0, 0 840px';
document.getElementById("c").style.webkitTransition =  'background-position 1.6s';



//document.getElementById("results").style.visibility = "visible";


} /* END FUNCTION stopslotmachine */

function showresults() {

document.getElementById("results").style.visibility = "visible";
document.getElementById("results").innerHTML='<h1 align="center">'+ resultstring + '</h1>';
document.getElementById("credits").innerHTML='<h1 align="center">'+ creditstring + '</h1>';

} /* END FUNCTION stopslotmachine */

function slotspin() {

runslotmachine();

return false;
} /* END FUNCTION slotspin */

function redbuttonaction() {

if (gamemode == 'trivia' ) {

  return 0; /* prevent wiping out trivia question */

} /* END IF */

//document.getElementById("triviaanswer").innerHTML='<h1 align="center" style="color:red;">Red</h1>';

return false;
} /* END FUNCTION redbuttonaction */

function greenbuttonaction() {

if (gamemode == 'trivia' ) {

  return 0; /* prevent wiping out trivia question */

} /* END IF */

//document.getElementById("triviaanswer").innerHTML='<h1 align="center" style="color:green;">Green</h1>';

return false;
} /* END FUNCTION greenbuttonaction */

/* GLOBALS (property of window object) */
<!-- this javascript snippet draws the temptation box -->
var temptationdelaytime = 6000; /* 6 second delay */
var intervalhandle;

var temptingswitch = false;

var hourcounter = 0;
var minutecounter = 0;
var secondcounter = 0;
var tenthsecondcounter = 0;
var hundredthsecondcounter = 0;

function checktimedispatcher() {

/* TIMER COUNT DOWN AFTER A SPIN */
if ( spincounter > 0 ) {

  spincounter = spincounter - 1 ; /* decrement */
  if ( spincounter == 200 ) {
    stopslotmachine();
  } /* END IF */
  if ( spincounter <= 0 ) {
    showresults();
  } /* END IF */

} /* END IF */

/* TIMER COUNT DOWN AFTER A SLAM */
if ( slamcounter > 0 ) {

  slamcounter = slamcounter - 1 ; /* decrement */
  if ( slamcounter <= 0 ) {
    submitround(slamchoice,lovechoice,mastergamenumber);
  } /* END IF */

} /* END IF */

/* CHECK FOR TRIVIA */
if (document.getElementById('trivia1').checked) {
  maketrivia(1);
} /* END IF */
else if (document.getElementById('trivia2').checked) {
  maketrivia(2);
} /* END IF */

//document.getElementById("slamcounterelement").innerHTML= slamcounter; /* DEBUG */

var currentdate=new Date();
var currenttime= currentdate.toLocaleTimeString();
/*document.getElementById("timerelement").innerHTML= currenttime;*/

/* knocked out so that we look better - restore for debugging */
/* hundredthsecondcounter = hundredthsecondcounter +1;
document.getElementById("hundredthelement").innerHTML= hundredthsecondcounter;
if ( (hundredthsecondcounter%10) == 0 ) {
  tenthsecondcounter = tenthsecondcounter +1;
  document.getElementById("tenthelement").innerHTML= tenthsecondcounter;
  if ( (tenthsecondcounter%10) == 0) {
    secondcounter = secondcounter + 1;
    document.getElementById("secondelement").innerHTML= secondcounter;
    if ( (secondcounter%60) == 0) {
      minutecounter = minutecounter + 1;
      document.getElementById("minuteelement").innerHTML= minutecounter;
      if ( (minutecounter%60) == 0) {
        hourcounter = hourcounter + 1;
        document.getElementById("hourelement").innerHTML= hourcounter;
      } /* END hour check */
/*    } /* END minute check */
/*  } /* END second check */
/*} /* END tenth second check */

} /* END FUNCTION checktimedispatcher */

function celebrityswitcher() {

if (temptingswitch == false) { return false; } /* stop if the user wants to do something with current data */

var urlstringcelebrityswitch = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/newcelebrity.php";
var xmlhttpcelebrityswitch = new XMLHttpRequest();
xmlhttpcelebrityswitch.onreadystatechange=function()
  {
  if (xmlhttpcelebrityswitch.readyState==4 && xmlhttpcelebrityswitch.status==200)
    {
    document.getElementById("gamecontent").innerHTML=xmlhttpcelebrityswitch.responseText;
    }
else if (xmlhttpcelebrityswitch.readyState==4) {newstringcelebrityswitch='code is '+xmlhttpcelebrityswitch.status; document.getElementById("targetarea").innerHTML=newstringcelebrityswitch;}
  }
xmlhttpcelebrityswitch.open("GET",urlstringcelebrityswitch,true);
xmlhttpcelebrityswitch.send();

} /* END FUNCTION celebrityswitcher */

var angle = 0;

function divspin() {

    angle = angle + 3600;

    var spin10 = "rotate(" + angle + "deg)";

    document.getElementById("gamecontent").style.webkitTransform = spin10;

} /* END FUNCTION divspin */

function redbuttonaction() {

if (gamemode == 'trivia' ) {

  return 0; /* prevent wiping out trivia question */

} /* END IF */

document.getElementById("triviaanswer").innerHTML='<h1 align="center" style="color:red;">Red</h1>';

return false;
} /* END FUNCTION redbuttonaction */

function greenbuttonaction() {

if (gamemode == 'trivia' ) {

  return 0; /* prevent wiping out trivia question */

} /* END IF */

document.getElementById("triviaanswer").innerHTML='<h1 align="center" style="color:green;">Green</h1>';

return false;
} /* END FUNCTION greenbuttonaction */


/*!--on window load init--*/


//-->
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>

<!--main HTML-->
<body text="#ffffff" bgcolor="#000000" onload="intervalhandle=window.setInterval(function() {checktimedispatcher() },10);">

<?php //ErrorReporting(); ?>
<?php SQLReporting(); ?>
    
<!--h1 align="center" style="width:320px;background-color:black;margin-left:auto; margin-right:auto;text-align:center;font-family:Geneva,sanserif;font-size:48px"><span style="color:red">Slam</span><span style="color:yellow">Z</span><span style="color:green">ee</span></h1-->

<?php

if ($accountemail == '') /* NOT SIGNED IN */
  {

    echo '<h1 align="center">you must be logged in to play!<br>or sign up for free!</h1>';
    DisplayLoginForm(); /* default to showing a login form */
//echo '<br>the account sting is *'.$accountemail .'*<br>'; /* DEBUG */
    DisplayRegistrationForm();

    exit;

  } /* END IF not signed in */

?>

<div id="mainpage">

<div style="position:relative;float:left;visibility:hidden;background-color:cyan;color:black;width:320px;font-family:Arial, Geneva, Helvetica, serif;border-radius:18px;margin-left:auto;margin-right:auto;padding:1px 8px 1px 8px;" id="leftinfo"></div>

<div style="position:relative;float:right;visibility:hidden;background-color:yellow;color:black;width:320px;font-family:Arial, Geneva, Helvetica, serif;border-radius:18px;margin-left:auto;margin-right:auto;padding:1px 8px 1px 8px;" id="rightinfo"></div>

<div id="gamecontent">

<?php

if ( ( $_GET['action'] == 'logout' ) )
echo '<div id="headerbox" style="position:relative;margin-left:auto; margin-right:auto;text-align:center;width:320px"><img src="./testpict/mainheader.png" width="320" height="58" border="0"><img src="./testpict/mainheaderlogin.png" width="320" height="58" style="position:absolute;z-index:20;top:0;left:0;" id="loggedoutheader"></div>';
elseif ( ($accountemail != '') OR ( $_GET['action'] == 'createaccount' ) OR ( $_GET['action'] == 'login' ) )
echo '<div id="headerbox" style="position:relative;margin-left:auto; margin-right:auto;text-align:center;width:320px"><img src="./testpict/mainheader.png" width="320" height="58" border="0"><img src="./testpict/mainheaderlogin.png" width="320" height="58" style="position:absolute;z-index:20;top:0;left:0;visibility:hidden;" id="loggedoutheader"></div>';
else
echo '<div id="headerbox" style="position:relative;margin-left:auto; margin-right:auto;text-align:center;width:320px"><img src="./testpict/mainheader.png" width="320" height="58" border="0"><img src="./testpict/mainheaderlogin.png" width="320" height="58" style="position:absolute;z-index:20;top:0;left:0;" id="loggedoutheader"></div>';

//echo '<br>action code is *'.$_GET['action'].'*<br>';

/* check to see if an incoming new registration form and process as needed */

if ( $_GET['action'] == 'logout' )
  {
    require_once('./php/logout.php');
    echo '<div id="loginarea">';
    ProcessLogOut();
    $accountemail = CheckValidUser(); /* update this for later check */ /* located in accounts.php */
//echo '<br>the account sting is *'.$accountemail .'*<br>'; /* DEBUG */
    echo '<p align="center">please play again soon!</p>';
    echo '</div><!--loginarea-->';
    DisplayLoginForm(); /* and show the login form */
  }
elseif ($accountemail != '')
  {
    echo '<div id="loginarea">';
    echo '<p align="center">currently logged in as ',GetAccountNameFromAccountNumber(GetAccountNumberFromEmail($accountemail)),'<br>';
//echo '<br>the account sting is *'.$accountemail .'*<br>'; /* DEBUG */
    echo '<a href="./index.php?action=logout">logout</a></p>';
    echo '<h3 align="center" id="topstartgamearea"><a href="javascript:void(0);" onclick="startgame();" style="cursor:pointer;"><span style="color:white">start play now!</span></a></h3>';
    echo '</div><!--loginarea-->';
  }
elseif ( $_GET['action'] == 'createaccount' )
  {
    echo '<div id="loginarea">';
    ProcessRegistrationForm();
    $accountemail = CheckValidUser(); /* update this for later check */ /* located in accounts.php */
//echo '<br>the account sting is *'.$accountemail .'*<br>'; /* DEBUG */
    echo '<p align="center"><a href="./index.php?action=logout">logout</a></p>';
    echo '<h3 align="center"><a href="javascript:void(0);" onclick="startgame();" style="cursor:pointer;"><span style="color:white">start play now!</span></a></h3>';
    echo '</div><!--loginarea-->';
  }
elseif ( $_GET['action'] == 'login' )
  {
    echo '<div id="loginarea">';
    ProcessLoginForm();
    $accountemail = CheckValidUser(); /* update this for later check */ /* located in accounts.php */
//echo '<br>the account sting is *'.$accountemail .'*<br>'; /* DEBUG */
    echo '<p align="center"><a href="./index.php?action=logout">logout</a></p>';
    echo '<h3 align="center"><a href="javascript:void(0);" onclick="startgame();" style="cursor:pointer;"><span style="color:white">start play now!</span></a></h3>';
    echo '</div><!--loginarea-->';
  }
else
  {

/* DEBUG */ /* TEMPORARY DISABLE */

    //DisplayLoginForm(); /* default to showing a login form */
//echo '<br>the account sting is *'.$accountemail .'*<br>'; /* DEBUG */
    //echo '<p align="center">login to play now!<br>or sign up for free!</p>';
  }

?>

    <div id="machine">
        <div id="a"></div>
        <div id="b"></div>
        <div id="c"></div>
    </div>
    <div id="navigation" style="display:block; text-align:center;">
        <?php DisplaySpinner(); ?>
    </div>

<div id="results" style="visibility:hidden;"></div>
<div id="credits"><h1 align="center">Tokens: 2     Credits: 5     Cash: $0.01</h1></div>

</div><!--gamecontent-->

</div><!--mainpage-->

</body>
</html>

return to explanation of source code

show tokens, credits, and money
third pass

    Display the token, credit, and money results.

<div id="moneycolumn">
<?php DisplayMoneyColumn(GetAccountNumberFromEmail($accountemail)); ?>
</div><!--moneycolumn-->

return to explanation of source code

add new game segment for slots
fourth pass

    Add new game segment for slots.

<div id="targetarea">
<h1 align="center">Welcome to Slamzee</h1>
<h2 align="center">Use slams to gain tokens
<br>to play slots and/or trivia.</h2>
<h2 align="center"><a href="javascript:void(0);" onclick="startgame();" style="cursor:pointer;"><span style="color:black">start play now!</span></a></h2>
</div><!--targetarea-->

<p align="center"><img src="./testpict/playforpay.png" width="320" height="131"></p>

</div><!--gamecontent-->
function submitround(slamchoice,lovechoice,gamenumber) {

//gamemode = 'trivia';
gamemode = 'slots'; /* switching mode */

if (slamchoice > 0)
  choicestring = "slam="+slamchoice;
if (lovechoice > 0)
  choicestring = "love="+lovechoice;

slamchoice= 0;
lovechoice= 0;

document.getElementById("targetarea").innerHTML="<p align=\"center\">loading next round</p>"; 

var submitroundurlstring = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/gameserver.php?"+choicestring+"&game="+gamenumber;
var submitroundxmlhttp = new XMLHttpRequest();
submitroundxmlhttp.onreadystatechange=function()
  {
  if (submitroundxmlhttp.readyState==4 && submitroundxmlhttp.status==200)
    {
      document.getElementById("targetarea").innerHTML=submitroundxmlhttp.responseText;
    }
else if (submitroundxmlhttp.readyState==4) {newstring='code is '+submitroundxmlhttp.status; document.getElementById("targetarea").innerHTML=newstring;}
  }
submitroundxmlhttp.open("GET",submitroundurlstring,true);
submitroundxmlhttp.send();

return false;
} /* END FUNCTION submitround */
function showresults() {

document.getElementById("results").style.visibility = "visible";
document.getElementById("results").innerHTML='<p align="center"><a href="javascript:void(0);" onclick="advancetonewround();" style="cursor:pointer;"><span style="color:black">play next round</span></a>';
//document.getElementById("credits").innerHTML='<h1 align="center">'+ creditstring + '</h1>';

var urlstring = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/gameserver.php?slotchoice="+ mastergamenumber;
var slotresultxmlhttp = new XMLHttpRequest();
slotresultxmlhttp.onreadystatechange=function()
  {
  if (slotresultxmlhttp.readyState==4 && slotresultxmlhttp.status==200)
    {
    document.getElementById('moneybox').innerHTML= slotresultxmlhttp.responseText;
    }
else if (slotresultxmlhttp.readyState==4) {newstring='code is '+ slotresultxmlhttp.status; document.getElementById("targetarea").innerHTML=newstring;}
  }
slotresultxmlhttp.open("GET",urlstring,true);
slotresultxmlhttp.send();
return false;


} /* END FUNCTION showresults */
function advancetonewround() {

document.getElementById("targetarea").innerHTML="<p align=\"center\">loading new round</p>";

var urlstring = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/gameserver.php?advanceround="+ mastergamenumber;
var advanceroundxmlhttp = new XMLHttpRequest();
advanceroundxmlhttp.onreadystatechange=function()
  {
  if (advanceroundxmlhttp.readyState==4 && advanceroundxmlhttp.status==200)
    {
    document.getElementById('targetarea').innerHTML= advanceroundxmlhttp.responseText;
    gamemode = 'trivia';
    }
else if (advanceroundxmlhttp.readyState==4) {newstring='code is '+ advanceroundxmlhttp.status; document.getElementById("targetarea").innerHTML=newstring;}
  }
advanceroundxmlhttp.open("GET",urlstring,true);
advanceroundxmlhttp.send();
return false;

} /* END FUNCTION advancetonewround */

return to explanation of source code

picture answer in trivia
fifth pass

    Change the picture so that it also an answer during trivia.

function makepicturechoice(whichchoice,gamenumber) {

if (gamemode == 'trivia' ) {

  maketrivia(whichchoice);

} /* END IF */

else { /* ASSUMING MUST BE gamemode == 'slam' */

  makeinfo(whichchoice,gamenumber);

} /* END ELSE */

return false;
} /* END FUNCTION makepicturechoice */

return to explanation of source code

hide initial slot pictures
sixth pass

    Hide the slot pictures at the start of slot, then reveal on a spin.

    Add to function runslotmachine:

document.getElementById("slota").style.visibility = "hidden";
document.getElementById("slotb").style.visibility = "hidden";
document.getElementById("slotc").style.visibility = "hidden";

return to explanation of source code

hide initial slot pictures
seventh pass

    Shrink the size of the slots to fit in portrait format on smart phones by changing the width of slot divs in the CSS (leaving out unchanged parts).

        #machine { 
            width: 300px; 
            padding:10px; 
        #machine > div { 
            width:90px; 
            margin:5px; 

return to explanation of source code

message for slot winnings
eighth pass

    Remove message for next round from slots (will come from server).

document.getElementById("results").style.visibility = "hidden";
document.getElementById("results").innerHTML='';

return to explanation of source code

change slots timer
ninth pass

    Change the slots animation timer to get a JavaScript time and add two seconds. On older iPhones the two second animation is running more than 20 seconds because the counter approach is not running often enough.

    Add global variables. They will contain zero when not in use and will contain the time out time when non-zero.

var slotstime = 0;
var slotresultstime = 0;

    Change checktimedispatcher to react correctly to the new global slots timer variables.

var dateitem = new Date();
var timeitem = dateitem.getTime();

/* TIMER COUNT DOWN AFTER START SPIN */
if ( slotstime > 0 ) {

  if ( timeitem >= slotstime ) {
    stopslotmachine();
  } /* END IF */

} /* END IF */

/* TIMER COUNT DOWN AFTER END SPIN ANIMATION */
if ( slotresultstime > 0 ) {

  if ( timeitem >= slotresultstime ) {
    showresults();
  } /* END IF */

} /* END IF */

    Modify runslotmachine so that it sets the slots timer up. Add two seconds (2,000 milliseconds to current time).

//spincounter = 200 + 160; /* comment out old timer */

var dateitem = new Date();
var timeitem = dateitem.getTime();

slotstime = timeitem + 2000; /* add 2,000 milliseconds */

    Modify stopslotmachine so that it clears the slots timer up and starts the slots results timer.

slotstime = 0; /* clear the slots timer */
var dateitem = new Date();
var timeitem = dateitem.getTime();
slotresultstime = timeitem + 2000; /* add 2,000 milliseconds */

    Modify showresults so that it clears the slots results timer.

slotresultstime = 0; /* clear the slots results timer */

return to explanation of source code


OSdata.com is used in more than 300 colleges and universities around the world

Find out how to get similar high web traffic and search engine placement.


OSdata.com is used in more than 300 colleges and universities around the world

Read details here.


    A web site on dozens of operating systems simply can’t be maintained by one person. This is a cooperative effort. If you spot an error in fact, grammar, syntax, or spelling, or a broken link, or have additional information, commentary, or constructive criticism, please e-mail Milo. If you have any extra copies of docs, manuals, or other materials that can assist in accuracy and completeness, please send them to Milo, PO Box 1361, Tustin, CA, USA, 92781.

    Click here for our privacy policy.


previous page next page
previous page next page

home page


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2013, 2014 Milo

    Last Updated:January 12, 2014

    Created: November 18, 2013

previous page next page
previous page next page