Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with a CGI game PLEASE!!

Status
Not open for further replies.

Val10

Technical User
Feb 20, 2010
1
0
0
I truly hope someone can help me with this!

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 - 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. (K-of-H will always been in one of those position each time the person clicks the button.)

I hope I explained this well without confusion.

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!

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>
 
Hey,

The code you posted above isn't CGI although the post action is card.cgi (but you haven't provided any code for this). Looks like you are trying to build your game using javascript therefore the javascript forum would have probably been more useful.

I'm not sure if I quite follow however you discussed that you would like to run your "cgi database" using a javascript onClick event. This would require using an AJAX XML Http Request ( This allows you to use the client side language (javascript) to access and return data from a server side script (CGI).

I apologise if this isn't what you are trying to achieve,

Chris
 
I hope I explained this well without confusion
Nope, I don't have a clue what you're trying to do.

However, it is clear that you don't understand the distinction between server-side and client-side code. CGI is a server-side approach - you submit a set of data to the script, and it returns a new page as a result.

Onclick is a client-side event - it triggers a bit of javascript that runs locally on your machine. It is possible to combine the two approaches - via AJAX, for example - but you need to know the basics of what's happening where.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top