card game javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Camblin

    card game javascript

    Has anyone got a script to run a higher or lower card game on a web page.

    Like the game show play you cards right.


  • Andrew Urquhart

    #2
    Re: card game javascript

    Gary Camblin wrote:[color=blue]
    > Has anyone got a script to run a higher or lower card game on a web
    > page.
    >
    > Like the game show play you cards right.[/color]

    <tongueinchee k>
    function Bruce_CardType( intCard) {
    switch (intCard) {
    case 1 :
    case 2 :
    case 3 :
    case 4 :
    case 5 :
    case 6 :
    case 7 :
    case 8 : return intCard + 1;
    case 9 : return "Jack";
    case 10 : return "Queen";
    case 11 : return "King";
    case 12 : return "Ace";
    default : null;
    }
    }
    function Bruce(intCurren tCard) {
    var intNewCard = Math.ceil(Math. random() * 12);
    var strNewCard = Bruce_CardType( intNewCard);
    if (typeof intCurrentCard != "number") {
    alert("Nice to see you, to see you, nice");
    alert("First card is a " + strNewCard);
    }
    else {
    var intHigherOrLowe r = Math.round(Math .random());
    var strCurrentCard = Bruce_CardType( intCurrentCard) ;
    if (intHigherOrLow er == 0) {
    alert((intCurre ntCard > 2 ? "Lower" : "Higher") + " than a " +
    strCurrentCard + "?");
    }
    else {
    alert((intCurre ntCard < 12 ? "Higher" : "Lower") + " than a " +
    strCurrentCard + "?");
    }
    if (intNewCard > intCurrentCard) {
    if (intHigherOrLow er == 0) {
    alert("Ohh! A " + strNewCard + ", it's higher! What a shame!");
    return;
    }
    else {
    alert("Yes! A " + strNewCard + "!");
    }
    }
    else {
    if (intNewCard == intCurrentCard) {
    alert("Lucky! Another " + strNewCard + "!");
    }
    else if (intHigherOrLow er == 0) {
    alert("Yes! A " + strNewCard + "!");
    }
    else {
    alert("Ohh! A " + strNewCard + ", it's lower! What a shame!");
    return;
    }
    }
    }

    setTimeout("Bru ce(" + intNewCard + ")", 1000);
    }
    Bruce();

    </tongueincheek>
    --
    Andrew Urquhart
    - FAQ: http://jibbering.com/faq
    - Archive: http://groups.google.com/groups?grou...ang.javascript
    - Reply: www.andrewu.co.uk/about/contact/


    Comment

    Working...