Results 1 to 7 of 7
  1.    #1  
    Ok lemme give some background on what I want to do...


    Basically I'm making a form of blackjack game and need some help with some of the code I'm writing..

    For now i'm going to ignore all factors like how many players, the card suits etc..

    I'm, at the moment , focusing on just the deal.


    So what I believe I need for the deal is (broken in steps)


    1) set player "score" to zero

    2) "deal" player random "card"

    3) update "score"

    4) if "score" is <21 deal another random "card"

    5) add the new random card amount to the last score amount

    6) if "score" is =21 stop

    6a) else go back to step 2

    7) else if "score"is >20 alert("you lose")
    ------------------------------------------------------------------------

    now I want to call upon this section of code whenever I want so I set it up as a function. However I can't seem to figure out how to continually update the score with the value of the random card. I believe I have to use the for loop, but that doesn't seem to make sense, since I only understand the for loop to be a sort of "counter" (do X for n amount of times as long as condition y is true)



    Any help would be much appreciated.

    -- Sent from my TouchPad using Communities
  2. #2  
    Read this over and see if it helps:


    Set score to Zero in setup function or somewhere else.

    /* call myScoreFunction on screen tap
    Or by Pressing deal card button */


    myScoreFunction ()
    {

    // create random number here

    score = score + randNum;

    if (score == 21)
    {
    // you win
    score = 0;
    }
    else
    {
    // you loose
    score = 0;
    }


    /*
    Note:
    if (score < 21) we Do nothing
    and
    Keep score for next deal card screen tap to call the myScoreFunction again

    */


    }


    Or another way to look at it is*


    while ( ! ( score >= 21) )*// while score is Not >= 21
    {
    // create random number here
    score = score + randNum;
    /* this has no pause and will repeat to be
    equal to or higher than 21 before exiting while loop */
    }
    if (score == 21)
    {
    // you win
    score = 0;
    }
    else
    {
    // you loose
    score = 0;
    }
    Last edited by djgardn2; 12/20/2011 at 11:44 AM.
    If you like any of my patches or apps, donations are appreciated. PayPal Link
    All Donations go towards my college classes & I want to thank anyone that purchases my apps or considers donating to me.
    -- 12 patches & 40 save/restore scripts.
    -Apps-
    Paid:
    Days To Come, Days Gone By, Quick-Keys Keyboard, Days Till Christmas, Days Till Christmas HD, Days Till New Year, Days Till New Year HD
    Free:
    Night Light Timer, webOS Launcher
  3.    #3  
    Read this over and see if it helps:


    Set score to Zero in setup function or somewhere else.

    /* call myScoreFunction on screen tap
    Or by Pressing deal card button */


    myScoreFunction ()
    {

    // create random number here

    score = score + randNum;

    if (score == 21)
    {
    // you win
    score = 0;
    }
    else
    {
    // you loose
    score = 0;
    }


    /*
    Note:
    if (score < 21) we Do nothing
    and
    Keep score for next deal card screen tap to call the myScoreFunction again

    */


    }


    Or another way to look at it is*


    while ( ! ( score >= 21) )*// while score is Not >= 21
    {
    // create random number here
    score = score + randNum;
    /* this has no pause and will repeat to be
    equal to or higher than 21 before exiting while loop */
    }
    if (score == 21)
    {
    // you win
    score = 0;
    }
    else
    {
    // you loose
    score = 0;
    }
    Thanks for the response... I actually have a similar code I wrote up but can't see the score updating.. :-\


    This is what I have

    function random (number) {
    if (number < 10) {
    alert("You Suck, You need to get 21")
    }
    else if (number > 10 && randomCard <= 20){
    alert("Almost There...")
    }
    else {
    alert("You got 21!!!")
    }
    }

    var score = 0;
    var randomCard = Math.floor(Math.random () * 21 + 1);
    var fRandom = random(randomCard);
  4. #4  
    I don't know where you placed this code:

    var score = 0;
    var randomCard = Math.floor(Math.random () * 21 + 1);
    var fRandom = random(randomCard);


    but you can try adding/looking at this code

    if (score >= 21)
    {
    score = 0;
    }
    else
    {
    score = randomCard + score;
    }

    You may be setting score to 0 everytime its called depending how you set it up.


    Also maybe look at this

    function random (number) {
    if ( score < 10) {
    alert("You Suck, You need to get 21")
    }
    else if (score >= 10 && score <= 20 ){
    alert("Almost There...")
    }
    else {
    alert("You got 21!!!")
    }
    }
    If you like any of my patches or apps, donations are appreciated. PayPal Link
    All Donations go towards my college classes & I want to thank anyone that purchases my apps or considers donating to me.
    -- 12 patches & 40 save/restore scripts.
    -Apps-
    Paid:
    Days To Come, Days Gone By, Quick-Keys Keyboard, Days Till Christmas, Days Till Christmas HD, Days Till New Year, Days Till New Year HD
    Free:
    Night Light Timer, webOS Launcher
  5.    #5  
    Quote Originally Posted by djgardn2 View Post
    I don't know where you placed this code:
    var score = 0;
    var randomCard = Math.floor(Math.random () * 21 + 1);
    var fRandom = random(randomCard);

    but you can try adding/looking at this code
    if (score >= 21) {
    score = 0; }
    else { score = randomCard + score;
    }

    You may be setting score to 0 everytime its called depending how you set it up.
    Hmm this makes more sense, I'll need to look this over.

    so according to this I still would need to set up a variable of score .. But not give it a value?

    var score; ?

    Quote Originally Posted by djgardn2 View Post
    Also maybe look at this
    function random (number) {
    if ( score < 10) {
    alert("You Suck, You need to get 21")
    }
    else if (score >= 10 && score <= 20 ){
    alert("Almost There...")
    }
    else { alert("You got 21!!!")
    }
    }
    I actually had it this way (or something like it) but where does score update there.. I see it checking score is 21 or not but where does it update ..
  6. #6  
    Depending on your code this may work or give you insight on things to try. Hopefully between looking at the three posts you might be about to piece it together.

    function random (number) {

    score = (randomCard + score) ; /*this will update or add rand# to score, assuming score is set to zero, somewhere else in your app */


    if ( score < 10) {
    alert("Not enough, You need to get 21")
    }
    else if (score >= 10 && score <= 20 ){
    alert("Almost There...")
    }
    else { alert("You got 21!!!")
    }
    }
  7.    #7  
    Ok... I really need to examine all this... (come on work... End already!!!!)

    So I can play with it more.. Thank you so much..

    -- Sent from my TouchPad using Communities

Posting Permissions