Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy card game help please.

    i have the shuffling functions working but when i try to get it to move the cards i'm having trouble:

    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin

    function Shuffle(max){
    var num=Math.random()*max;
    return Math.round(num)+1;
    }

    function getSuit(){
    suit = Shuffle(4);
    if(suit == 1) return "Bows";
    if(suit == 2) return "Swords";
    if(suit == 3) return "Wands";
    else return "Lutes";
    }

    function getCard(){
    card = Shuffle(6)
    if(card == 1) return "One";
    if(card == 2) return "Two";
    if(card == 3) return "Three";
    if(card == 4) return "Four";
    if(card == 5) return "Five";
    else return "Six";
    }

    function displayDealerCard1(card, suit){
    document.display.deal1.value=(card + " of " + suit);
    return;
    }

    function displayDealerCard2(card, suit){
    document.display.deal2.value=(card + " of " + suit);
    return;
    }

    function displayDealerCard3(card, suit){
    document.display.deal3.value=(card + " of " + suit);
    return;
    }

    function displayPlayerCard(card, suit){
    document.display.you.value=(card + " of " + suit);
    return;
    }


    function NewHand(form){
    var dealerCard1 = getCard();
    var dealerCard2 = getCard();
    var dealerCard3 = getCard();
    var dealerSuit1 = getSuit();
    var dealerSuit2 = getSuit();
    var dealerSuit3 = getSuit();
    var playerCard = getCard();
    var playerSuit = getSuit();
    displayDealerCard1(dealerCard1, dealerSuit1);
    displayDealerCard2(dealerCard2, dealerSuit2);
    displayDealerCard3(dealerCard3, dealerSuit3);
    displayPlayerCard(playerCard, playerSuit);
    }

    function Crowned(playerCard, dealerCard1, playerSuit, dealerSuit1)
    {
    if ( (playerCard + dealerCard1) == 7)
    {
    dealerCard1 = "Crowned";
    dealerSuit1 = "";
    playerCard = getCard();
    playerSuit = getSuit();
    displayDealerCard1(dealerCard1, dealerSuit1);
    displayPlayerCard(playerCard, playerSuit);
    }
    else
    {
    alert("Not a valid move");
    }
    }



    // End -->
    </script>

    <BODY>

    <center>
    <form name="display">

    <table bgcolor="#c0c0c0" border="1" cellspacing="0" cellpadding="3">
    <tr>
    <td><input type=button value="Start" onClick="NewHand(form)"></td>
    <td>Dealer Card(1): <input type=text name="deal1" size="18" value=""></td>
    </tr>
    <tr>
    <td>Wins:</td>
    <td>Dealer Card(2): <input type=text name="deal2" size="18" value=""></td>
    </tr>
    <tr>
    <td><input type=text name="win" size="3" value="0"></td>
    <td>Dealer Card(3): <input type=text name="deal3" size="18" value=""></td>
    </tr>
    <tr>
    <td colspan=2>You have: <input type=text name="you" size="18" value=""> place it..?</td>
    </tr>
    <tr>
    <td colspan=2><center>
    <input type=button value="Card(1)" onClick="Crowned(); return false;">
    <input type=button value="Card(2)">
    <input type=button value="Card(3)"></center></td></tr>
    </table>

    </form>
    </center>

    as far as i know the function crowned should work, it's using the cards displayed and if the total seven it reassigns the variables and the tells it to display with those variables. like the newhand script does. but i get error when i use it... actually not an error all it does is pop up the "not valid move" alert.

    i uploaded it here if it's easier to check the script this way: http://delyria.united.net.kg/crowntest.html

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    okay you have a big problem.....the one thing is this

    function Crowned(playerCard, dealerCard1, playerSuit, dealerSuit1)


    That is the wrong way to call it

    just use

    function Crowned()


    Now you need to make your variables global so it can read the values....


    just add this to the top of the script

    <script>
    var dealerCard1;
    var dealerCard2;
    var dealerCard3;
    var dealerSuit1;
    var dealerSuit2;
    var dealerSuit3;
    var playerCard;
    var playerSuit;

    See if that helps


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •