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.
|
|
|
|
|
![]() |
||
Array for a deck of cards
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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. |
|
|
|
|||
|
Re: Array for a deck of cards
How far have you got at the moment?
|
|
|||
|
Re: Array for a deck of cards
Nowhere at the moment. I'm still trying to work out how everything can be done using JavaScript...
|
|
|||
|
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. |
|
|||
|
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? |
|
|||
|
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! |
![]() |
| Tags |
| array, cards, deck, javascript |
| Thread Tools | |
|
|
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 |