FAQ Search Memberlist Usergroups
Jolt Country Forum Index
Register Profile Log in to check your private messages Log in
Log in Log in

Deal Cards

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Jolt Country Forum Index -> Hugo's House of Horrors
View previous topic :: View next topic  
Author Message
Tdarcos



Joined: 16 May 2008
Posts: 4441
Location: University Park, Maryland

PostPosted: Sun Feb 24, 2013 12:35 pm    Post subject: Deal Cards Reply with quote

This example shuffles a deck and displays the results. Can be used to create any game that requires a deck of cards.

Code:

!\---------------------------------------------------------------------------
!
! deal_cards.hug
! Demonstration of a method to create a shuffled deck
! Released by Viridian Development Corporation
!
! Paul Robinson 02/24/2013
! Last updated 00/00/0000
!
! Updates:
!
! 00/00/0000 -
!
!
---------------------------------------------------------------------------\!

#include "hugolib.h"

array usedcard[52]         ! To make sure the deck has no repeats
array Card [52]            ! Shuffled Deck

array cardname[13]         ! Ace Through King
array suitname[4]         ! H C D S

routine init
{

   suitname[1] = "Hearts","Clubs","Diamonds","Spades"
   cardname[1] = "Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"
   ShowGame
   
}

   
Routine Shuffle
{   
local this_card
local Index

   for (Index=1; Index<=52; Index++) ! Clear prior shuffle if any
     usedcard[Index] = FALSE
   
   for (Index=1; Index<=52; Index++)
   {
      this_card = random(52)
      while usedcard[this_card]=true         
      {
           this_card = random(52)
       }
      usedcard[this_card]=true
      card[Index]=this_card
   }
}
 
Routine Display_Card (Card_Number)
{
 local Card_Rank
 local Card_Suit
 
   Card_rank = mod(card[Card_Number], 13 )
   Card_suit = card[Card_Number] / 13 +1
   if Card_rank = 0
   {
      Card_suit = Card_suit - 1
      Card_rank = 13
   }

    print cardname[Card_rank]; " of ";suitname[Card_suit]
}

 
Routine Deal_Deck
{
local Index
 
   for (Index=1; Index<=52; Index++)
   {
      print "Card["; number Index ; "]=" ; number card[index];"  ";
     Display_Card(Index)
   }
}


routine main
{

}



Routine ShowGame
{   
   Shuffle
   Deal_Deck
   print "\n Press a key to deal again"
   Pause
   print " "
   Shuffle
   Deal_Deck
   print "\n Press a key to end"
   pause
   quit
}


_________________
The lessons of history teach us - if they teach us anything - that no one learns the lessons of history.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Jolt Country Forum Index -> Hugo's House of Horrors All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001 phpBB Group

Theme by Kage Musha - RPG Garden

Copyrights and trademarks are all of the belonging company. No copyright Infringement intended