Results 1 to 13 of 13

Thread: Card Games

  1. #1

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372

    Card Games

    Hi All.

    I've started writing a very basic game of 21. I'm just using shapes and labels to make up the cards. I did a quick search for other 21 games and found one similar the the type I want to write. The code is a bit on the long side though. Is there an easier way of doing this? I was thinking of using an array for the cards but I could use a point in the right direction.
    I've attached the form I found. It looks like it still needs a lot of work but I'm only interested in how to use and call the cards, without spending the next three weeks typing the code.

    If anyone knows of any step by step guides that would be great too.
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

  2. #2

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    DOH!

    here's the form.
    Attached Files Attached Files
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

  3. #3
    Junior Member
    Join Date
    Aug 2002
    Location
    Sydney
    Posts
    16
    Hi, I haven't actually looked at the form (sorry, I don't have enough time), but something you might wish to have a look at is this tutorial over here:

    http://rookscape.com/vbgaming/tutU.php

    It is a *bit* more advanced than using shapes and labels, but you might be a lot more pleased with the look of your program by using it. It describes how to use the same 'deck' of cards which the windows card games like solitaire use. Included is a demo of a certain card game (I'm not sure which one ), which will give you a fairly good idea as to how to actually implement the tutorial.

    Also, don't be put off about the length of code, some of the simplest code you can write would be pages long, and I've written some single liners which would bamboozle you for months . Blackjack is a good project to work on because there are a couple of nice problems to solve, and there are different ways of doing so, you might find a way of doing it which you find is a lot neater/shorter/nicer/faster than the way you see.
    Trying is the first step towards failure

  4. #4

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    Thanks.

    I checked out the site and downloaded the card game, but it was too hard to follow. I need a dummies guide.
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

  5. #5
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    299
    I would reccomend making a Deck class. Write member functions to create the cards, shuffle the deck, cut the deck, and a way to access an array of 52 cards. I would also make a Card UDT to isolate indiviual cards. When taking cards, keep a static variable of the card that is to be drawn, and increment it when was is taken. Once you have a good card class, you have it made because the rest is just like writing out the rules of a game.

  6. #6

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    Hi, a deck class sounds about right.
    What do you mean by a Card UDT?
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

  7. #7
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    I wrote a deck shufling program,

    It only uses random, which some people will argue till they are blue in the face is not random enough, but check it out:
    Attached Files Attached Files
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  8. #8
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    299
    nice code rat. I've got some ancient code here that shuffles a deck pretty well. [edit] make iteration very high for better shuffling. Arround 100000 works ver nicely.[/edit]

    VB Code:
    1. Type Card
    2.      CardName as String
    3.      CardValue as Long
    4.      SuitIndex as Long
    5. End Type
    6.  
    7. Dim Cards(51) as Card
    8.  
    9. Sub Shuffle(iterations as Long)
    10. Dim replaceBuff as Card, lCounter1 as Long,Index1 as Long, Index2 as Long
    11. Randomize
    12.      For lCounter1 = 1 to iterations Step 1
    13.           Index1=Int(Rnd*52)
    14.           Index2=Int(Rnd*52)
    15.           replaceBuff = Cards(Index1)
    16.           Cards(Index1)=Cards(Index2)
    17.           Cards(Index2)=replaceBuff
    18.      Next lCounter1
    19. End Sub

  9. #9

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    What about this for a shuffle?
    Code:
    Private Sub ShuffleCards()
    Dim TempValue As Integer
    Dim LoopCounter As Integer
    Dim ItemPicked As Integer
    Dim Remaining As Integer
    
    'One Card Shuffle
    'Initialize CardNumber
    For LoopCounter = 1 To 52
        CardNumber(LoopCounter) = LoopCounter
    Next LoopCounter
    
    'Work through remaining values
    For Remaining = 52 To 2 Step -1
        ItemPicked = Int(Rnd * Remaining) + 1
        TempValue = CardNumber(Remaining)
        CardNumber(Remaining) = CardNumber(ItemPicked)
        CardNumber(ItemPicked) = TempValue
    Next Remaining
    End Sub
    This is the code that's in my course book.
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

  10. #10
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Mine could be pretty easily modified to use iterations also
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  11. #11

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    erm, excuse my ignorance, but what is "iterations"?
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

  12. #12
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Basically, the code would shuffle, then shuffle the shuffle, then shuffle the shuffled shuffle for a specified number of times.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  13. #13

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    So, there's a whole lotta shufflin goin on
    How is it one careless match can start a forest fire, but it takes a whole box to start a campfire?

    Global Freelancers | Web Traffic Analyser

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width