| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
NeverFuckWithoutaRubber
|
Jacascript Help
So I have an assignment and it's to create a "War" based card game. For those unfimiliar with it, basically you start out with a deck of cards and each person draws one card, the highest card wins and the winner keeps both cards until the game is over and then the cards are counted up and you see who wins. Ive been sifting through my notes/homework from the class aswell as the internet but I couldnt come up with anything. If anyone could point me in the right direction I would greatly appreciate it. |
|
|
|
|
|
#4 (permalink) | |
|
ExCoder
|
Quote:
Okey. First you should have all cards stored into an array. Some example code: Code:
Now you should mess up the order in the array before each new game. You can sort it by diff. criteria. Then you should split the array on half (one part for each player). Some example code: Code:
And you can start playing the game. You can compare the cards like this: Code:
If the statement is true player1 wins, otherwise player2 wins and you should run one extra check: Code:
In this case you have War. Basically this is how I would do it. Good luck. |
|
|
|
|
#5 (permalink) | |
|
Senior Member
|
Quote:
you could probably make it a bit easier on yourself by disreguarding suit considering suit does not matter in this game. Code:
|
|
|
|
|
#7 (permalink) | |
|
Senior Member
|
Quote:
|
|
|
|
|
#8 (permalink) |
|
NeverFuckWithoutaRubber
|
ok So I got the array setup; Code:
And I was looking for a Randomizing function which I thnk I found but didnt implement it right; Original: Code:
Mine: Code:
Am I doing it right or atleast coming close? |
|
|
|
#10 (permalink) | |
|
NeverFuckWithoutaRubber
|
Quote:
Why? Im not worried about file size or the extra time it would take to type it out; I want to keep this as simple as possible for me. Or is there a specific reason why this wouldnt work? |
|
|
|
|
#13 (permalink) |
|
NeverFuckWithoutaRubber
|
Code:
Better? |
|
|
|
#18 (permalink) |
|
ExCoder
|
Hi, As I can see, you have made the most of the game so far. Here is a simple demo of such kind of game I just wrote. It's not fully functional. Code:
Of course you can modify the code and make it better. In this version 'War!' is not detected and player 2 will win 95% of all games. You can improve the 'array split' code to split the array in better way. Good Luck |
|
|
|
#19 (permalink) |
|
NeverFuckWithoutaRubber
|
any help with that? Only thing I could come up with is this Javascript Tutorial - Split which seems would fit for what Im doing but I could be wrong. |
|
![]() |