View Full Version : card game help please.

06-10-2003, 11:09 PM
i have the shuffling functions working but when i try to get it to move the cards i'm having trouble:

<!-- 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);

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

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

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

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);
alert("Not a valid move");

// End -->


<form name="display">

<table bgcolor="#c0c0c0" border="1" cellspacing="0" cellpadding="3">
<td><input type=button value="Start" onClick="NewHand(form)"></td>
<td>Dealer Card(1): <input type=text name="deal1" size="18" value=""></td>
<td>Dealer Card(2): <input type=text name="deal2" size="18" value=""></td>
<td><input type=text name="win" size="3" value="0"></td>
<td>Dealer Card(3): <input type=text name="deal3" size="18" value=""></td>
<td colspan=2>You have: <input type=text name="you" size="18" value=""> place it..?</td>
<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>


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

06-11-2003, 01:59 AM
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

var dealerCard1;
var dealerCard2;
var dealerCard3;
var dealerSuit1;
var dealerSuit2;
var dealerSuit3;
var playerCard;
var playerSuit;

See if that helps