Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > PUblic array With images


Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2003, 10:45 PM
NeverMore5
Guest
 
Posts: n/a
Default PUblic array With images


this is how i have the array set up it in a module

Public Card(1 To 52, 1 To 2) As Variant
Public intpc(8), intdc(8), intrnd(10), inthit(2) As Integer, hit(6) As Boolean
'intpc holds play card vaule intdc holds dealer card vaule intrnd are random numbers to pic cards
Public Sub cards()
Card(1, 1) = App.Path & "\images\2CLUBS.gif" ' This is image
Card(1, 2) = 2 'Value of card
Card(2, 1) = App.Path & "\images\2DIMND.gif" ' This is image
Card(2, 2) = 2 'Value of card
Card(3, 1) = App.Path & "\images\2HEARTS.gif" ' This is image
Card(3, 2) = 2 'Value of card
Card(4, 1) = App.Path & "\images\2SPADE.gif" ' This is image
Card(4, 2) = 2 'Value of card
Card(5, 1) = App.Path & "\images\3CLUBS.gif" ' This is image
Card(5, 2) = 3 'Value of card
Card(6, 1) = App.Path & "\images\3DIMND.gif" ' This is image
Card(6, 2) = 3 'Value of card
Card(7, 1) = App.Path & "\images\3HEARTS.gif" ' This is image
Card(7, 2) = 3 'Value of card
Card(8, 1) = App.Path & "\images\3SPADE.gif" ' This is image
Card(8, 2) = 3 'Value of card
Card(9, 1) = App.Path & "\images\4CLUBS.gif" ' This is image
Card(9, 2) = 4 'Value of card
Card(10, 1) = App.Path & "\images\4DIMND.gif" ' This is image
Card(10, 2) = 4 'Value of card
Card(11, 1) = App.Path & "\images\4HEARTS.gif" ' This is image
Card(11, 2) = 4 'Value of card
Card(12, 1) = App.Path & "\images\4SPADE.gif" ' This is image
Card(12, 2) = 4 'Value of card
Card(13, 1) = App.Path & "\images\5CLUBS.gif" ' This is image
Card(13, 2) = 5 'Value of card
Card(14, 1) = App.Path & "\images\5DIMND.gif" ' This is image
Card(14, 2) = 5 'Value of card
Card(15, 1) = App.Path & "\images\5HEARTS.gif" ' This is image
Card(15, 2) = 5 'Value of card
Card(16, 1) = App.Path & "\images\5SPADE.gif" ' This is image
Card(16, 2) = 5 'Value of card
Card(17, 1) = App.Path & "\images\6CLUBS.gif" ' This is image
Card(17, 2) = 6 'Value of card
Card(18, 1) = App.Path & "\images\6DIMND.gif" ' This is image
Card(18, 2) = 6 'Value of card
Card(19, 1) = App.Path & "\images\6HEARTS.gif" ' This is image
Card(19, 2) = 6 'Value of card
Card(20, 1) = App.Path & "\images\6SPADE.gif" ' This is image
Card(20, 2) = 6 'Value of card
Card(21, 1) = App.Path & "\images\7CLUBS.gif" ' This is image
Card(21, 2) = 7 'Value of card
Card(22, 1) = App.Path & "\images\7DIMND.gif" ' This is image
Card(22, 2) = 7 'Value of card
Card(23, 1) = App.Path & "\images\7HEARTS.gif" ' This is image
Card(23, 2) = 7 'Value of card
Card(24, 1) = App.Path & "\images\7SPADE.gif" ' This is image
Card(24, 2) = 7 'Value of card
Card(25, 1) = App.Path & "\images\8DIMND.gif" ' This is image
Card(25, 2) = 8 'Value of card
Card(26, 1) = App.Path & "\images\8HEARTS.gif" ' This is image
Card(26, 2) = 8 'Value of card
Card(27, 1) = App.Path & "\images\8SPADE.gif" ' This is image
Card(27, 2) = 8 'Value of card
Card(28, 1) = App.Path & "\images\8CLUBS.gif" ' This is image
Card(28, 2) = 8 'Value of card
Card(29, 1) = App.Path & "\images\9DIMND.gif" ' This is image
Card(29, 2) = 9 'Value of card
Card(30, 1) = App.Path & "\images\9HEARTS.gif" ' This is image
Card(30, 2) = 9 'Value of card
Card(31, 1) = App.Path & "\images\9SPADE.gif" ' This is image
Card(31, 2) = 9 'Value of card
Card(32, 1) = App.Path & "\images\9CLUBS.gif" ' This is image
Card(32, 2) = 9 'Value of card
Card(33, 1) = App.Path & "\images\10DIMND.gif" ' This is image
Card(33, 2) = 10 'Value of card
Card(34, 1) = App.Path & "\images\10HEARTS.gif" ' This is image
Card(34, 2) = 10 'Value of card
Card(35, 1) = App.Path & "\images\10SPADe.gif" ' This is image
Card(35, 2) = 10 'Value of card
Card(36, 1) = App.Path & "\images\10CLUBS.gif" ' This is image
Card(36, 2) = 10 'Value of card
Card(37, 1) = App.Path & "\images\jackDMND.gif" ' This is image
Card(37, 2) = 10 'Value of card
Card(38, 1) = App.Path & "\images\JACKHRTS.gif" ' This is image
Card(38, 2) = 10 'Value of card
Card(39, 1) = App.Path & "\images\jackSPAD.gif" ' This is image
Card(39, 2) = 10 'Value of card
Card(40, 1) = App.Path & "\images\jackclub.gif" ' This is image
Card(40, 2) = 10 'Value of card
Card(41, 1) = App.Path & "\images\KINGHRTS.gif" ' This is image
Card(41, 2) = 10 'Value of card
Card(42, 1) = App.Path & "\images\KINGSPAD.gif" ' This is image
Card(42, 2) = 10 'Value of card
Card(43, 1) = App.Path & "\images\KINGCLUB.gif" ' This is image
Card(43, 2) = 10 'Value of card
Card(44, 1) = App.Path & "\images\KINGDMND.gif" ' This is image
Card(44, 2) = 10 'Value of card
Card(45, 1) = App.Path & "\images\QUENHRTS.gif" ' This is image
Card(45, 2) = 10 'Value of card
Card(46, 1) = App.Path & "\images\QUENSPAD.gif" ' This is image
Card(46, 2) = 10 'Value of card
Card(47, 1) = App.Path & "\images\QUENCLUB.gif" ' This is image
Card(47, 2) = 10 'Value of card
Card(48, 1) = App.Path & "\images\QUENDMND.gif" ' This is image
Card(48, 2) = 10 'Value of card
Card(49, 1) = App.Path & "\images\aceHEART.gif" ' This is image
Card(49, 2) = 11 'Value of card
Card(50, 1) = App.Path & "\images\aceSPADe.gif" ' This is image
Card(50, 2) = 11 'Value of card
Card(51, 1) = App.Path & "\images\aceCLUBs.gif" ' This is image
Card(51, 2) = 11 'Value of card
Card(52, 1) = App.Path & "\images\aceDiMND.gif" ' This is image
Card(52, 2) = 11 'Value of card
End Sub




this is the deal button code

Private Sub cmdDeal_Click()

Dim intace, intp, intd As Integer, player, dealer As Boolean
'intace is a new vaule you for int ace intp and intd are counters to fill card slot 1 and 2

player = True

For intp = 1 To 2 Step 1

Do While player = True

modcard.intrnd(0) = Int(Rnd * 52 + 1)

If modcard.Card(modcard.intrnd(0), 2) <> 100 Then
picpc(intp).Picture = LoadPicture(modcard.Card(modcard.intrnd(0), 1))
modcard.intpc(intp) = modcard.Card(modcard.intrnd(0), 2)
modcard.Card(modcard.intrnd(0), 2) = 100
player = False
Else
player = True
End If

Loop
Next intp

If modcard.intpc(1) = modcard.intpc(2) Then
cmdsplit.Enabled = True
End If

For intd = 1 To 2
Do While dealer = True
modcard.intrnd(1) = Int(Rnd * 52 + 1)

If modcard.Card(modcard.intrnd(1), 2) <> 100 Then
picdc(intd).Picture = LoadPicture(modcard.Card(modcard.intrnd(1), 1))
intdc(intd) = modcard.Card(modcard.intrnd(1), 2)
modcard.Card(modcard.intrnd(1), 2) = 100
dealer = False
If intd = 2 Then
picdc(intd).Picture = LoadPicture(cardback)
End If

Else
dealer = True
End If
Loop
Next

modcard.intpc(0) = modcard.intpc(1) + modcard.intpc(2)
If modcard.intdc(1) = 11 Then
If modcard.intpc(0) <> 21 Then
intace = InputBox("pic 1 or 11", , "Ace")
If intace + modcard.intpc(2) > 22 Then
intace = 1
End If
modcard.intpc(0) = 0
modcard.intpc(0) = intace + modcard.intpc(2)
End If
End If

lblpc.Caption = modcard.intpc(0)

modcard.intdc(0) = modcard.intdc(1) + modcard.intdc(2)

now when i hit the deal button it dose nothing and it so post to load oic and vaules as u can see can someone plase help me i wouls appreacit it alot thank you
Reply With Quote
  #2  
Old 02-07-2003, 04:30 AM
Elrabin Elrabin is offline
Centurion
 
Join Date: Jan 2003
Location: Georgia
Posts: 122
Default

Oi, ick, too many variables!!
Code is real hard to follow..but here is my try..

I think the line in question is this:
picpc(intp).Picture = LoadPicture(modcard.Card(modcard.intrnd(0), 1))
Dont use loadpicture if there is a pic in a variable. You could do that if the path was in that variable. You need to do this...I think...dont quite understand why do do a few things...
You should also make a resource file, which would make getting the cards (and storing them) easier, but if not...just name them from 0.bmp to 51.bmp
Code:
Private oCard(51, 1) as Object Dim x as Integer For x = 0 to 51 oCard(x, 0) = App.Path & "\" & x & ".bmp" Next ... picpc(intp).Picture = oCard(y, z)
Use the type Object if you are loading pictures. I can't think of very many situations you would actually want to declare a variable as a variant.
Another thing, you dont need to add the Step 1 at the end of a For/Next loop because its defaulted as 1.

You should probably try to make your code a bit more simple. That nasty little bunch of loops down there is very bad, it could be done MUCH better. Try looking through planetsourcecode.com for a poker game, that should give you a start.
__________________
Level I DCI judge
Reply With Quote
  #3  
Old 02-07-2003, 09:16 AM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

It'd be more efficient to use a User-defined Type instead of 104 Variants.

Code:
'In module... if you have no module (*.bas), then change Public 'to private Public Type Card InFile As String Value As Byte End Type Dim Cards(0 To 51) As Card
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #4  
Old 02-07-2003, 01:59 PM
happy_mouse's Avatar
happy_mouse happy_mouse is offline
Regular
 
Join Date: Dec 2002
Location: North Carolina
Posts: 54
Default

A clarification from Iceplugs response, lots of your variable declares are declaring variants. If you declare more than one variable on a line and only specify the type on one, then all the others on that line become variants.

I agree with Iceplug, use a UDT.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->