Page 1 of 1

Please HELP!! Racking my brain on a CGI Game

Posted: Fri Feb 19, 2010 2:25 pm
by valeen10
I truly hope someone can help me with this! :D

I'm making a simple playing card game, setting up the database is simple, the script is simple but there is one thing that baffles me....

Here's the card layout

Once the person picks their court card(s) and clicks the button - the card game will be laid out like this...
*****card 1*******
*****card 2*******
*****card 3*******
*****card 4*******
*****card 5*******
*****card 6*******
*****card 7*******
*****card 8*******
*****card 9*******
*****card 10******


Here's is what's racking my brain and baffles me :banghead: :dubious: - I want to keep 'one card' appearing randomly in one of these 10 positions per ONCLICK?

Here's an example...
*****card 1 position*******King of Hearts******
*****card 2 position*******Ace of Spade******
*****card 3 position*******Two of Hearts*****
*****card 4 position*******Three of Diamonds*
*****card 5 position*******Five of Clubs*****
*****card 6 position*******Nine of Hearts****
*****card 7 position*******Eight of Clubs****
*****card 8 position*******Seven of Spades***
*****card 9 position*******Four of Clubs*****
*****card 10 position******Ten of Diamonds***

The King of Hearts is the card I want to keep repeating randomly in one of the 10 positions.

Here's more detail on this - Lets say I clicked the button and now the King of Hearts is in position 9 instead of 1. Next time the King of Hearts is in position 3 instead of 9 however, all the other cards listed above are being executed by a cgi database at random, appearing in one of those 10 position WITH the King of Hearts who will always been in one of those position each time the person clicks the button.

I hope I explained this well without confusion. :dubious:

So I was wondering can I use random javascript for the King of Hearts and have the ONCLICK execute the cgi database for ace-ten? Can this be done? If so, can someone explain how I can do this or provide a simple script source...I'll be forever thankful!

Or is there a simple way to execute two databases on one ()ONCLICK? If so, can someone please explain how?

If anyone has any questions or needs more info from me please let me know.

Thanks in advance for your help! :D

Just in case- here is a copy of the cgi script that executes the database...


<FORM NAME="CardForm" ACTION="/cgi/card.cgi"
METHOD="POST">


<P>Layout:
<SELECT NAME="spreadpath" SIZE="1">

<OPTION
VALUE="../card/layout/10card.html">Layout</OPTION>

</SELECT></P>


<P>Location:
<SELECT NAME="deckpath" SIZE="1">

<OPTION
VALUE="../cards/databases/cards.cgi">Card Location</OPTION>
</SELECT></P>


<P><INPUT TYPE="SUBMIT" NAME="Submit1"
VALUE="Get Cards"
ONCLICK="var forever=new Date('October 17, 2030 03:24:00')var forever=new Date('October 17, 2030 03:24:00');setCookie('spreadpath', document.cardForm.spreadpath.value , forever , '', '', '');setCookie('deckpath', document.cardForm.deckpath.value , forever , '', '', '');"></P></FORM>


</TR>
</TABLE></TD>
</TR>
</TABLE> <SCRIPT>
document.cardForm.spreadpath.value = getCookie('spreadpath') || '../card/layout/10card.html';
document.cardForm.deckpath.value = getCookie('deckpath') || '../cards/databases/cards.cgi';
</SCRIPT> </BODY>

</HTML>

Re: Please HELP!! Racking my brain on a CGI Game

Posted: Fri Feb 19, 2010 3:11 pm
by pickle
I'd do 2 different randomizations. First, randomly choose a number between 1 & 10. That's where the King of Hearts goes. Then, for each of the other 9 cards, choose random, non-King of Hearts card.

Re: Please HELP!! Racking my brain on a CGI Game

Posted: Sat Feb 20, 2010 11:49 am
by valeen10
Hi, pickle!

Thanks for replying! :D

You have a GREAT idea :bow: but not sure how it'll work with the cgi card layout I have...since the database and script work together to place the card and text in it's location.

I did look into what you suggested though because i'd rather do it like that. I searched for randomized scripts and could not find any! I spent 5 hours searching but no luck. I found many rotating or changing (page reload) but nothing that's stable or keeps the card the same even if the page is reloaded. I found no scripts that chooses a number between 1 & 10. :(

Is there something else I can do? or maybe you have a script that could help? do you know any links that can help?

Anything you can do, when you have a moment, I'll be forever thankful!

xoxoxo

Valeen

Re: Please HELP!! Racking my brain on a CGI Game

Posted: Mon Feb 22, 2010 9:49 am
by pickle
Pretty much every language has a random number generator. PHP has rand() & mt_rand() for example.