vb.net - How to display deck of cards and compare for doubles -


so.. right having pretty big problem. have pictures of card deck not displaying @ when deal button clicked. being displayed initially, tweaked , not.. there 3 players, test code player one. right set 16 cards, idea.

also, how compare check doubles , remove them discard pile? please help, beyond capabilities @ point , have no idea how proceed. thanks!!

deckofcardstest

public class deckofcardstest     dim playercards integer = 16     dim playermatches integer     dim comp1cards integer     dim comp1matches integer     dim comp2cards integer     dim comp2matches integer       private deck new deckofcards() ' create deck of cards       private sub dealbutton_click(byval sender system.object,        byval e system.eventargs) handles dealbutton.click         discard1picturebox.visible = true          deck.shuffle() ' shuffles deck          dim card1 = deck.dealcard()         card1picturebox.image = getcardimage(card1)          dim card2 = deck.dealcard()         card2picturebox.image = getcardimage(card2)          dim card3 = deck.dealcard()         card3picturebox.image = getcardimage(card3)          dim card4 = deck.dealcard()         card4picturebox.image = getcardimage(card4)          dim card5 = deck.dealcard()         card5picturebox.image = getcardimage(card5)          dim card6 = deck.dealcard()         card6picturebox.image = getcardimage(card6)          dim card7 = deck.dealcard()         card7picturebox.image = getcardimage(card7)          dim card8 = deck.dealcard()         card8picturebox.image = getcardimage(card8)          dim card9 = deck.dealcard()         card9picturebox.image = getcardimage(card9)          dim card10 = deck.dealcard()         card10picturebox.image = getcardimage(card10)          dim card11 = deck.dealcard()         card11picturebox.image = getcardimage(card11)          dim card12 = deck.dealcard()         card12picturebox.image = getcardimage(card12)          dim card13 = deck.dealcard()         card13picturebox.image = getcardimage(card13)          dim card14 = deck.dealcard()         card14picturebox.image = getcardimage(card14)          dim card15 = deck.dealcard()         card15picturebox.image = getcardimage(card15)          dim card16 = deck.dealcard()         card16picturebox.image = getcardimage(card16)          lblplayercards.text = cstr(playercards)         end sub ' dealbutton_click      ' return image card argument     private function getcardimage(byval card card) image         if card isnot nothing             ' retrieve specific card image resources             dim pictureresource = my.resources.resourcemanager.getobject(               card.tostring().replace(" ", ""))             return ctype(pictureresource, image) ' return image         else             dealbutton.enabled = false ' disable deal button             return nothing ' no more cards         end if        end function ' getcardimage      private sub btnquick_click(byval sender system.object, byval e system.eventargs) handles btnquick.click         discard1picturebox.visible = true           deck.shuffle() ' shuffles deck                        dim card1 = deck.dealcard()             card1picturebox.image = getcardimage(card1)              dim card2 = deck.dealcard()             card2picturebox.image = getcardimage(card2)              messagebox.show("thank playing")             dealbutton.enabled = false             btnquick.enabled = false         loop     end sub   end class ' deckofcardstest 

card

public class card      public enum cardvalue         ace = 1         2 = 2         3 = 3         4 = 4         5 = 5         6 = 6         secen = 7         8 = 8         9 = 9         ten = 10         jack = 11         queen = 12         king = 13     end enum      public enum cardsuit         clubs         spades         hearts         diamonds     end enum      public property value cardvalue     public property suit cardsuit      public sub new(byval value cardvalue, byval suit cardsuit)         me.value = value         me.suit = suit     end sub  end class 

deckofcards

public class deckofcards    private const number_of_cards integer = 52 ' number of cards    private deck(number_of_cards - 1) card ' array of card objects    private currentcard integer ' index of next card dealt    private shared randomnumbers new random() ' random number generator     ' constructor fills deck of cards    public sub new()       dim faces() string = {"ace", "two", "three", "four", "five",          "six", "seven", "eight", "nine", "ten", "jack", "queen", "king"}       dim suits() string = {"hearts", "diamonds", "clubs", "spades"}         currentcard = 0 ' set currentcard first card dealt deck(0)            dim deck(51) card         dim cardposition integer = 0          'loop through each suit , each value in suit setting 1 of deck            each suit card.cardsuit in [enum].getvalues(gettype(card.cardsuit))             each value card.cardvalue in [enum].getvalues(gettype(card.cardvalue))                 deck(cardposition) = new card(value, suit)                 cardposition += 1             next         next       end sub ' new     ' shuffle deck of cards simple one-pass algorithm    public sub shuffle()       ' after shuffling, dealing should start @ deck(0) again       currentcard = 0 ' reinitialize currentcard        ' each card, pick random card , swap them       first = 0 deck.getupperbound(0)          ' select random number between 0 , 51          dim second integer = randomnumbers.next(number_of_cards)           ' swap current card randomly selected card          dim temp card = deck(first) ' store copy of deck(first)          deck(first) = deck(second) ' move deck(second) deck(first)          deck(second) = temp ' move original deck(first) deck(second)       next    end sub ' shuffle     ' deal 1 card    public function dealcard() card       ' determine whether cards remain dealt       if currentcard <= deck.getupperbound(0)          dim lastcard integer = currentcard ' store current card number          currentcard += 1 ' increment current card number          return deck(lastcard)       else          return nothing ' no more cards deal         end if        end function ' dealcard   end class ' deckofcards 

i can see in getcardimage function, using card.tostring().replace(" ", "") name of card image name resource.

since didn't provide how card images named in resource, i'll assume named follows:

club1   spade1   heart1   diamond1    --> aces of each suit club2   spade2   heart2   diamond2    --> two's of each suit .       .        .        . .       .        .        . .       .        .        . club13  spade13  heart13  diamond13   --> kings of each suit 

in general, each card named {suitname}{facevalue}.

inside card class, add following overrides:

public overrides function tostring() string   dim suit string = ""    select case me.suit     case cardsuit.clubs : suit = "club"     case cardsuit.diamonds : suit = "diamond"     case cardsuit.hearts : suit = "heart"     case cardsuit.spades : suit = "spade"   end select    dim value string = cint(me.value).tostring    return suit & value end function 

inside getcardimage function, name of card image using card.tostring(), no need replace() since formatted name in overrides above.

my code above solely based on assumption of how card images named in resource (ie. {suitname}{facevalue} format). if use different naming format, have modify overrides function return matching card image name each card suit/values.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -