Need help making a slot machine

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 16913 Views - Last Post: 10 November 2007 - 10:26 PM Rate Topic: -----

#1 rahil92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-November 07

Need help making a slot machine

Posted 05 November 2007 - 01:41 AM

im havin difficulty with one of the challenges tht my teacher has set for me...he's asked me 2 create a slot machine....n im beginner to visual basic...n hve no idea how to go about it....can you guys plz help me... as in wht controls i shud use..wht myt the code be....
Is This A Good Question/Topic? 0
  • +

Replies To: Need help making a slot machine

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Need help making a slot machine

Posted 05 November 2007 - 05:39 AM

Well, had you read the Forum Rules you'd already know that without some effort on your part, you're not going to get much help. We don't mind helping people, in fact thats what we're here for, but when you come here with no code to show an effort, just asking how to do your assignment, well we draw the line there.

Do some searching, I know you must have a textbook, and I'm pretty sure your professor discussed the items/skills needed at some point in class before assigning this project.
Was This Post Helpful? 0
  • +
  • -

#3 rabbit_slayer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 30-September 07

Re: Need help making a slot machine

Posted 05 November 2007 - 10:59 AM

well, i'm not going to break the rules, but i will give you a hint as to how to create a random number.
Use "rnd" to generate a random value between 1 and 10.

Now go start coding :pirate:
Was This Post Helpful? 0
  • +
  • -

#4 rahil92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-November 07

Re: Need help making a slot machine

Posted 06 November 2007 - 07:59 AM

View Postrabbit_slayer, on 5 Nov, 2007 - 10:59 AM, said:

well, i'm not going to break the rules, but i will give you a hint as to how to create a random number.
Use "rnd" to generate a random value between 1 and 10.

Now go start coding :pirate:


guys...thts wht the prob is....r teacher has not given us ne book 2 start with at the beginning of the sem. n has not taught us nethin bout the randomize function...thts y ive come here for help...i knw it wud be against the rule of the forum 2 help some1 from scratch..but srsly guys i hve no other alternate...either help from scratch...or fail my task...coz i dnt understand a single bit of this subject....im in yr10 studyin in australia..n had 2 tke it as an elective...i wnt be continuin with it in yr11...but 2 pass yr10..i need 2 get a gud mrk for my assignment...plz help guys...im helpless...
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Need help making a slot machine

Posted 06 November 2007 - 08:33 AM

View Postrahil92, on 6 Nov, 2007 - 06:59 AM, said:

guys...thts wht the prob is....r teacher has not given us ne book 2 start with at the beginning of the sem. n has not taught us nethin bout the randomize function...thts y ive come here for help...i knw it wud be against the rule of the forum 2 help some1 from scratch..but srsly guys i hve no other alternate...either help from scratch...or fail my task...coz i dnt understand a single bit of this subject....im in yr10 studyin in australia..n had 2 tke it as an elective...i wnt be continuin with it in yr11...but 2 pass yr10..i need 2 get a gud mrk for my assignment...plz help guys...im helpless...


No offense or anything, but can you please translate that to some form of English please, and stop using the SMS speak :)
Was This Post Helpful? 0
  • +
  • -

#6 rabbit_slayer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 30-September 07

Re: Need help making a slot machine

Posted 06 November 2007 - 11:24 AM

Quote

No offense or anything, but can you please translate that to some form of English please, and stop using the SMS speak


well said psycho...half the words are not understandable, try again rahli :P
Was This Post Helpful? 0
  • +
  • -

#7 rahil92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-November 07

Re: Need help making a slot machine

Posted 06 November 2007 - 02:22 PM

View PostPsychoCoder, on 6 Nov, 2007 - 08:33 AM, said:

View Postrahil92, on 6 Nov, 2007 - 06:59 AM, said:

guys...thts wht the prob is....r teacher has not given us ne book 2 start with at the beginning of the sem. n has not taught us nethin bout the randomize function...thts y ive come here for help...i knw it wud be against the rule of the forum 2 help some1 from scratch..but srsly guys i hve no other alternate...either help from scratch...or fail my task...coz i dnt understand a single bit of this subject....im in yr10 studyin in australia..n had 2 tke it as an elective...i wnt be continuin with it in yr11...but 2 pass yr10..i need 2 get a gud mrk for my assignment...plz help guys...im helpless...


No offense or anything, but can you please translate that to some form of English please, and stop using the SMS speak :)

This post has been edited by rahil92: 07 November 2007 - 01:18 AM

Was This Post Helpful? 0
  • +
  • -

#8 rahil92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-November 07

Re: Need help making a slot machine

Posted 07 November 2007 - 01:18 AM

guys...thats what the problem is....our teacher has not given us any book to start with at the beginning of the semester and has not taught us anythin about the randomize function...thats why i have come here for help...i know it would be against the rule of the forum to help someone from scratch..but serioussly guys i have no other alternate...either help from scratch...or fail my task...because i dont understand a single bit of this subject....im in yr10 studying in australia..and n had 2 take it software development and design course an elective...i wont be continuing with it in yr11...but to pass yr10..i need to get a gud mark for my assignment...please help guys...im helpless...
Was This Post Helpful? 0
  • +
  • -

#9 rabbit_slayer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 30-September 07

Re: Need help making a slot machine

Posted 07 November 2007 - 02:17 AM

dude, i'm oly going to say 1 thing: "Rnd"
put it anywhere, it will give u value between 1 and 10.
for example
Private Sub Command1_Click()
	label1.caption=rnd
End Sub


This post has been edited by rabbit_slayer: 07 November 2007 - 02:17 AM

Was This Post Helpful? 0
  • +
  • -

#10 rahil92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-November 07

Re: Need help making a slot machine

Posted 07 November 2007 - 04:10 AM

hey guys, i tried doing some of it by myself, but wasnt successful. but still managed to do something. below is my code. im using visual basic 5, so my control name and stuff would be different.

Public Class Form1
	Dim win As Integer
	Dim num1 As Integer
	Dim num2 As Integer
	Dim num3 As Integer
	Dim pic1 As Image
	Dim pic2 As Image
	Dim pic3 As Image


	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Randomize()
		win = 10
	End Sub

	Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
		Randomize()
		tmr1.Enabled = True
		tmr2.Enabled = True
		tmr3.Enabled = True
		lblCredit.Text = lblCredit.Text - Val(txtBet.Text)
		win = win - 5
		num1 = Int(3 * Rnd() + 1)
		num2 = Int(3 * Rnd() + 1)
		num3 = Int(3 * Rnd() + 1)
		picBar.Image = num1
		picCherry.Image = num2
		picSeven.Image = num3
		If pic1 =picBar.Image And pic2 =picBar.Image And pic3 = picBar.Image them
			lblWelcome.Text = "Congratulations! You've won $10"
			win = win + 3
		ElseIf pic2 = picCherry.Image And pic2 = picCherry.Image And pic3 = picCherry.Image Then
			lblWelcome.Text = "Congratulations! You've won $20"
			win = win + 6
		ElseIf pic3 = picSeven.Image And pic3 = picSeven.Image And pic3 = picSeven.Image Then
			lblWelcome.Text = "Jackpot! You've won $50"
			win = win + 10
		Else
			lblWelcome.Text = "Hard Luck! Try again"
		End If
		lblCredit.Text = win
	End Sub
End Class


so thats my code, and the problem that i dont know how to convert an integer value to an image. or probably there is some other way for it. please have a look at this and feedback on it. i have attached my form as well, just in case you need to have a look.

i really appreciate your help people. thank you

rahil

Attached image(s)

  • Attached Image

This post has been edited by rahil92: 07 November 2007 - 04:13 AM

Was This Post Helpful? 0
  • +
  • -

#11 rahil92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-November 07

Re: Need help making a slot machine

Posted 09 November 2007 - 06:57 AM

hey guys...havent heard from you all for a long time..is there any problem solving my question???i need to submit my assignment on 18th of november, so if i could request you people to try and help me before then please.
rahil
Was This Post Helpful? 0
  • +
  • -

#12 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Need help making a slot machine

Posted 09 November 2007 - 07:04 AM

Look into using an ImageList control instead of trying to convert an integer value to an image.
Was This Post Helpful? 0
  • +
  • -

#13 rahil92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-November 07

Re: Need help making a slot machine

Posted 09 November 2007 - 06:05 PM

how do i do that??
Was This Post Helpful? 0
  • +
  • -

#14 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Need help making a slot machine

Posted 09 November 2007 - 08:49 PM

@rahil92, if you'll click on the link I provided in the previous post, they offer a decent tutorial on using the ImageList in VB5
Was This Post Helpful? 0
  • +
  • -

#15 rahil92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-November 07

Re: Need help making a slot machine

Posted 10 November 2007 - 02:26 AM

thanks psycoCoder for your help, i did try making mine a bit different to what i had, and this is what i came up with

Public Class frmSlot
	Dim Bet As String   'Amount you bet
	Dim RandomImage As Integer 'Random Image
	Public RandomCount As Integer 'Number of times random image is displayed
	Public One As Integer 'First Image
	Public Two As Integer 'Second Image
	Public Three As Integer 'Third image

	Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
		If txtBet.Modified Then 'checks if anything was modified in txtBet
			txtBet.Text = "" 'displays no value in txtBet
			txtBet.Focus() 'sets cursor focus on txtbet
			lblCredit.Text = 50 'sets your credit back to $50
			lblWelcome.Text = "Welcome to Play!" 'displays message on the top (lblWelcome)
			End If
	End Sub

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Randomize() 'randomises numbers
		lblCredit.Text = 50 'Sets the starting amount
	End Sub


	Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
		Bet = txtBet.Text 'states that Bet is the same as txtBet.Text
		If Not IsNumeric(Bet) Then 'Checks to make sure that the bet is a number
			txtBet.Text = "" 'Clears the input
			MsgBox("Please enter a dollar amount.") 'Displays the message box
			txtBet.Focus() 'Sets the focus to be on the input
			Exit Sub 'exits sub i.e. doesn't let you play any further
		End If

		If Bet <= 0 Then 'Checks to make sure the bet is positive
			txtBet.Text = "" 'Clears the input
			MsgBox("You must enter $1 or more!") 'Displays the message box
			txtBet.Focus() 'Sets the focus to be on the input
			Exit Sub 'exits sub i.e. doesn't let you play any further
		End If

		If lblCredit.Text <= 0 Then 'Checks if the user is trying to bankrupt themselves
			MsgBox("You can't bet more than you have!")   'Displays the message box
			Exit Sub 'exits sub i.e. doesn't let you play any further
		End If

		If Val(txtBet.Text) > Val(lblCredit.Text) Then 'Checks to make sure your bet is not greater than your credit
			MsgBox("You can't bet more than you have!") 'Displays the message box
			Exit Sub 'exits sub i.e. doesn't let you play any further
		End If

		imgOne.Image = My.Resources._23315_m 'RandomImage 'value of imgOne is equal to the random number produced
		imgTwo.Image = My.Resources._23316_m 'RandomImage 'value of imgTwo is equal to the random number produced
		imgThree.Image = My.Resources._23318_m 'RandomImage 'value of imgThree is equal to the random number produced

		tmr1.Enabled = True 'enables the ticking of the first timer
		tmr2.Enabled = True 'enables the ticking of the second timer
		tmr3.Enabled = True 'enables the ticking of the third timer

		If RandomImage = 1 And RandomImage = 1 And RandomImage = 1 Then 'checks if RandomImage(imgOne), RandomImage(imgTwo), RandomImage(imgThree) is 1
			lblWelcome.Font = New Font("Ravie", 14, FontStyle.Bold) 'changes the font
			lblWelcome.Text = "Yippiee! You've won $10" 'displays message on the top (lblWelcome)
			lblCredit.Text = Trim(Str(Val(lblCredit.Text) + 10)) 'adds $10 to your credit

		ElseIf RandomImage = 2 And RandomImage = 2 And RandomImage = 2 Then 'checks if RandomImage(imgOne), RandomImage(imgTwo), RandomImage(imgThree) is 2
			lblWelcome.Font = New Font("Ravie", 14, FontStyle.Bold) 'changes the font
			lblWelcome.Text = "Yippiee! You've won $20" 'displays message on the top (lblWelcome)
			lblCredit.Text = Trim(Str(Val(lblCredit.Text) + 20)) 'adds $20 to your credit

		ElseIf RandomImage = 3 And RandomImage = 3 And RandomImage = 3 Then 'checks if RandomImage(imgOne), RandomImage(imgTwo), RandomImage(imgThree) is 2
			lblWelcome.Font = New Font("Ravie", 14, FontStyle.Bold) 'changes the font
			lblWelcome.Text = "Jackpot! You've won $50" 'displays message on the top (lblWelcome)
			lblCredit.Text = Trim(Str(Val(lblCredit.Text) + 50)) 'adds $50 to your credit

		Else 'checks is RandomNumber(imgOne), RandomImage(imgTwo), RandomImage(imgThree) are unequal
			lblWelcome.Font = New Font("Ravie", 14, FontStyle.Bold)
			lblWelcome.Text = "Hard Luck! Try again" 'displays message on the top (lblWelcome)
		End If
		lblCredit.Text = Trim(Str(Val(lblCredit.Text) - Val(txtBet.Text))) 'decreases your credit by the amount you bet
	End Sub

	Private Sub tmr1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr1.Tick
		'Code to randomize imgOne and display the images
		'RandomCount = 0 'Resets the RandomCount
		'Do Until RandomCount = 5 'Start the Loop
		RandomCount = RandomCount + 1 'Add one to RandomCount
		Randomize()
		RandomImage = Int(3 * Rnd() + 1) 'Selects a random image
		If RandomImage = 1 Then 'checks if imgOne (Bar) is selected
			One = 1
			imgOne.Image = My.Resources._23315_m 'load pic of bar
		End If
		If RandomImage = 2 Then 'checks if imgtwo (Cherry) is selected
			One = 2
			imgOne.Image = My.Resources._23316_m 'load pic of cherry
		End If
		If RandomImage = 3 Then 'checks if imgThree (Seven) is selected
			One = 3
			imgOne.Image = My.Resources._23318_m 'load pic of seven
		End If
		'loop
	End Sub

	Private Sub tmr2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr2.Tick
		'Code to randomize imgTwo and display the images
		'RandomCount = 0 'Resets the RandomCount
		'Do Until RandomCount = 10 'Start the Loop
		RandomCount = RandomCount + 1 'Add one to RandomCount
		RandomImage = Int(3 * Rnd() + 1) 'Selects a random image
		If RandomImage = 1 Then 'checks if imgOne (Bar) is selected.
			Two = 1
			imgTwo.Image = My.Resources._23315_m 'load pic of bar
		End If
		If RandomImage = 2 Then 'checks if imgtwo (Cherry) is selected
			Two = 2
			imgTwo.Image = My.Resources._23316_m 'load pic of cherry
		End If
		If RandomImage = 3 Then 'checks if imgThree (Seven) is selected
			Two = 3
			imgTwo.Image = My.Resources._23318_m 'load pic of seven
		End If
		'Loop
	End Sub

	Private Sub tmr3_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr3.Tick
		'Code to randomize imgThree and display the images
		'RandomCount = 0 'Resets the RandomCount
		'Do Until RandomCount = 15 'Start the Loop
		RandomCount = RandomCount + 1 'Add one to RandomCount
		RandomImage = Int(3 * Rnd() + 1) 'Selects a random image
		If RandomImage = 1 Then 'checks if imgOne (Bar) is selected
			Three = 1
			imgThree.Image = My.Resources._23315_m 'load pic of bar
		End If
		If RandomImage = 2 Then 'checks if imgtwo (Cherry) is selected
			Three = 2
			imgThree.Image = My.Resources._23316_m 'load pic of cherry
		End If
		If RandomImage = 3 Then 'checks if imgThree (Seven) is selected
			Three = 3
			imgThree.Image = My.Resources._23318_m 'load pic of seven
		End If
		'loop
	End Sub




i am also attaching my form, for you guys to have a look. thanks a tonne for all your help people, i am actually getting better at this subject :D

as per my knowledge, what i think is that i have to insert a timer interval to disable the ticking of the timer. if you could please help me with where should i put that, it would be really nice of you.

if there are any other corrections, please do make them. it would really help me a lot.

thank you guys for all your help.
rahil

Attached image(s)

  • Attached Image

This post has been edited by rahil92: 10 November 2007 - 05:15 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2