iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old February 2nd, 2007, 04:23 PM   #1
New Member
 

Join Date: Feb 2007
Location: UK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 gerryflockhart is on a distinguished road
Array for a deck of cards

Hello,

I am a bit of a novice at JavaScript but am trying to make a simple card game. Unfortunately, I've fallen at the first hurdle which is to make a standard deck of cards (I'm guessing as an array) and then randomly split the deck into 2 random piles, A and B (each will therefore be of size 26).

Does anyone know how I might do this? Or be kind enough to point me in the right direction for the best approach.

Many Thanks.
gerryflockhart is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old February 2nd, 2007, 06:16 PM   #2
Reputable Member
 

Join Date: Jul 2006
Location: Scotland
Age: 23
Posts: 355
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 snow is on a distinguished road
Re: Array for a deck of cards

How far have you got at the moment?
snow is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old February 2nd, 2007, 07:01 PM   #3
New Member
 

Join Date: Feb 2007
Location: UK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 gerryflockhart is on a distinguished road
Re: Array for a deck of cards

Quote:
Originally Posted by snow View Post
How far have you got at the moment?
Nowhere at the moment. I'm still trying to work out how everything can be done using JavaScript...
gerryflockhart is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old February 5th, 2007, 07:07 PM   #4
Most Reputable Member
 

Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,307
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 ukgeoff has a spectacular aura about ukgeoff has a spectacular aura about
Re: Array for a deck of cards

Start with an array of the numbers 1 - 52 which represent the pack.

Have a random generate a number between 1 and the length of this array.

Have two other arrays for your two halves of the pack.

Remove the number from the pack array at the cell location generated and place it into one of the smaller arrays.

Removing the number from the pack array reduces its length by one.

Repeat the sequence, each time placing the number chosen into the opposite small array than last time.

Eventually the pack array will be empty and you will have two arrays of 26 numbers, each representing half the pack, randomly chosen.
ukgeoff is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old February 8th, 2007, 05:17 PM   #5
New Member
 

Join Date: Feb 2007
Location: UK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 gerryflockhart is on a distinguished road
Re: Array for a deck of cards

Thanks so much for all your help. I seem to have a function that shuffles the cards now... although, I now have a different problem.

I am trying to output from the array to a textarea. When I do, the output is not going over multiple lines even though I have set the properties of the textarea to have 3. Does anyone know how to make the output go onto a different line when the top line is full?
gerryflockhart is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old February 11th, 2007, 11:39 AM   #6
New Member
 

Join Date: Feb 2007
Location: UK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 gerryflockhart is on a distinguished road
Re: Array for a deck of cards

I've sorted this problem out now. It seems Firefox would keep everything on one line, but IE uses multiple lines.

I am making progress (albeit slow)...

Does anyone know how to make a function so that when a button is pressed, the computer puts the card from their deck down, and when the button is pressed again, the human player puts their card down... and so on..?

Thanks in advance!
gerryflockhart is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
array , cards , deck , javascript


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
e-cards aslanandbeez Flash and ActionScript 2 April 26th, 2008 12:51 PM
Sorting a new array from an existing array Ozeona Flash and ActionScript 2 September 20th, 2005 05:43 AM
array unable to check another array so as to be displayed Ozeona Flash and ActionScript 1 August 5th, 2005 07:26 AM
E Cards Help Andy_H HTML, XHTML and CSS 1 February 25th, 2005 07:38 PM


Search Engine Optimization by vBSEO 3.2.0 RC8