Jump to content
  • Advertisement

Rayj00

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

110 Neutral

About Rayj00

  • Rank
    Newbie
  1. Rayj00

    New Game Programmer!

    I have a for loop.  It should finish when it gets to 52.  That's the problem, it NEVER gets to 52..  The fix should be simple.  I can't figure it out.  Can you?
  2. Ok I am pulling my hair out on this one. I am trying to intialize an array size 52 with random numbers that represent a deck of cards.   A loop should count from 0-51 but it stops at various random values.  I am using document.write to trouble shoot.  As of now, calling the page will generate a numbered list of random numbers.  It should show 52 numbers but never does.   Here is the code.  Help a guy out please?   Thanks.   <html> <head> <script type="text/javascript" language="JavaScript"> function shuffle() { //document.write("Got in shuffle" + "<br>"); var i; var num; // Holds the generated random number var card; var deck_array = []; // 52 card deck var dup_array = []; // This array used to track the generated number //Don't know whether I need to initialize the arrays or not? But won't hurt. for (i = 0; i < 52; i++) { dup_array = 0; deck_array = 0;} //This loop is for initializing a 52 card deck for (card = 0; card < 52; card++){ getRndNmbr: num = Math.floor((Math.random() * 52) + 1); document.write(card + " "); // Check for duplicate numbers. Initially the dup_array should be all zeros. // When a random number is generated, set that numbers dup location to “1” to indicate // that this number was already generated and we need to generate another number. // If this number was not generated before, set the dup location to “1” and set the // deck_array current card location to the random number. // If dup_array[num] is a "1", number was already picked, get another if (dup_array[num] == 1) { getRndNmbr;} // num was never generated. Set current location in the deck to num // Populate the deck top to bottom deck_array[card] = num; document.write(deck_array[card] + " " + "<br>"); // Set the dup indicator so we don't pick the same number again dup_array[num] = 1; // document.write(dup_array[card] + " "); // document.write(dup_array[num] + " ");                             }                                   } // end shuffle </script> </head> <body> <script type="text/javascript" language="JavaScript"> shuffle(); </script> </body> </html>
  3. Rayj00

    New Game Programmer!

    Ok I am pulling my hair out on this one. I am trying to intialize an array size 52 with random numbers that represent a deck of cards.   A loop should count from 0-51 but it stops at various random values.  I am using document.write to trouble shoot.  As of now, calling the page will generate a numbered list of random numbers.  It should show 52 numbers but never does.   Here is the code.  Help a guy out please?   Thanks.   <html> <head> <script type="text/javascript" language="JavaScript"> function shuffle() { //document.write("Got in shuffle" + "<br>"); var i; var num; // Holds the generated random number var card; var deck_array = []; // 52 card deck var dup_array = []; // This array used to track the generated number //Don't know whether I need to initialize the arrays or not? But won't hurt. for (i = 0; i < 52; i++) { dup_array = 0; deck_array = 0;} //This loop is for initializing a 52 card deck for (card = 0; card < 52; card++){ getRndNmbr: num = Math.floor((Math.random() * 52) + 1); document.write(card + " "); // Check for duplicate numbers. Initially the dup_array should be all zeros. // When a random number is generated, set that numbers dup location to “1” to indicate // that this number was already generated and we need to generate another number. // If this number was not generated before, set the dup location to “1” and set the // deck_array current card location to the random number. // If dup_array[num] is a "1", number was already picked, get another if (dup_array[num] == 1) { getRndNmbr;} // num was never generated. Set current location in the deck to num // Populate the deck top to bottom deck_array[card] = num; document.write(deck_array[card] + " " + "<br>"); // Set the dup indicator so we don't pick the same number again dup_array[num] = 1; // document.write(dup_array[card] + " "); // document.write(dup_array[num] + " ");                             }                                   } // end shuffle </script> </head> <body> <script type="text/javascript" language="JavaScript"> shuffle(); </script> </body> </html>
  4. Rayj00

    Broken code

    So I have this code:    var final; // random number var card; // loops 52 times to create a random deck of cards (values) //code to generate random numers   // This code works and outputs 52 random numbers deck_array[card] = final; document.write(deck_array[card] + " ");   // But this code returns undefined 52 times: deck_array[card] = final; document.write(deck_array[final] + " ");   Why?  
  5. Actually, I am totally green!  I know enough about programming to be dangeous.   I am an avid Hearts game player, I saw an online Hearts game the did not require any downoads or installs,  It plays strictly through the browser. It uses pixi.js for graphics.   It's pretty awesome and fast.   Anyway, I'd like to program a Hearts game.  I have a few ideas to improve what is generally available online. It will be HTML5 compliant.  Along with a lot of custom Javascript programming, I am thinking I will need either Websockets or sockit.io?   Right now I am looking at the easy stuff (graphics) and how to actually deal the cards out.    Is this the place to ask about client/server issues?  I have no idea how to deal cards to 4 players so each player can only see his own cards? That's just one issue I will be facing.   If you have ideas for me I would appreciate it.   Thanks, Ray
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!