I am working on a Javascript slot machine for a school project and i require some assistance. What i am having trouble with is getting a “spinning”/random effect on the slots. Below i will put my source code. I assume the spinning effect would probably go in the [B]spin()
Here is my source:
<html>
<head>
<title>Super Slots</title>
<script>
/*
slotpix=new Array
slotpix[1]=”moneybag.gif”
slotpix[2]=”cherry.gif”
slotpix[3]=”lemon.gif”
slotpix[4]=”pi.gif”
slotpix[5]=”turkey.gif”
slotpix[6]=”goldbar.gif”
slotpix[7]=”pyramid.gif”
slotname=new Array
slotname[1]=”Moneybags”
slotname[2]=”Cherries”
slotname[3]=”Lemons”
slotname[4]=”Pi”
slotname[5]=”Turkeys”
slotname[6]=”Gold Bars”
slotname[7]=”Pyramids”
function betcheck()
{
playagainvar=null
money=Number(document.slots.money1.value)
bet=document.slots.bet.value
bet=Number(Math.round(bet))
document.slots.bet.value=bet
if(Number(bet))
{
if(bet>money)
{
alert(“You bet “+bet+’n’+”You do not have that much cash!”)
document.slots.bet.value=””
}
else if(bet<0)
{
alert(“You cannot bet negative number!”)
document.slots.bet.value=””
}
else
{
money=money-bet
document.slots.money1.value=money
document.slots.money.value=money
spin()
}
}
else
{
alert(“Please enter a valid bet!”)
document.slots.bet.value=””
focus(document.slots.bet)
}
}
function spin()
{
document.slots.slot1.value=null
document.slots.slot2.value=null
document.slots.slot3.value=null
num1=Number(Math.random()*(7-1)+1)
num1=num1.toFixed(0)
document.slots.slot1.value=num1
document.slots.slotpic1.src=slotpix[num1]
num2=Number(Math.random()*(7-1)+1)
num2=num2.toFixed(0)
document.slots.slot2.value=num2
document.slots.slotpic2.src=slotpix[num2]
num3=Number(Math.random()*(7-1)+1)
num3=num3.toFixed(0)
document.slots.slot3.value=num3
document.slots.slotpic3.src=slotpix[num3]
matchcheck()
}
function matchcheck()
{
if(num1==num2&&num1==num3)
{
if(num1==4 && num2==4 && num3==4)
{
document.slots.message.value=”You hit the Jackpot!! 3 PI”
money=Number(money)+Number((10*bet))
document.slots.money1.value=money
document.slots.money.value=money
}
else
{
document.slots.message.value=”You win!! You have three “+slotname[num1]
money=Number(money)+Number((3*bet))
document.slots.money1.value=money
document.slots.money.value=money
}
}
else if(num1==num2||num1==num3||num2==num3)
{
document.slots.message.value=”You have a pair!!”
money=Number(money)+Number((2*bet))
document.slots.money1.value=money
document.slots.money.value=money
}
else
{
document.slots.message.value=”You lose!!”
}
document.slots.bet.value=””
brokecheck()
}
function brokecheck()
{
if(money==0)
{
alert(“You are broke!”)
playagain()
}
}
function playagain()
{
playagainvar=confirm(“Would you like to play again?”)
if(!playagainvar)
{
alert(“Thanks for playing!”)
}
else
{
document.slots.money.value=100
document.slots.money1.value=100
}
}
function fixbank()
{
document.slots.money1.value=100
}
function about()
{
alert(“SuperSlots v 0.7″+’n’+”Class ICS3M1″+’n’+”Hearst High School”+’n’+”May 2006”)
}
</script>
<style type=”text/css”>
input.btn
{
color:#FFFF99;
font-family:”Times New Roman”, Times, serif;
font-size:100%;
font-weight:bold;
width=400;
height=50;
cursor:hand;
background-color: #0000FF;
border-top: thin ridge #FF9900;
border-right: thin ridge #FF9900;
border-bottom: medium ridge #FF9900;
border-left: medium ridge #FF9900;
}
</style>
</head>
<body>
<h1 align=”center”><marquee behavior=”alternate” scrollamount=”15″ width=”300″><img src=”dmsinterface_slot.jpg” width=”34.9px” height=”45.7px”><font color=”#000000″ face=”Arial, Helvetica, sans-serif”>Super Slots</font><img src=”dmsinterface_slot.jpg” width=”34.9px” height=”45.7px”></marquee></h1>
<p align=”center”><small><strong><font color=”#FF0000″>Beta</font></strong></small></p>
<hr color=”#000000″>
<form name=”slots”>
<table align=”center” border=”2″ bordercolor=”#000099″><tr><td>
<table align=”center”>
<tr>
<td><p align=”center”><font style=”font-size:18px”>$Money$ :</font><input type=”text” name=”money” value=”100″ readonly size=”2″></p></td>
</tr>
<tr>
<td><p><input type=”text” name=”message” readonly size=”50″></p></td>
</tr>
</table>
<table border=”5″ bordercolor=”#0000FF” align=”center”>
<tr>
<td><img src=”moneybag.gif” name=”slotpic1″></td>
<td><img src=”moneybag.gif” name=”slotpic2″></td>
<td><img src=”moneybag.gif” name=”slotpic3″></td>
</tr>
</table>
<br>
<table align=”center”>
<tr>
<td><p>Bet $:<input type=”text” name=”bet” size=”5″></p></td>
</tr>
</table>
<br>
<p align=”center”>
<input name=”button” type=”button” onClick=”betcheck()” value=”Spin!” class=”btn”>
<br>
<br>
<input type=”reset” value=”New Game” onclick=”fixbank()”>
</p>
<p align=”right”><input type=”button” value=”About” onclick=”about()”></p>
<input type=”hidden” name=”slot1″ readonly>
<input type=”hidden” name=”slot2″ readonly>
<input type=”hidden” name=”slot3″ readonly>
<input type=”hidden” name=”money1″ value=”100″>
</td></tr></table>
</form>
</body>
</html>
Thanx……