Jump to content

Recommended Posts

Posted

Well I will show you how to make a 21 cards game in VB

 

this game is not like normal 21cards game.. you can't stop at 2-3 cards... you must take cards untill you get 21 or burst....

the program will look like this:

1zwj3vo.jpg

ok we can now start :P

 

Firstly, follow the instructions below to add the right components and give them the right properties:

 

 

- Click on Form1, and change the text to "21", change the STARTPOSITION property to "CENTERSCREEN", change the MAXIMIZEBOX property to "FALSE", change the FORMBORDERSTYLE property to "FIXEDSINGLE", and finally the BACKCOLOUR property to "GREEN".

 

- Add Label1, and change the text to "Player 1 Cards: 0"

 

- Add Label2, change the VISIBLE property to "FALSE" and delete it's text. It doesn't matter where you put this label on the form

 

- Add Label3, and change the text to "Target: 21"

 

- Add Label4, change the VISIBLE property to "FALSE" and delete it's text. It doesn't matter where you put this label on the form

 

- Add Label5, and change the text to "Player 2 Cards: 0"

 

- Add Label6, and change the text to "First Player To Fill Their Progress Bar Wins!"

 

- Add Label7, change the VISIBLE property to "FALSE" and delete it's text. It doesn't matter where you put this label on the form.

 

 - Add Button1 and change it's text to "Player 1"

 

- Add Button2, change the ENABLED property to "FALSE" and change the text to "Player 2"

 

- Add Button 3, and change the text to "New Game"

 

 - Add 2 progress bars

 

 - Add 5 picture boxes and change the VISIBLE property to "FALSE" for all of them. Save the pictures of the cards(download them from the end of topiC) to your computer. Then, go to PictureBox1, and click on the IMAGE property. Click "Local Resource" and "Import", then find the picture of the ace. For PictureBox2, do the same but select the picture of the 2 of Spades, for PictureBox3 select the 3 of Hearts etc.

 

- Position all the PictureBoxes on top of each other

 

- If you haven't done already, move all the different components about so that they are in the correct places (as shown in the video).

 

 

Now we can start to programme the game, so switch to Code View and follow these instructions:

 

 

 

Enter the following code at the top (below "Public Class Form1")

 

Public P1Cards As Integer = 0

 

Public P2Cards As Integer = 0

 

Public P1Score As Integer = 0

 

Public P2Score As Integer = 0

 

 

Double click Button1 and copy + paste this:

 

Dim TheRandomClass As New Random

 

       Dim i As Integer = 0

 

       i = TheRandomClass.Next(1, 6)

 

       Label2.Text = i.ToString

 

       P1Cards += i

 

       Label1.Text = "Player 1 Cards: " + P1Cards.ToString

 

       If Label2.Text = 1 Then

 

           PictureBox1.Visible = True

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = False

 

       End If

 

       If Label2.Text = 2 Then

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = True

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = False

 

       End If

 

       If Label2.Text = 3 Then

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = True

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = False

 

       End If

 

       If Label2.Text = 4 Then

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = True

 

           PictureBox5.Visible = False

 

       End If

 

       If Label2.Text = 5 Then

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = True

 

       End If

 

       If P1Cards > 21 Then

 

           MsgBox("Bust!", MsgBoxStyle.Critical, "End Of Turn")

 

           P1Cards = 0

 

           Label2.Text = ""

 

           Label1.Text = "Player 1 Cards: 0"

 

           Button1.Enabled = False

 

           Button2.Enabled = True

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = False

 

       End If

 

       If P1Cards = 21 Then

 

           MsgBox("21!", MsgBoxStyle.Information, "End Of Turn")

 

           P1Cards = 0

 

           Label2.Text = ""

 

           Label1.Text = "Player 1 Cards: 0"

 

           Dim o As Integer = 0

 

           o = 1

 

           P1Score += o

 

           Label4.Text = P1Score * 20

 

           ProgressBar1.Value = Label4.Text

 

           Button1.Enabled = False

 

           Button2.Enabled = True

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = False

 

       End If

 

       If ProgressBar1.Value = 100 Then

 

           MsgBox("Player 1 Wins!", MsgBoxStyle.Information, "End Of Game")

 

           Button1.Enabled = False

 

           Button2.Enabled = False

 

           Label1.Text = "Player 1 Cards: 0"

 

           Label5.Text = "Player 2 Cards: 0"

 

       End If

 

 

 

 

 

Double click Button2 and copy + paste this:

 

 

 

Dim TheRandomClass As New Random

 

       Dim i As Integer = 0

 

       i = TheRandomClass.Next(1, 6)

 

       Label2.Text = i.ToString

 

       P2Cards += i

 

       Label5.Text = "Player 2 Cards: " + P2Cards.ToString

 

       If Label2.Text = 1 Then

 

           PictureBox1.Visible = True

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = False

 

       End If

 

       If Label2.Text = 2 Then

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = True

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = False

 

       End If

 

       If Label2.Text = 3 Then

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = True

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = False

 

       End If

 

       If Label2.Text = 4 Then

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = True

 

           PictureBox5.Visible = False

 

       End If

 

       If Label2.Text = 5 Then

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = True

 

       End If

 

       If P2Cards > 21 Then

 

           MsgBox("Bust!", MsgBoxStyle.Critical, "End Of Turn")

 

           P2Cards = 0

 

           Label2.Text = ""

 

           Label5.Text = "Player 2 Cards: 0"

 

           Button2.Enabled = False

 

           Button1.Enabled = True

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = False

 

       End If

 

       If P2Cards = 21 Then

 

           MsgBox("21!", MsgBoxStyle.Information, "End Of Turn")

 

           P2Cards = 0

 

           Label2.Text = ""

 

           Label5.Text = "Player 2 Cards: 0"

 

           Dim o As Integer = 0

 

           o = 1

 

           P2Score += o

 

           Label7.Text = P2Score * 20

 

           ProgressBar2.Value = Label7.Text

 

           Button2.Enabled = False

 

           Button1.Enabled = True

 

           PictureBox1.Visible = False

 

           PictureBox2.Visible = False

 

           PictureBox3.Visible = False

 

           PictureBox4.Visible = False

 

           PictureBox5.Visible = False

 

       End If

 

       If ProgressBar2.Value = 100 Then

 

           MsgBox("Player 2 Wins!", MsgBoxStyle.Information, "End Of Game")

 

           Button1.Enabled = False

 

           Button2.Enabled = False

 

           Label1.Text = "Player 1 Cards: 0"

 

           Label5.Text = "Player 2 Cards: 0"

 

       End If

 

 

Double Click Button3 and copy + paste this:

 

 

 

P1Cards = 0

 

       P2Cards = 0

 

       P1Score = 0

 

       P2Score = 0

 

       Label1.Text = "Player 1 Cards: 0"

 

       Label5.Text = "Player 2 Cards: 0"

 

       Label2.Text = ""

 

       Button1.Enabled = True

 

       Button2.Enabled = False

 

       ProgressBar1.Value = 0

 

       ProgressBar2.Value = 0

 

       PictureBox1.Visible = False

 

       PictureBox2.Visible = False

 

       PictureBox3.Visible = False

 

       PictureBox4.Visible = False

 

       PictureBox5.Visible = False

 

 

Click Start Debugging, and the game should work!

 

 

 

ok that was all ..

 

code credits to : Davidboskett

text credits to : Davidboskett

 

Download pictures for last step from Here

Download game from Here

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..