|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help starting a card game..
Hey all, I am fairly new to CF. I am wanting to make a simple text based version of blackjack.. player against player. I was just wondering if you could give me a little jump starting out, just dealing the cards or whatnot... Should I store them in lists or what would be most efficient in keeping it fair? I am using sessions on my site, so sessions would work for me.. I don't know where to start, just can't think.
![]() |
|
#2
|
||||
|
||||
|
Black jack in CF kinda boring me thinks any game worthwhile should be made in Flash,
just my opinion, -Alas |
|
#3
|
|||
|
|||
|
It can be an interesting learning experience to build such a game, but I'm not really sure what you are asking. Without something more specific it's hard to give advice. What have you come up with?
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#4
|
||||
|
||||
|
I would advise that you not begin programming in any language with something so complex as a game.
But, If you really want to. I would advise getting to know what components (cfc) are. I would find that sort of thing easiest on an object oriented type rout. Also I would invest some time in learning stacks and/or queues. Again I wouldnt advise this type of undertaking unless you're able to write this in an actual programming language (ie. Java). Even simple games are very complicated and it's not best for a markup language like CF. Suggestions: Write a trivia program. Try to build a simple blog or photo album. You can add features as you learn new things.
__________________
Don't really care who you vote for but go vote. Early voting has started in several places. Election day is November 4. being healthier the hard way CJ @ Flickr |
|
#5
|
|||
|
|||
|
I'm sure it will be boring, but that isn't the point of the project..
![]() Kiteless, i have looked through the list functions and here is how i have it dealing so far, please let me know if there is a better way. I'm sure there is as i get the error once in a while: Invalid list index 51. In function ListGetAt(list, index [, delimiters]), the value of index, 51, is not a valid as the first argument (this list has 48 elements). Valid indexes are in the range 1 through the number of elements in the list. here is the code for dealing the first player: Code:
<cfset session.Cards = 'Ace of Spades, Ace of Hearts, Ace of Clubs, Ace of Diamonds, Two of Spades, Two of Clubs, Two of Diamonds, Two of Hearts, Three of Spades, Three of Clubs, Three of Diamonds, Three of Hearts, Four of Spades, Four of Clubs, Four of Diamonds, Four of Hearts, Five of Diamonds, Five of Hearts, Five of Clubs, Six of Diamonds, Six of Hearts, Six of Clubs, Six of Spades, Seven of Hearts, Seven of Spades, Seven of Clubs, Seven of Diamonds, Eight of Hearts, Eight of Diamonds, Eight of Hearts, Eight of Clubs, Nine of Diamonds, Nine of Hearts, Nine of Clubs, Nine of Spades, Ten of Hearts, Ten of Clubs, Ten of Spades, Ten of Diamonds, Jack of Hearts, Jack of Diamonds, Jack of Clubs, Jack of Spades, Queen of Hearts, Queen of Diamonds, Queen of Clubs, Queen of Spades, King of Diamonds, King of Hearts, King of Clubs, King of Spades'> <cfparam name="session.player1cards" default=""> <cfloop from="1" to="5" index="i"> <cfset Random = RandRange(1,56)> <cfset deal = #ListGetAt(session.cards, '#Random#')#> <cfset session.player1cards = ListAppend(session.player1cards, "#deal#")> <cfset session.Cards = ListDeleteAt(session.Cards, "#Random#")> </cfloop> <cfoutput>#session.player1cards#</cfoutput> am i on the right track? i do not know how to go about storing this information for both players, i am only familiar with sessions.. and i'm not sure that would work in this instance. Thanks for being patient with me. :$ |
|
#6
|
|||
|
|||
|
I whipped this up in a few minutes to show how I would start. This will probably be way over your head right now since it uses a CFC to model the game functions and follows numerous conventions and best practices that have evolved around using CFCs. I was hoping that it might illustrate how you could do different things, and also hoping to demonstrate some more advanced techniques that you may come back to once you are more familiar with the language.
Calling code... Code:
Initializing game...<br /> <cfset cardGame = createObject( 'component', 'CardGame' ).init() /> Game initialized...<br /><br /> Dealing 5 cards...<br /> <cfoutput>#cardGame.dealCards( 5 )#</cfoutput> CardGame.cfc code... Code:
<cfcomponent name="CardGame" hint="I model a simple card game."> <cffunction name="init" access="public" returntype="CardGame" hint="Constructor."> <cfset resetDeck() /> <cfreturn this /> </cffunction> <cffunction name="resetDeck" access="public" returntype="void" output="false" hint="Builds the deck of cards."> <cfset var local = structNew() /> <cfset variables.instance.deck = arrayNew(1) /> <cfset local.suitList = "Spades,Hearts,Clubs,Diamonds" /> <cfset local.cardValueList = "2,3,4,5,6,7,8,9,10,Jack,Queen,King,Ace" /> <cfloop list="#local.suitList#" index="local.thisSuit"> <cfloop list="#local.cardValueList#" index="local.thisValue"> <cfset arrayAppend( variables.instance.deck, structNew() ) /> <cfset local.currentDeckSize = arrayLen( variables.instance.deck ) /> <cfset variables.instance.deck[local.currentDeckSize].suit = local.thisSuit /> <cfset variables.instance.deck[local.currentDeckSize].value = local.thisValue /> </cfloop> </cfloop> <cfset variables.instance.usedCardList = "" /> </cffunction> <cffunction name="dealCards" access="public" returntype="string" output="false" hint="Deals out the specified number of cards."> <cfargument name="numberOfCards" type="numeric" required="true" hint="Number of cards to deal." /> <cfset var local = structNew() /> <cfset local.dealtCardOutput = "" /> <cfloop from="1" to="#arguments.numberOfCards#" index="local.thisDealCard"> <!--- Get a new card and determine it's suit and value ---> <cfset local.currentCard = getCard() /> <cfset local.currentCardSuit = variables.instance.deck[local.currentCard].suit /> <cfset local.currentCardValue = variables.instance.deck[local.currentCard].value /> <!--- Add the current card to the output text. ---> <cfset local.dealtCardOutput = local.dealtCardOutput & "The #local.currentCardValue# of #local.currentCardSuit#<br />" /> </cfloop> <cfreturn local.dealtCardOutput /> </cffunction> <cffunction name="getCard" access="private" returntype="any" output="false" hint="Get one card that hasn't been dealt yet."> <cfset var local = structNew() /> <!--- Pick a random card. ---> <cfset local.currentCard = randRange( 1, 52 ) /> <!--- If the current card has not already been dealt we can use it and add it to the list of used cards. ---> <cfif not listFind( variables.instance.usedCardList, local.currentCard )> <cfset variables.instance.usedCardList = listAppend( variables.instance.usedCardList, local.currentCard ) /> <!--- Otherwise, call getCard() recursively until we get to a card that hasn't been used ---> <cfelse> <cfset local.currentCard = getCard() /> </cfif> <cfreturn local.currentCard /> </cffunction> </cfcomponent> Last edited by kiteless : October 6th, 2005 at 08:52 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Need help starting a card game.. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|