Slot Machine Game Visual Basic

Home > Articles > Programming > Visual Basic

Slot machine game in visual basic

Visual Studio Graphics Diagnostics provides an easy way to capture and analyze frames from your DirectX 10, 11, or 12 games locally or remotely. You can inspect each DirectX event, graphics object, pixel history, and look into the graphics pipeline to understand exactly what occurred during the frame. Welcome to the Visual Basic Games and Fun page! A lot of people might think that Visual Basic is not a suitable programming language for games. Well, though there might be some limitations in Visual Basic regarding games programming and animation, we can actually construct some very interesting games and fun programs in VB6 if we put in a lot. Hey Guys a second tutorial but third video from TheCoding Seal, this time we look at programming in Visual Basic using Visual Studio 2013 from Microsoft.

  1. Programming Card Games
Page 1 of 8Next >
In this sample chapter, author Clayton Walnum teaches you how to create a class for manipulating a deck of cards. Learn how to write a class to represent a single card or a deck of cards, and how to use classes to write card programs such as blackjack.
This chapter was selected from Sams Teach Yourself Game Programming with Visual Basic in 21 Days.

Visual Basic Games Easy

Few types of games are more popular than card games. Most households have a deck of cards, and probably more fortunes are won and lost over a card table than on a roulette wheel or a slot machine. That popularity crosses over to computer card games as well. The bottom line is that if you're going to be a Visual Basic game programmer, you need to know how to use VB to handle a deck of virtual cards.

Fortunately, Lady Luck is smiling upon you. In this chapter, not only will you create a class for manipulating a deck of cards, but you'll also get a full set of graphical images for your cards. If there's one thing that discourages most programmers from creating card games, it's the daunting challenge of drawing images for 52 cards—especially the face cards, which are the most graphically complex cards in the deck.

Specifically, today you'll learn the following:

  • How to write a class to represent a single card

  • How to write a class to represent a deck of cards

  • How to write card programs using classes

  • How to write a simple blackjack game

Deck-Handling Functions

Slot Machine Game Visual Basic Games

In the following sections, you'll create a class that you can use to program card games. Before creating a class, however, you have to consider carefully the different ways that you must manipulate the data encapsulated in the class. After you've analyzed your game's needs, you can then write the class's functions. Unfortunately for programmers, there are more card games than craters on the moon. This makes creating a complete card class a nearly impossible task. You can never predict all the different ways that you might need to manipulate cards in your programs.

Therefore, the best you can do is to write the functions that every card game needs—such as shuffling a deck and dealing hands—and then add more specific functions as you need them. That's the approach this chapter will take with the clsCard class, which will be used in the next few chapters. After you understand how the clsCard class works, you'll be able to add any other functions that you need to create specific card games.

Related Resources

There are currently no related titles. Please check back later.

Slot Machine Game In Visual Basic

P: 6
This is a slot machine game, 2 forms. One is the actual game (frmMachine) and the other is in the background and randomizes the images shown on frmMachine. I need to make frmMachine wait for frmRandom, i tried it with the Sleep API and a Do/Until Loop and neither worked, could you please help me, I have my code below.
frmMachine
  1. 'Slot Machine, (c) 2006 Peter Browne, GPL Licensed
  2. '
  3. 'Peter Browne
  4. 'Sheridan Corporate Centre
  5. '2155 Leanne Blvd., Ste. 200B
  6. 'Mississauga ON L5K 2K8
  7. '(905) 616-6099
  8. 'peterrbrowne@hotmail.com
  9. '
  10. '
  11. 'PPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPPPPPP BBBBBBBBBBBBBBBBBBBB
  12. ' PPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPPPPPPP B BB
  13. ' PPPPPPPPP PP PPPPPPPPP PP B BB
  14. ' PPPPPPPPP PP PPPPPPPPP PP B BB
  15. ' PPPPPPPPP P PPPPPPPPP P B BB
  16. ' PPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPPPPP B BB
  17. ' PPPPPPPPP PPPPPPPPPRRR B BB
  18. ' PPPPPPPPP PPPPPPPPP RRR B BB
  19. ' PPPPPPPPP PPPPPPPPP RRR B BB
  20. ' PPPPPPPPP PPPPPPPPP RRR BBBBBBBBBBBBBBBBBBB
  21. ' PPPPPPPPP PPPPPPPPP RRR BBBBBBBBBBBBBBBBBBB
  22. ' PPPPPPPPP PPPPPPPPP RRR B BB
  23. ' PPPPPPPPP PPPPPPPPP RRR B BB
  24. ' PPPPPPPPP PPPPPPPPP RRR B BB
  25. ' PPPPPPPPP PPPPPPPPP RRR B BB
  26. ' PPPPPPPPP PPPPPPPPP RRR B BB
  27. ' PPPPPPPPP PPPPPPPPP RRR B BB
  28. ' PPPPPPPPP PPPPPPPPP RRR B BB
  29. 'PPPPPPPPPPP PPPPPPPPPPP RRR BBBBBBBBBBBBBBBBBBBB
  30. '
  31. ' GNU GENERAL PUBLIC LICENSE
  32. ' Version 2, June 1991
  33. '
  34. ' Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
  35. ' 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  36. ' Everyone is permitted to copy and distribute verbatim copies
  37. ' of this license document, but changing it is not allowed.
  38. '
  39. ' Preamble
  40. '
  41. ' The licenses for most software are designed to take away your
  42. 'freedom to share and change it. By contrast, the GNU General Public
  43. 'License is intended to guarantee your freedom to share and change free
  44. 'software--to make sure the software is free for all its users. This
  45. 'General Public License applies to most of the Free Software
  46. 'Foundation 's software and to any other program whose authors commit to
  47. 'using it. (Some other Free Software Foundation software is covered by
  48. 'the GNU Lesser General Public License instead.) You can apply it to
  49. 'your programs, too.
  50. '
  51. ' When we speak of free software, we are referring to freedom, not
  52. 'price. Our General Public Licenses are designed to make sure that you
  53. 'have the freedom to distribute copies of free software (and charge for
  54. 'this service if you wish), that you receive source code or can get it
  55. 'if you want it, that you can change the software or use pieces of it
  56. 'in new free programs; and that you know you can do these things.
  57. '
  58. ' To protect your rights, we need to make restrictions that forbid
  59. 'anyone to deny you these rights or to ask you to surrender the rights.
  60. 'These restrictions translate to certain responsibilities for you if you
  61. 'distribute copies of the software, or if you modify it.
  62. '
  63. ' For example, if you distribute copies of such a program, whether
  64. 'gratis or for a fee, you must give the recipients all the rights that
  65. 'you have. You must make sure that they, too, receive or can get the
  66. 'source code. And you must show them these terms so they know their
  67. 'rights.
  68. '
  69. ' We protect your rights with two steps: (1) copyright the software, and
  70. '(2) offer you this license which gives you legal permission to copy,
  71. 'distribute and/or modify the software.
  72. '
  73. ' Also, for each author's protection and ours, we want to make certain
  74. 'that everyone understands that there is no warranty for this free
  75. 'software. If the software is modified by someone else and passed on, we
  76. 'want its recipients to know that what they have is not the original, so
  77. 'that any problems introduced by others will not reflect on the original
  78. 'authors ' reputations.
  79. '
  80. ' Finally, any free program is threatened constantly by software
  81. 'patents. We wish to avoid the danger that redistributors of a free
  82. 'program will individually obtain patent licenses, in effect making the
  83. 'program proprietary. To prevent this, we have made it clear that any
  84. 'patent must be licensed for everyone's free use or not licensed at all.
  85. 'Declares the variables
  86. Dim Bet As String 'Amount Bet
  87. Dim Amount As String 'Amount in Account
  88. Dim RandomImage As Integer 'Random Image
  89. Dim RandomCount As Integer 'Number of times random image is displayed
  90. Public One As Integer 'First Image
  91. Public Two As Integer 'Second Image
  92. Public Three As Integer 'Third image
  93. 'Sleep
  94. Private Declare Sub Sleep Lib 'kernel32' (ByVal dwMilliseconds As Long)
  95. Private Sub Form_Load()
  96. 'Sets the starting amount
  97. Amount = 250
  98. 'Shows the starting amount
  99. lblAmount.Caption = 'You have: $' + Str(Amount)
  100. 'Starts the music
  101. OLE1.DoVerb ' (Play)
  102. End Sub
  103. Private Sub cmdPull_Click()
  104. 'Sets the bet as the input
  105. Bet = txtBet.Text
  106. 'Checks to make sure that the bet is a number
  107. If Not IsNumeric(Bet) Then
  108. txtBet.Text = ' 'Clears the input
  109. MsgBox ('Please enter a dollar amount.') 'Displays the message box
  110. txtBet.SetFocus 'Sets the focus to be on the input
  111. Exit Sub 'Ends the program
  112. End If
  113. 'Checks to make sure the bet is positive
  114. If Bet <= 0 Then
  115. txtBet.Text = ' 'Clears the input
  116. MsgBox ('You must enter $1 or more!') 'Displays the message box
  117. txtBet.SetFocus 'Sets the focus to be on the input
  118. Exit Sub 'Ends the program
  119. End If
  120. 'Reduces the amount by the bet
  121. Amount = Amount - Bet
  122. lblAmount.Caption = 'You Have: $' + Str(Amount)
  123. 'Checks if the user is trying to bankrupt themselves
  124. If Amount <= 0 Then
  125. Amount = Amount + Bet 'Raises the amount to the previous amount
  126. MsgBox ('You can't bet more then you have!') 'Displays the Message Box
  127. Exit Sub 'Ends the program
  128. End If
  129. 'Calls frmRandom
  130. frmRandom.Show
  131. 'Pauses for randomization
  132. Do Until frmRandom.RandomCount = 30
  133. Loop
  134. 'Winner
  135. If One = Two And Two = Three Then 'Determines if user is a winner
  136. If One = 1 Then 'Sequence for vehicle is One
  137. Amount = Amount + 25 'Raises the amount by $25
  138. MsgBox ('You win $25!') 'Displays Message Box
  139. lblAmount.Caption = 'You Have: $' + Str(Amount)
  140. End If
  141. If One = 2 Then 'Sequence for vehicle is Two
  142. Amount = Amount + 30 'Raises the amount
  143. MsgBox ('You Win $30!') 'Displays Message Box
  144. lblAmount.Caption = 'You Have: $' + Str(Amount)
  145. End If
  146. If One = 3 Then 'Sequence for vehicle is Three
  147. Amount = Amount + 20 'Raises the amount
  148. MsgBox ('You Win $20') 'Diplays Message Box
  149. lblAmount.Caption = 'You Have: $' + Str(Amount)
  150. End If
  151. If One = 4 Then 'Sequence for vehicle is Four
  152. Amount = Amount - 35 'Lowers the Amount
  153. If Amount <= 0 Then 'Sequence for bankrupt users
  154. Amount = 0
  155. MsgBox ('You went bankrupt! I will now close!')
  156. lblAmount.Caption = 'You Have: $' + Str(Amount)
  157. Unload frmMachine
  158. Exit Sub
  159. End If
  160. MsgBox ('You Lost $35!')
  161. lblAmount.Caption = 'You Have: $' + Str(Amount)
  162. End If
  163. Else 'If user did not win
  164. MsgBox ('You did not win!')
  165. MsgBox ('Please try again!')
  166. End If
  167. End Sub
  168. Private Sub cmdDone_Click()
  169. 'Closes the program
  170. Unload frmMachine
  171. End Sub