If lblPlayer.Text >= 21 & lblDealer.Text >= 21 ThenĮvery time the Hit button gets pressed, the current score of both players gets increased to a randomly generated number. LblDealer.Text = Val(lblDealer.Text) + RandomNumber(21) LblPlayer.Text = Val(lblPlayer.Text) + RandomNumber(21) ![]() This function generates a random number between 1 and the supplied value.Īdd the following code for the button labeled “ Hit:” Private Sub btnHit_Click(ByVal sender As System.Object, _īyVal e As System.EventArgs) Handles btnHit.Click This indicates that a new game has been started.Īdd the RandomNumber function: Public Function RandomNumber(ByVal intNum As Integer) _ĭim rRnd As New Random() Based on these two tests, a potential winner can immediately be identified, so that the next game can commence. The two labels ( lblPlayer and lblDealer)’s Text get set to a number that gets returned by the RandomNumber function, which we will add shortly. Just keep in mind that my names might differ from yours.Īdd the following code for the button labeled “ Deal:“ Private Sub btnDeal_Click(ByVal sender As System.Object, _īyVal e As System.EventArgs) Handles btnDeal.Click You are welcome to name your objects to your liking. Create a Visual Basic Windows Forms project and design your form to resemble Figure 1: The aim of this project is to show you how easy it is to create a Blackjack game albeit without cards, yet the logic remains. All other cards are counted as the numeric value shown on the card.Īfter receiving their first two cards, players have the option of taking an additional card, or getting a “hit.” In a given round, the player or the dealer wins by having a score of 21 or by having the higher score that is less than 21. The player and the dealer can count an ace as either 1 point or 11 points. Face cards-such as kings, queens, and jacks-are counted as ten points each. The player or players are dealt a two-card hand and add together the value of their cards.
0 Comments
Leave a Reply. |