Array for a deck of cards

This is a discussion on "Array for a deck of cards" within the JavaScript Forum section. This forum, and the thread "Array for a deck of cards are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 2nd, 2007, 19:23
New Member
Join Date: Feb 2007
Location: UK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote

  #2 (permalink)  
Old Feb 2nd, 2007, 21:16
Reputable Member
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to snow
Re: Array for a deck of cards

How far have you got at the moment?
Reply With Quote
  #3 (permalink)  
Old Feb 2nd, 2007, 22:01
New Member
Join Date: Feb 2007
Location: UK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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...
Reply With Quote
  #4 (permalink)  
Old Feb 5th, 2007, 22:07
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
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.
Reply With Quote
  #5 (permalink)  
Old Feb 8th, 2007, 20:17
New Member
Join Date: Feb 2007
Location: UK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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?
Reply With Quote
  #6 (permalink)  
Old Feb 11th, 2007, 14:39
New Member
Join Date: Feb 2007
Location: UK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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!
Reply With Quote
Reply

Tags
array, cards, deck, javascript

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 & Multimedia Forum 2 Apr 26th, 2008 15:51
Sorting a new array from an existing array Ozeona Flash & Multimedia Forum 2 Sep 20th, 2005 08:43
array unable to check another array so as to be displayed Ozeona Flash & Multimedia Forum 1 Aug 5th, 2005 10:26
E Cards Help Andy_H Web Page Design 1 Feb 25th, 2005 22:38


All times are GMT. The time now is 22:36.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43