Megalith
Well-known member
- Joined
- Aug 21, 2006
- Messages
- 66
- Programming Experience
- 10+
i'm developing a card game ive come a long way with it but have discovered a problem. In essence the cards are a class and instances of the class are loaded into a list by a class called deck the deck can be shuffled and cards dealt 1 at a time. my problem is how would you go about resetting the deck so that i once more have a full deck of cards. heres my card test application in a form1
the code in button 1 draws a card and that in button 2 is supposed to replace the deck with a new one and shuffle it however it shuffles the cards remaining in the deck and after a few deals you have an empty deck. i'm rusty on Object programming (vb5 then an absense of programming for 4+ years) and new to the .NET framework.
VB.NET:
Imports cardgame.CardGameFramework
Public Class Form1
Dim m_Deck As New Cards ' this class contains the card images
Dim m_D As New Deck ' this class contains shuffle new and deal methods
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Ace As Card ' instance of a card with various card properties
Dim q As Integer
Ace = m_D.Draw() ' draw a card
q = Ace.CardVal get its value from 1 to 52
PictureBox1.Image = m_Deck.Card(q) 'retrieve the card for the value
TextBox1.Text = Ace.ToString ' output the name of the card
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Destroy the old Deck Create new one
Dim m_D As New Deck
MakeDeck()
End Sub
Protected Sub MakeDeck()
' Routine to shuffle
m_D.Shuffle()
End Sub
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
MakeDeck()
End Sub
End Class
the code in button 1 draws a card and that in button 2 is supposed to replace the deck with a new one and shuffle it however it shuffles the cards remaining in the deck and after a few deals you have an empty deck. i'm rusty on Object programming (vb5 then an absense of programming for 4+ years) and new to the .NET framework.