473,626 Members | 3,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2d array question...

I have to set up a 2d array(13, 4) containing a deck of playing cards.
What I am wondering is how to correctly set up the array in the first
place, and then how do you access the information once the data is in the
array? Button clicks tell the array the rank and suit of the card chosen.
The output should be a prompt telling the user what they have in their hand
if anything at all.

Here is what I have thus far:

****

Dim countEntered(13 ) As Boolean
Dim suitEntered(4) As Boolean
Dim x, y, z As Integer

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim handResult(13, 4) As Boolean
'Fill arrays
countEntered(1) = False
countEntered(2) = False
countEntered(3) = False
countEntered(4) = False
countEntered(5) = False
countEntered(6) = False
countEntered(7) = False
countEntered(8) = False
countEntered(9) = False
countEntered(10 ) = False
countEntered(11 ) = False
countEntered(12 ) = False
countEntered(13 ) = False
suitEntered(1) = False
suitEntered(2) = False
suitEntered(3) = False
suitEntered(4) = False
End Sub

*****

Here is what I have entered for button clicks....

Private Sub Button13_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button13.Click
countEntered(13 ) = True
Display.Text = "Ace"
y = y + 1
End Sub

Private Sub Button16_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button16.Click
suitEntered(1) = True
Display.Text = Display.Text & " of Spades"
z = z + 1
Return
End Sub

*****

My intent is to change the boolean value to true once the proper buttons
are clicked. Am I going about this the right way? Then, once the boolean
values are established in the array, how do I associate them with the card
value and return what is in the player's hand?

I'm a little confused. Any help will be greatly appreciated!
Nov 21 '05 #1
2 1845
You might have better luck using a class to define a single playing
card and then create an array or cards. You might even consider a
class to indicate a Hand which can hold one or more Cards. You might
also have a class called Deck which models a deck of cards. The Deck
class could have a Deal method that returns a Hand. Here is some
simple code that should give you some ideas.

Public Enum eSuit
Hearts
Clubs
Diamonds
Spades
End Enum

Public Enum eRank
Joker
Ace
Two
Three

'fill in the rest of the ranks here

King
End Enum

Public Class Card
Public Rank As eRank
Public Suit As eSuit

Public Function ToString() As String
'Code to display card here
End Function
End Class

Public Class Hand
Public CardsPerHand As Integer
Public Cards As ArrayList

Public Sub New(cardsperhan d As Integer)
Cards = New ArrayList(cards perhand)
End Sub

Public Sub AddCard(c As Card)
Cards.Add(c)
End Sub
End Class

Public Class Deck

Private _topCard As Integer
Private Cards As ArrayList

Public Sub New(cardsindeck )
_topCard = 0
Cards = New ArrayList
FillDeck()
ShuffleDeck()
End Sub

Public Function Deal(numcards) As Hand

Dim h As Hand

If (_topCard + numcards) < Cards.Length Then
h = New Hand(numcards)
For x As Integer = 0 to numcards-1
Hand.AddCard(Di rectCast(Cards( _topCard),Card) )
_topCard += 1
Next
End If

Return h

End Function

Private Sub FillDeck()
'Code to fill the deck with individual cards
End Sub

Public Sub Shuffle()
'Code to shuffle the elements of the ArrayList here
End Sub
End Class

Nov 21 '05 #2
I thank you for your reply, but I wasn't clear enough with my question...
This has to be set up as an array of Boolean type. I will be greatly
appreciative for any help I can receive. I have to create a 2D Boolean
array of size (13, 4) The contents contain a deck of 52 cards, of which
they are broken down into the obvious, hearts, spades, clubs, and diamonds,
and then obviously, the rank cards.

My question is this: I believe I have set up the array correctly, and have
it loaded when the form loads, however, I am having trouble understanding
how to access the data in the array, and then associate that data with a
particular card that the user enters. A full hand is to be analyzed by the
program and is to return a message as to whether the user has a hand that
contains anything of value: ie One Pair, Two Pair, etc.

I have included the code below.

***VB Code***

Dim handResult(13, 4) As Boolean
Dim count(13) As Integer
Dim suit(4) As Integer
Dim x, y, z As Integer
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim handResult(13, 4) As Boolean
'Fill arrays
handResult(1, 1) = count(1) & suit(1)
handResult(1, 2) = count(1) & suit(2)
handResult(1, 3) = count(1) & suit(3)
handResult(1, 4) = count(1) & suit(4)
handResult(2, 1) = count(2) & suit(1)
handResult(2, 2) = count(2) & suit(2)
handResult(2, 3) = count(2) & suit(3)
handResult(2, 4) = count(2) & suit(4)
handResult(3, 1) = count(3) & suit(1)
handResult(3, 2) = count(3) & suit(2)
handResult(3, 3) = count(3) & suit(3)
handResult(3, 4) = count(3) & suit(4)
handResult(4, 1) = count(4) & suit(1)
handResult(4, 2) = count(4) & suit(2)
handResult(4, 3) = count(4) & suit(3)
handResult(4, 4) = count(4) & suit(4)
handResult(5, 1) = count(5) & suit(1)
handResult(5, 2) = count(5) & suit(2)
handResult(5, 3) = count(5) & suit(3)
handResult(5, 4) = count(5) & suit(4)
handResult(6, 1) = count(6) & suit(1)
handResult(6, 2) = count(6) & suit(2)
handResult(6, 3) = count(6) & suit(3)
handResult(6, 4) = count(6) & suit(4)
handResult(7, 1) = count(7) & suit(1)
handResult(7, 2) = count(7) & suit(2)
handResult(7, 3) = count(7) & suit(3)
handResult(7, 4) = count(7) & suit(4)
handResult(8, 1) = count(8) & suit(1)
handResult(8, 2) = count(8) & suit(2)
handResult(8, 3) = count(8) & suit(3)
handResult(8, 4) = count(8) & suit(4)
handResult(9, 1) = count(9) & suit(1)
handResult(9, 2) = count(9) & suit(2)
handResult(9, 3) = count(9) & suit(3)
handResult(9, 4) = count(9) & suit(4)
handResult(10, 1) = count(10) & suit(1)
handResult(10, 2) = count(10) & suit(2)
handResult(10, 3) = count(10) & suit(3)
handResult(10, 4) = count(10) & suit(4)
handResult(11, 1) = count(11) & suit(1)
handResult(11, 2) = count(11) & suit(2)
handResult(11, 3) = count(11) & suit(3)
handResult(11, 4) = count(11) & suit(4)
handResult(12, 1) = count(12) & suit(1)
handResult(12, 2) = count(12) & suit(2)
handResult(12, 3) = count(12) & suit(3)
handResult(12, 4) = count(12) & suit(4)
handResult(13, 1) = count(13) & suit(1)
handResult(13, 2) = count(13) & suit(2)
handResult(13, 3) = count(13) & suit(3)
handResult(13, 4) = count(13) & suit(4)

End Sub
Private Sub Button19_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button19.Click
End
End Sub

Private Sub Button18_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button18.Click
Display.Clear()
InHand.Clear()
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
count(1) = True
Display.Text = "2"
y = y + 1
End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
count(2) = True
Display.Text = "3"
y = y + 1
End Sub

Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
count(3) = True
Display.Text = "4"
y = y + 1
End Sub

Private Sub Button4_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button4.Click
count(4) = True
Display.Text = "5"
y = y + 1
End Sub

Private Sub Button5_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button5.Click
count(5) = True
Display.Text = "6"
y = y + 1
End Sub

Private Sub Button6_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button6.Click
count(6) = True
Display.Text = "7"
y = y + 1
End Sub

Private Sub Button7_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button7.Click
count(7) = True
Display.Text = "8"
y = y + 1
End Sub

Private Sub Button8_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button8.Click
count(8) = True
Display.Text = "9"
y = y + 1
End Sub

Private Sub Button9_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button9.Click
count(9) = True
Display.Text = "10"
y = y + 1
End Sub

Private Sub Button10_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button10.Click
count(10) = True
Display.Text = "Jack"
y = y + 1
End Sub

Private Sub Button11_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button11.Click
count(11) = True
Display.Text = "Queen"
y = y + 1
End Sub

Private Sub Button12_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button12.Click
count(12) = True
Display.Text = "King"
y = y + 1
End Sub

Private Sub Button13_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button13.Click
count(13) = True
Display.Text = "Ace"
y = y + 1
End Sub

Private Sub Button16_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button16.Click
suit(1) = True
Display.Text = Display.Text & " of Spades"
z = z + 1
Return
End Sub

Private Sub Button17_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button17.Click
suit(2) = True
Display.Text = Display.Text & " of Hearts"
z = z + 1
Return
End Sub

Private Sub Button14_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button14.Click
suit(3) = True
Display.Text = Display.Text & " of Clubs"
z = z + 1
Return
End Sub

Private Sub Button15_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button15.Click
suit(4) = True
Display.Text = Display.Text & " of Diamonds"
z = z + 1
Return
End Sub

Private Sub Button20_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button20.Click
'For y = 0 To 5
'If y = 5 And z >= 4 Then
'InHand.Text = Val(suitEntered )
'End If

'Next
InHand.Text = count(1) & count(2)
If (y) & (z) = 11 Then
InHand.Text = "true"
Else : InHand.Text = "false"
End If

Display.Clear()
End Sub

Private Sub Button21_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button21.Click
InHand.Clear()
Display.Clear()
End Sub
End Class

***/VB Code***

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6401
by: SilverWolf | last post by:
I need some help with sorting and shuffling array of strings. I can't seem to get qsort working, and I don't even know how to start to shuffle the array. Here is what I have for now: #include <stdio.h> void main(void) { char lines; int count = 0, i;
9
2612
by: buda | last post by:
Hi, I've been wondering for a while now (and always forgot to ask :) what is the exact quote from the Standard that forbids the use of (&array) (when x >= number_of_columns) as stated in the FAQ 6.19 (http://www.eskimo.com/~scs/C-faq/q6.19.html). Thanks.
3
2690
by: Pol Bawin | last post by:
Hi All, One : I have a property that get/set a array of an abstract class A By default my array is null In the propertygrid, It is not works correctly when my array is null. (when my array is initialized with one element it works fine) But I can not change the initial state of the array. It must be null. what must I change.
11
2259
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^ LHSquestions = gcnew array<String^> {"question 1","question 2"}; private: static array<String^>^ RHSquestions = gcnew array<String^> {"question 1",
28
2430
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions 1: Why cannot I do the following:
104
16922
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from that array Could you show me a little example how to do this? Thanks.
51
23684
by: Pedro Graca | last post by:
I run into a strange warning (for me) today (I was trying to improve the score of the UVA #10018 Programming Challenge). $ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc 10018-clc.c: In function `main': 10018-clc.c:22: warning: array subscript has type `char' I don't like warnings ... or casts.
7
6425
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are now thown out of the array released properly by the CLI?
8
1481
by: T. Wintershoven | last post by:
Hello all, I have a form with some checkboxes. The names of these checkboxes come from an array. When i click the submit button the resultcode doesn't recognize the names when i want to check wether or not some checkboxes are ticked. Assume that i tick checkboxes 100, 150 and 200 Below is some code i've used.(between the ****** lines)
4
4555
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first element so append a comma
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.