ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 30th, 2005, 09:56 PM
Tyler7282 Tyler7282 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 50 Tyler7282 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 28 m 34 sec
Reputation Power: 4
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.

Reply With Quote
  #2  
Old October 5th, 2005, 02:08 PM
Alas's Avatar
Alas Alas is offline
Wickedwd.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: wickedwd.com
Posts: 187 Alas Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 17 h 32 m 22 sec
Reputation Power: 0
Black jack in CF kinda boring me thinks any game worthwhile should be made in Flash,

just my opinion,
-Alas
Comments on this post
jamieB disagrees: If he wants to learn how it's done who cares if you think it's boring?

Reply With Quote
  #3  
Old October 5th, 2005, 02:37 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
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

Reply With Quote
  #4  
Old October 5th, 2005, 02:45 PM
crownjewel82's Avatar
crownjewel82 crownjewel82 is offline
rebel with a cause
Dev Shed God (5000 - 5499 posts)
 
Join Date: May 2004
Location: The Batsh!t Crazy State.
Posts: 5,399 crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 17th Grade (Above 100000 Reputation Level)  Folding Points: 40517 Folding Title: Beginner FolderFolding Points: 40517 Folding Title: Beginner FolderFolding Points: 40517 Folding Title: Beginner Folder
Time spent in forums: 2 Months 3 Weeks 6 Days 14 h 22 m 3 sec
Reputation Power: 2120
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

Reply With Quote
  #5  
Old October 6th, 2005, 07:09 PM
Tyler7282 Tyler7282 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 50 Tyler7282 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 28 m 34 sec
Reputation Power: 4
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. :$

Reply With Quote
  #6  
Old October 6th, 2005, 08:19 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Need help starting a card game..


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT