Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Please help with my blackjack javascript game

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help with my blackjack javascript game

    Ok basically i am making a blackjack game and so far i have a random generator for my cards, once i press deal 4 cards are dealt at random, but when i try to insert a new button for the player to press for another card "hit", the card comes down and is not random at all. I could really do with this help. Thank you.



    <html>

    <HEAD>



    <SCRIPT LANGUAGE="JavaScript">



    var deck=new Array; var hand=new Array(53); var hcrd=new Array(53); var hsut=new Array(53);

    var isPlaying=-1; var betn=1; var dpos=0; var crdts; var ncard=0;



    /* ----------------------------------------------------------------------------------------- */



    function initdeck(){

    crd=0;

    for(i=0;i<4;i++){

    if(i==0){st="club";} else if(i==1){st="heart";} else if(i==2){st="diamond";}else{st="spade";}

    for(c=1;c<14;c++){

    if(c==1){num="ace";}else if(c==11){num="jack";}

    else if(c==12){num="queen";}else if(c==13){num="king";}else{num=c;}

    deck[crd++]=st+"|"+num;

    } //for c

    } //for i

    }





    /* ----------------------------------------------------------------------------------------- */

    function showcard(cnum)

    {

    p = hand[cnum].indexOf("|");

    s = hand[cnum].substring(0,p);

    c = hand[cnum].substring(p+1,hand[cnum].length);



    if(cnum==0){document.images.card1.src="cards/"+s+c+".jpg";}

    else if(cnum==1){document.images.card2.src="cards/"+s+c+".jpg";}

    else if(cnum==2){document.images.card3.src="cards/"+s+c+".jpg";}

    else if(cnum==3){document.images.card4.src="cards/"+s+c+".jpg";}



    else{document.images.card11.src="cards/"+s+c+".jpg";}

    }



    function hit(ncard)

    {





    p = hand[ncard].indexOf("|");

    s = hand[ncard].substring(0,p);

    c = hand[ncard].substring(p+1,hand[ncard].length);



    if(ncard==4){document.images.card5.src="cards/"+s+c+".jpg";}

    else if(ncard==5){document.images.card6.src="cards/"+s+c+".jpg";}

    else if(ncard==6){document.images.card7.src="cards/"+s+c+".jpg";}





    }



    function stand()

    {



    document.images.card8.src="cards/"+s+c+".jpg";





    }





    function deal()

    {

    if(isPlaying < 0)

    { // new game

    dpos = 0; isPlaying=1;



    for(i=0;i<500;i++)

    { //shuffle the cards(mix up the deck)

    tmp = Math.round(Math.random()*51); tmp2= Math.round(Math.random()*51);

    stmp = deck[tmp]; deck[tmp] = deck[tmp2]; deck[tmp2] = stmp;

    }





    for(i=0;i<53;i++)

    {

    hand[i]=deck[dpos++];showcard(i);

    hand[i]=deck[dpos++];hit(i);

    }



    }



    }











    function quit(){window.close();}

    /* ----------------------------------------------------------------------------------------- */

    initdeck();

    // End -->

    </script>



    </HEAD>

    <BODY>

    <table>

    <tr><form name="drwcrd">



    <td width=590></td>

    <td><b>Computer</b></td>

    </tr><tr></form>



    <table>

    <tr><form name="drwcrd">



    <td width=500></td>

    <td width=30 align=center><img name="card1" src="cards/cardback.jpg"></td>

    <td width=30 align=center><img name="card3" src="cards/cardback.jpg"></td>





    <td width=30 align=center><img name="card8" src=""></td>

    <td width=30 align=center><img name="card9" src=""></td>

    <td width=30 align=center><img name="card10" src=""></td>





    <table>

    <tr><form name="drwcrd">



    <td width=590></td>

    <td><b>Player</b></td>

    </tr><tr></form>



    <table>

    <tr><form name="drwcrd">
    <td width=500></td>
    <td width=30 align=center><img name="card2" src="cards/cardback.jpg"</td>
    <td width=30 align=center><img name="card4" src="cards/cardback.jpg"</td>
    <td width=30 align=center><img name="card5" src=""</td>
    <td width=30 align=center><img name="card6" src=""</td>
    <td width=30 align=center><img name="card7" src=""</td>
    </tr><tr></form>
    <table>
    <tr><td><input type="button" value ="DEAL Cards" onClick="javascript:deal();"></td>
    <td><input type="button" value ="Hit" onClick="javascript:hit();"></td>
    <td><input type="button" value ="Stand" onClick="javascript:stand();"></td>
    </body>
    </html>









    if anyone has any help id be grateful or if anyone has any ideas on how to approach this differently. thanks in advance


  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help with my blackjack javascript game

    please excuse the code its a little messy atm. sorry

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please help with my blackjack javascript game

    If you'd convert it to a java program, there would be more chances of someone helping.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help with my blackjack javascript game

    I would but I chose to make it a javascript due to this game being uploaded onto a website and i cant have the game still running if the site is down. thanks

Similar Threads

  1. Please help with my blackjack javascript game
    By bigmanjames in forum Other Programming Languages
    Replies: 3
    Last Post: April 22nd, 2012, 02:06 PM
  2. Java BlackJack game
    By kas123 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 19th, 2012, 11:43 AM
  3. Blackjack game
    By roscowgo in forum Java Theory & Questions
    Replies: 5
    Last Post: January 17th, 2012, 12:21 PM
  4. How to add card images to Blackjack game??
    By Jayc44 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 15th, 2011, 12:43 PM
  5. Help with blackjack game
    By santosd1118 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 12th, 2010, 12:55 AM