Home > Articles > Programming > 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.
␡
- 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 - 'Slot Machine, (c) 2006 Peter Browne, GPL Licensed
- '
- 'Peter Browne
- 'Sheridan Corporate Centre
- '2155 Leanne Blvd., Ste. 200B
- 'Mississauga ON L5K 2K8
- '(905) 616-6099
- 'peterrbrowne@hotmail.com
- '
- '
- 'PPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPPPPPP BBBBBBBBBBBBBBBBBBBB
- ' PPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPPPPPPP B BB
- ' PPPPPPPPP PP PPPPPPPPP PP B BB
- ' PPPPPPPPP PP PPPPPPPPP PP B BB
- ' PPPPPPPPP P PPPPPPPPP P B BB
- ' PPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPPPPP B BB
- ' PPPPPPPPP PPPPPPPPPRRR B BB
- ' PPPPPPPPP PPPPPPPPP RRR B BB
- ' PPPPPPPPP PPPPPPPPP RRR B BB
- ' PPPPPPPPP PPPPPPPPP RRR BBBBBBBBBBBBBBBBBBB
- ' PPPPPPPPP PPPPPPPPP RRR BBBBBBBBBBBBBBBBBBB
- ' PPPPPPPPP PPPPPPPPP RRR B BB
- ' PPPPPPPPP PPPPPPPPP RRR B BB
- ' PPPPPPPPP PPPPPPPPP RRR B BB
- ' PPPPPPPPP PPPPPPPPP RRR B BB
- ' PPPPPPPPP PPPPPPPPP RRR B BB
- ' PPPPPPPPP PPPPPPPPP RRR B BB
- ' PPPPPPPPP PPPPPPPPP RRR B BB
- 'PPPPPPPPPPP PPPPPPPPPPP RRR BBBBBBBBBBBBBBBBBBBB
- '
- ' GNU GENERAL PUBLIC LICENSE
- ' Version 2, June 1991
- '
- ' Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- ' 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- ' Everyone is permitted to copy and distribute verbatim copies
- ' of this license document, but changing it is not allowed.
- '
- ' Preamble
- '
- ' The licenses for most software are designed to take away your
- 'freedom to share and change it. By contrast, the GNU General Public
- 'License is intended to guarantee your freedom to share and change free
- 'software--to make sure the software is free for all its users. This
- 'General Public License applies to most of the Free Software
- 'Foundation 's software and to any other program whose authors commit to
- 'using it. (Some other Free Software Foundation software is covered by
- 'the GNU Lesser General Public License instead.) You can apply it to
- 'your programs, too.
- '
- ' When we speak of free software, we are referring to freedom, not
- 'price. Our General Public Licenses are designed to make sure that you
- 'have the freedom to distribute copies of free software (and charge for
- 'this service if you wish), that you receive source code or can get it
- 'if you want it, that you can change the software or use pieces of it
- 'in new free programs; and that you know you can do these things.
- '
- ' To protect your rights, we need to make restrictions that forbid
- 'anyone to deny you these rights or to ask you to surrender the rights.
- 'These restrictions translate to certain responsibilities for you if you
- 'distribute copies of the software, or if you modify it.
- '
- ' For example, if you distribute copies of such a program, whether
- 'gratis or for a fee, you must give the recipients all the rights that
- 'you have. You must make sure that they, too, receive or can get the
- 'source code. And you must show them these terms so they know their
- 'rights.
- '
- ' We protect your rights with two steps: (1) copyright the software, and
- '(2) offer you this license which gives you legal permission to copy,
- 'distribute and/or modify the software.
- '
- ' Also, for each author's protection and ours, we want to make certain
- 'that everyone understands that there is no warranty for this free
- 'software. If the software is modified by someone else and passed on, we
- 'want its recipients to know that what they have is not the original, so
- 'that any problems introduced by others will not reflect on the original
- 'authors ' reputations.
- '
- ' Finally, any free program is threatened constantly by software
- 'patents. We wish to avoid the danger that redistributors of a free
- 'program will individually obtain patent licenses, in effect making the
- 'program proprietary. To prevent this, we have made it clear that any
- 'patent must be licensed for everyone's free use or not licensed at all.
- 'Declares the variables
- Dim Bet As String 'Amount Bet
- Dim Amount As String 'Amount in Account
- Dim RandomImage As Integer 'Random Image
- Dim 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
- 'Sleep
- Private Declare Sub Sleep Lib 'kernel32' (ByVal dwMilliseconds As Long)
- Private Sub Form_Load()
- 'Sets the starting amount
- Amount = 250
- 'Shows the starting amount
- lblAmount.Caption = 'You have: $' + Str(Amount)
- 'Starts the music
- OLE1.DoVerb ' (Play)
- End Sub
- Private Sub cmdPull_Click()
- 'Sets the bet as the input
- Bet = txtBet.Text
- 'Checks to make sure that the bet is a number
- If Not IsNumeric(Bet) Then
- txtBet.Text = ' 'Clears the input
- MsgBox ('Please enter a dollar amount.') 'Displays the message box
- txtBet.SetFocus 'Sets the focus to be on the input
- Exit Sub 'Ends the program
- End If
- 'Checks to make sure the bet is positive
- If Bet <= 0 Then
- txtBet.Text = ' 'Clears the input
- MsgBox ('You must enter $1 or more!') 'Displays the message box
- txtBet.SetFocus 'Sets the focus to be on the input
- Exit Sub 'Ends the program
- End If
- 'Reduces the amount by the bet
- Amount = Amount - Bet
- lblAmount.Caption = 'You Have: $' + Str(Amount)
- 'Checks if the user is trying to bankrupt themselves
- If Amount <= 0 Then
- Amount = Amount + Bet 'Raises the amount to the previous amount
- MsgBox ('You can't bet more then you have!') 'Displays the Message Box
- Exit Sub 'Ends the program
- End If
- 'Calls frmRandom
- frmRandom.Show
- 'Pauses for randomization
- Do Until frmRandom.RandomCount = 30
- Loop
- 'Winner
- If One = Two And Two = Three Then 'Determines if user is a winner
- If One = 1 Then 'Sequence for vehicle is One
- Amount = Amount + 25 'Raises the amount by $25
- MsgBox ('You win $25!') 'Displays Message Box
- lblAmount.Caption = 'You Have: $' + Str(Amount)
- End If
- If One = 2 Then 'Sequence for vehicle is Two
- Amount = Amount + 30 'Raises the amount
- MsgBox ('You Win $30!') 'Displays Message Box
- lblAmount.Caption = 'You Have: $' + Str(Amount)
- End If
- If One = 3 Then 'Sequence for vehicle is Three
- Amount = Amount + 20 'Raises the amount
- MsgBox ('You Win $20') 'Diplays Message Box
- lblAmount.Caption = 'You Have: $' + Str(Amount)
- End If
- If One = 4 Then 'Sequence for vehicle is Four
- Amount = Amount - 35 'Lowers the Amount
- If Amount <= 0 Then 'Sequence for bankrupt users
- Amount = 0
- MsgBox ('You went bankrupt! I will now close!')
- lblAmount.Caption = 'You Have: $' + Str(Amount)
- Unload frmMachine
- Exit Sub
- End If
- MsgBox ('You Lost $35!')
- lblAmount.Caption = 'You Have: $' + Str(Amount)
- End If
- Else 'If user did not win
- MsgBox ('You did not win!')
- MsgBox ('Please try again!')
- End If
- End Sub
- Private Sub cmdDone_Click()
- 'Closes the program
- Unload frmMachine
- End Sub
|
|