slot machine

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 14796 Views - Last Post: 07 January 2014 - 05:30 PM

#1 tezza  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-January 09

slot machine

Post icon  Posted 19 January 2009 - 05:52 AM

hey guys, new here but been reading up on a few things and you all seem like a knowledgeable bunch.

my question begins here. Ive been searching for a javascript code to make a small game for my site. It consists of a slot machine with a variety of rewards.

ive found a code which ive altered slightly however i cannot work out how to edit certain parts. For example here is the code

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Slot Machine</TITLE>
<TBODY>
<TR>
	<TD align=middle width="99%"><FORM name=slots onsubmit="rollem(); return false;">
	  <TABLE cellSpacing=1 cellPadding=3 width=300 border=0>
		<TBODY>
		<TR>
		  <TH colSpan=2>Welcome to the Slot Machine! </TH></TR>
		<TR>
		  <TH align=right>Gold: </TH>
		  <TD align=left><INPUT readOnly type=box size=5 value=10 
		name=gold></TD></TR>
		<TR>
		  <TH align=right>Your bet: </TH>
		  <TD align=left><INPUT type=box size=5 name=bet></TD></TR>
		<TR>
		  <TH><INPUT type=submit value="Spin the slots"></TH>
		  <TH><INPUT onclick=stopplay(); type=button value="I am done for now"></TH></TR>
		<TR>
		  <TH colSpan=2>&nbsp; </TH>
		</TR>
		<TR>
		  <TD colSpan=2>
			<HR>
		  </TD></TR>
		<TR>
		  <TD colSpan=2>
			<CENTER>
			<TABLE cellSpacing=5 cellPadding=2 border=0>
			  <TBODY>
			  <TR>
				<TD><IMG 
				  src="../Slot Machine/1.gif" 
				  name=slot1></TD>
				<TD><IMG 
				  src="../Slot Machine/2.gif" 
				  name=slot2></TD>
				<TD><IMG 
				  src="../Slot Machine/3.gif" 
				  name=slot3></TD></TR></TBODY></TABLE><INPUT readOnly size=33 
			name=banner> </CENTER></TD></TR>
		<TR>
		  <TD colSpan=2>
			<HR>
		  </TD></TR>
		<TR>
		  <TD colSpan=2>
			<CENTER>
			<TABLE width="100%" border=0>
			  <TBODY>
			  <TR>
				<TH colSpan=3><FONT size=+1>Payouts</FONT></TH></TR>
			  <TR>
				<TH>3 of a kind </TH>
				<TD><IMG 
				  src="1.gif" width="32" height="32"> 
				  <IMG 
				  src="1.gif" width="32" height="32"> 
				  <IMG 
				  src="1.gif" width="32" height="32"> 
				</TD>
				<TH>10x your bet </TH></TR>
			  <TR>
				<TH>A pair </TH>
				<TD><IMG 
				  src="2.gif" width="32" height="32"> 
				  <IMG 
				  src="2.gif" width="32" height="32"> 
				  <IMG 
				  src="3.gif" width="32" height="32"> 
				</TD>
				<TH>2x your bet </TH></TR>
			  <TR>
				<TH>or </TH>
				<TD><IMG 
				  src="0.gif" width="32" height="32"> 
				  <IMG 
				  src="4.gif" width="32" height="32"> 
				  <IMG 
				  src="4.gif" width="32" height="32"> 
				</TD>
				<TH>2x your bet </TH></TR>
			  <TR>
				<TH>or </TH>
				<TD><IMG 
				  src="5.gif" width="32" height="32"> 
				  <IMG 
				  src="6.gif" width="32" height="32"> 
				  <IMG 
				  src="5.gif" width="32" height="32"> 
				</TD>
				<TH>2x your bet </TH></TR>
			  <TR>
				<TH>No match </TH>
				<TD><IMG 
				  src="7.gif" width="32" height="32"> 
				  <IMG 
				  src="8.gif" width="32" height="32"> 
				  <IMG 
				  src="9.gif" width="32" height="32"> 
				</TD>
				<TH>You lose </TH></TR></TBODY></TABLE></CENTER></TD></TR></TBODY></TABLE>
	  <CENTER></CENTER></FORM>
	  <script>


slotitem = new Array('0','1','2','3','4','5','6','7','8','9');
document.slots.bet.focus();

startgold=10;
document.slots.gold.value=startgold;

function stopplay () {
if (document.slots.gold.value < startgold) 
	{alert("You lost "+ (startgold-document.slots.gold.value) +" gold pieces.   ");}
else 	{alert("You gained "+ (document.slots.gold.value-startgold) +" gold pieces.   ");}
}

function rollem () {
if (document.slots.bet.value<1 || document.slots.bet.value == "") {alert("You cannot bet less that 1.   "); return;}
if (Math.floor(document.slots.gold.value) < Math.floor(document.slots.bet.value)) {alert("Your bet "+document.slots.bet.value+" is larger than your remaining gold "+document.slots.gold.value+".  "); return;}
if (document.slots.bet.value>1) {document.slots.banner.value="Bet is "+document.slots.bet.value+" gold pieces";}
else {document.slots.banner.value="Bet is "+document.slots.bet.value+" gold piece";}
counter=0;
spinem();
}


function spinem() {
turns1=10+Math.floor((Math.random() * 10))
for (a=0;a<turns1;a++)
	{document.slots.slot1.src=""+slotitem[a % 9]+".gif"; }
turns2=10+Math.floor((Math.random() * 10))
for (b=0;b<turns2;b++)
	{document.slots.slot2.src=""+slotitem[b % 9]+".gif"; }
turns3=10+Math.floor((Math.random() * 10))
for (c=0;c<turns3;c++)
	{document.slots.slot3.src=""+slotitem[c % 9]+".gif"; }
counter++;
if (counter<25) {setTimeout("spinem(counter);",50);} else {checkmatch();}
}


function checkmatch()	{ 
if ((document.slots.slot1.src == document.slots.slot2.src) && (document.slots.slot1.src == document.slots.slot3.src)) 
	{document.slots.banner.value="3 of a kind - You won "+Math.floor(document.slots.bet.value*10)+" gold pieces";
	 document.slots.gold.value=Math.floor(document.slots.gold.value)+Math.floor(document.slots.bet.value*10); }
else if ((document.slots.slot1.src == document.slots.slot2.src) ||
	(document.slots.slot1.src == document.slots.slot3.src) ||
	(document.slots.slot2.src == document.slots.slot3.src))
		{document.slots.banner.value="A pair - You won "+Math.floor(document.slots.bet.value*2)+" gold pieces";
		 document.slots.gold.value = Math.floor(document.slots.bet.value*2) + Math.floor(document.slots.gold.value);}
else {document.slots.gold.value=document.slots.gold.value-document.slots.bet.value; 
		document.slots.banner.value="No match - You lost "+document.slots.bet.value+" gold pieces";}
	}
</SCRIPT>

	  <P>
	  <P><A name=source>
	  <TABLE cellSpacing=0 cellPadding=3 width=486 border=0>
	  <TBODY><TR>
		<TD align=middle bgColor=yellow>		
 



my question is, how can i change the results. as currently it works as if its 2 of a kind so if slot 1 = slot 3 then you get a multiple of 10 etc. i ideally want it so that it can be if a certain picture in slot 1 is the same as slot 2 then you get the multple of 10. is this possible? and how? ive tried altering code, which ended up not working at all.

thanks for the help, and apologies for such a long winded newbie thread.

This post has been edited by tezza: 19 January 2009 - 06:03 AM


Is This A Good Question/Topic? 0
  • +

Replies To: slot machine

#2 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 125
  • View blog
  • Posts: 818
  • Joined: 25-October 08

Re: slot machine

Posted 19 January 2009 - 07:06 AM

You need to define the type of <script>
as in <script type="text/javascript">

Also, your code is out of order.
1. The <table></table> tags are not matched
2. The JS is in the middle of the HTML. Should be between <head> tags
3. Would be alot easier to help debug if you include a link to the images.
4. There are some validation errors. Are you using an error console?
Was This Post Helpful? 0
  • +
  • -

#3 tezza  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-January 09

Re: slot machine

Posted 19 January 2009 - 07:26 AM

thanks i will upload it all now.

The basic design of the slot machine:

http://kentmodified....slotmachine.htm

the results i require:

http://kentmodified....ine/results.htm

hope this helps.
Was This Post Helpful? 0
  • +
  • -

#4 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 125
  • View blog
  • Posts: 818
  • Joined: 25-October 08

Re: slot machine

Posted 19 January 2009 - 09:25 PM

Concerning the logic of your results.htm file
Is this what you want for point system? Which is the correct point system for the (-1 or 2|4|6) results?

? ? ? Remove all points
0 0 1 Lose
0 1 0 Lose
0 e|t|r e|t|r -1 or 2|4|6
1 0 0 Lose
etr 0 e|t|r -1 or 2|4|6
etr e|t|r 0 -1 or 2|4|6
etr e|t|r e|t|r 10|20|40

? = Mystery
0 = Any (?|e|t|r)
e = Emin
t = Turner
r = Rossetti
Was This Post Helpful? 0
  • +
  • -

#5 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 125
  • View blog
  • Posts: 818
  • Joined: 25-October 08

Re: slot machine

Posted 20 January 2009 - 08:39 PM

Here's a simplified version of your script.
It needs to have the logic for your 'Emin', 'Turner' and 'Rosetti' added but I have left room for that.

It is not as colorful, but you can add that feature as well.

Hopefully you can see the logic of the program and continue to modify to your needs from there. I find it easier to modify what I understand than to try to guess at the changes to some script that is somewhat confusing.

Modify from here if you want:
<html>
<head>
<title>Slot Machine</title>
<script type="text/javascript">
// From: http://www.dreamincode.net/forums/index.php?showtopic=81624&st=0&#entry516385

var ImageList = ('0123');	
// '3' is the "Mystery (?)" image
// '0', '1', '2' represent "Emin", "Turner" and "Rossetti" 
// (just a guess -- cannot tell from images provided)

function PullArm() {
  var WinLose = document.getElementById('bet').value * 1;
  if (WinLose == 0) { alert('Need to place a bet'); return; }
 
  var cntr = 5;
  do {
	var p1 = Math.floor(Math.random()*ImageList.length);
	document.getElementById('sp1').src = ImageList.charAt(p1)+'.gif';
	document.getElementById('sp1').alt = ImageList.charAt(p1)+'.gif';
	var p2 = Math.floor(Math.random()*ImageList.length);
	document.getElementById('sp2').src = ImageList.charAt(p2)+'.gif';
	document.getElementById('sp2').alt = ImageList.charAt(p2)+'.gif';
	var p3 = Math.floor(Math.random()*ImageList.length);
	document.getElementById('sp3').src = ImageList.charAt(p3)+'.gif';
	document.getElementById('sp3').alt = ImageList.charAt(p3)+'.gif';
	cntr--;
  } while (cntr > 0);  // un-necessary loop to delay displays
  
  scr = document.getElementById('score').value * 1;
  var msg = 'Lose';
  if (p1 == '3') { msg = "Penalty: 1 token"; }
  if (p2 == '3') { msg = "Penalty: 1 token"; }
  if (p3 == '3') { msg = "Penalty: 1 token"; }
  if ((p1 == p2) || (p1 == p3) || (p2 == p3)) { msg = 'Pair'; }   		// pair
  if ((p1 == p2) && (p1 == p3) && (p2 == p3)) { msg = '3 of a kind'; } 	// total match
  if ((p1 == '3') && (p2 == '3')) { msg = "Penalty: 5 tokens"; }
  if ((p2 == '3') && (p3 == '3')) { msg = "Penalty: 5 tokens"; }
  if ((p1 == '3') && (p3 == '3')) { msg = "Penalty: 5 tokens"; }
  if ((p1 =='3') && (p2 =='3') && (p3 =='3')) { msg = 'Bad news - Lose all'; }
  
// Add appropriate logic for 'Emin', 'Turner' and 'Rosetti' above and below
  
  switch (msg) {
	case '3 of a kind' : WinLose *= 5;  break;
	case "Pair" : WinLose *= 2;  break;
	case "Bad news - Lose all" :  scr = 0;  WinLose = 0;  break;
	case "Penalty: 1 token" : WinLose = -1;  break;
	case "Penalty: 5 tokens" : WinLose = -5;  break;
	default : WinLose *= -1;  break;  // default = "Lose"
  }
  scr += WinLose;
  document.getElementById('score').value = scr;
  document.getElementById('sp4').innerHTML = msg;
}

</script>
</head>
<body>
<table width="25%">
<caption><h1>Slot Machine</h1></caption>
<tr>
<th>Bet</th>
<th><button onclick="PullArm()">Play</button></th>
<th>Winnings</th>
</tr>
<tr>
<th><input id="bet" type="text" value='0' size="3"></th>
<th></th>
<th><input id="score" type="text" value='0' size="3"></th>
</tr>
<tr>
<th><img id='sp1' src='0.gif' alt='0.gif' height='50' width='50'></th>
<th><img id='sp2' src='1.gif' alt='1.gif' height='50' width='50'></th>
<th><img id='sp3' src='2.gif' alt='2.gif' height='50' width='50'></th>
</tr>
<tr>
<th colspan="3"><div id='sp4' style="font-size:large"></div></th>
</tr>
</table>
</body>
</html>


Post back if you have questions about what I have started for you.
Good Luck!
:)
Was This Post Helpful? 0
  • +
  • -

#6 DangerousDave  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-May 13

Re: slot machine

Posted 06 May 2013 - 10:45 PM

I am working on that same piece of freeware. but my problem is I want to exspand this to 5 reels. I've tried a few things but I would like to get this to spin 2 more reels. here is a sample of the code.
function spinem() {

turns1=10+Math.floor((Math.random() * 10))

for (a=0;a<turns1;a++)

	{document.slots.slot1.src=""+slotitem[a % 9]+".jpg"; }

turns2=10+Math.floor((Math.random() * 10))

for (b=0;b<turns2;b++)

	{document.slots.slot2.src=""+slotitem[b % 9]+".jpg"; }

turns3=10+Math.floor((Math.random() * 10))

for (c=0;c<turns3;c++)

	{document.slots.slot3.src=""+slotitem[c % 9]+".jpg"; }
	
/*turns4=10+Math.floor((Math.random() * 10))

for (d=0;c<turns4;d++)

	{document.slots.slot4.src=""+slotitem[d % 9]+".jpg"; }
	
turns5=10+Math.floor((Math.random() * 10))

for (e=0;c<turns5;e++)

	{document.slots.slot5.src=""+slotitem[e % 9]+".jpg"; } */

counter++;

if (counter<25) {setTimeout("spinem(counter);",50);} else {checkmatch();}

}


You will notice that I commented out the code I tried last to get to work. but it hangs the script.
any help guys? Thanks in advance new User Dave

This post has been edited by JackOfAllTrades: 07 May 2013 - 03:09 AM
Reason for edit:: Added code tags

Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2885
  • View blog
  • Posts: 9,570
  • Joined: 12-December 12

Re: slot machine

Posted 07 May 2013 - 03:17 AM

for (d=0; c < turns4; d++)

You are increasing d, but testing against c. You do the same for e.

[A mate of mine I call Dangerous Dave. Well, not to his face though!]
Was This Post Helpful? 0
  • +
  • -

#8 DangerousDave  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-May 13

Re: slot machine

Posted 08 May 2013 - 07:53 AM

Thanks you really know your stuff. Glad to know I was so close.
I am now having trouble with the pay outs. I want to add a wild card but I can't figure how. I will post my attempt after some more testing. Thanks again for the tip it worked great after I corrected that error.
U da Man!
Was This Post Helpful? 0
  • +
  • -

#9 DangerousDave  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-May 13

Re: slot machine

Posted 08 May 2013 - 09:43 AM

I'm having trouble with my pay outs. I have wild card images for 0 and 3 but need to figure how to pay the line. some of this code is working and some is not. I could use a little Help.
function checkmatch()	{ 

if (
(document.slots.slot1.src == document.slots.slot2.src) && (document.slots.slot1.src == document.slots.slot3.src)
&& (document.slots.slot1.src == document.slots.slot4.src) && (document.slots.slot1.src == document.slots.slot5.src)
// || (document.slots.slot1.src == 0|3)&&(document.slots.slot2.src == 0|3)&&(document.slots.slot3.src != 0|3) 
// || (document.slots.slot1.src == 0|3)&&(document.slots.slot2.src != 0|3)&&(document.slots.slot3.src = 0|3))
)
 {document.slots.banner.value="5 of a kind - You won "+Math.floor(document.slots.bet.value*100)+" gold pieces";

 document.slots.gold.value=Math.floor(document.slots.gold.value)+Math.floor(document.slots.bet.value*100); }

else if ((document.slots.slot1.src == document.slots.slot2.src) && (document.slots.slot1.src == document.slots.slot3.src)
&& (document.slots.slot1.src == document.slots.slot4.src ) 
)

		{document.slots.banner.value="4 of a kind - You won "+Math.floor(document.slots.bet.value*25)+" gold pieces";

		 document.slots.gold.value = Math.floor(document.slots.bet.value*25) + Math.floor(document.slots.gold.value);}
		 
		
		 
else if ((document.slots.slot1.src ==document.slots.slot2.src) && (document.slots.slot1.src == document.slots.slot3.src) )

	{document.slots.banner.value = "3 of a kind - You Won " +Math.floor(document.slots.bet.value*20) + "gold pieces";
	
	document.slots.gold.value = Math.floor(document.slots.bet.value*20) + Math.floor(document.slots.gold.value);}
	
else if ((document.slots.slot1.src == document.slots.slot2.src) || (document.slots.slot2.src | document.slots.slot1.src == 3|0)
)

		{document.slots.banner.value="A pair - You won "+Math.floor(document.slots.bet.value*5)+" gold pieces";

		 document.slots.gold.value = Math.floor(document.slots.bet.value*5) + Math.floor(document.slots.gold.value);}
		 
else {document.slots.gold.value=document.slots.gold.value-document.slots.bet.value; 

		document.slots.banner.value="No match - You lost "+document.slots.bet.value+" gold pieces";}

	}


I would like to figure out how to make my wild cards pay right. Thanks again in advance. Yall are real good at code.
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2885
  • View blog
  • Posts: 9,570
  • Joined: 12-December 12

Re: slot machine

Posted 08 May 2013 - 10:24 AM

Your code will be a lot easier to read, and more efficient, if you create variables within your function:

var slots = document.slots;
var gold = slots.gold;

Was This Post Helpful? 0
  • +
  • -

#11 DangerousDave  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-May 13

Re: slot machine

Posted 08 May 2013 - 10:42 AM

I am not really sure what you mean. The gold calculates fine. And I'm working with free code, just trying to modify it.
Thanks I'll try to clean it up. But, it's adding a wild card that I really want
Was This Post Helpful? 0
  • +
  • -

#12 DangerousDave  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-May 13

Re: slot machine

Posted 08 May 2013 - 11:17 AM

you can check out my problems here. www.dangerousdavesdesigns.com/4-22-13web/stot2c.html
Was This Post Helpful? 0
  • +
  • -

#13 DangerousDave  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-May 13

Re: slot machine

Posted 13 May 2013 - 12:23 PM

Sorry I posted a broken link. here is the good 1.

http://www.dangerous...web/slot2c.html
Was This Post Helpful? 0
  • +
  • -

#14 DangerousDave  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-May 13

Re: slot machine

Posted 07 January 2014 - 12:46 PM

So I finally got that code working. I have a new project very similar. I have a 5 reel slot machine loaded with images. I just got the wild cards to show in the spin, now I need to create a way to pay on the wild cards. any suggestions would be helpful.All the code is in the source online at DangerousDavesDesigns.com/machine/nflmix.html
Looking forward to your ideas. I have been doing this in Javascript so I am focusing on those solutions first. I am welcome to any other languages.
Was This Post Helpful? 0
  • +
  • -

#15 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2885
  • View blog
  • Posts: 9,570
  • Joined: 12-December 12

Re: slot machine

Posted 07 January 2014 - 01:09 PM

You are more likely to get some assistance if you ask a specific question and post some code relevant to your question. That is what this forum is for (primarily).

This post has been edited by andrewsw: 07 January 2014 - 01:10 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2