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>


  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

    if anyone has any ideas for me to easily allow me to press a button and place a new card id be very grateful thanks

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Please help with my blackjack javascript game

    a) Please read the following
    http://www.javaprogrammingforums.com...e-posting.html
    I have moved your thread to the appropriate place
    b) java != javascript, and these forums are focused on java. Recommend trying your luck on a javascript dedicated forum.

  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

    hi there sorry im new to this, where did you place the post. thanks

Similar Threads

  1. Java BlackJack game
    By kas123 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 19th, 2012, 11:43 AM
  2. Blackjack game
    By roscowgo in forum Java Theory & Questions
    Replies: 5
    Last Post: January 17th, 2012, 12:21 PM
  3. 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
  4. BlackJack Game can"t figure out how to finsh it.
    By flurr in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 13th, 2011, 10:06 AM
  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