473,385 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.EventArgs) 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.EventArgs) 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 1836
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(cardsperhand As Integer)
Cards = New ArrayList(cardsperhand)
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(DirectCast(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(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.EventArgs) Handles Button19.Click
End
End Sub

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

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

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

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

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

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

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

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

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

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.EventArgs) 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.EventArgs) 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.EventArgs) 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.EventArgs) 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.EventArgs) 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.EventArgs) 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.EventArgs) 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.EventArgs) 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.EventArgs) 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.EventArgs) 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
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...
9
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...
3
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...
11
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^>^...
28
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...
104
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...
51
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...
7
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...
8
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...
4
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.