Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   tic tac toe help (http://www.programmingforums.org/showthread.php?t=15580)

scottrobot Apr 9th, 2008 5:37 PM

tic tac toe help
 
i know javascript is not rly for this type of thing but its for a project:D

im trying to make a basic tic tac toe game using this type of set up

button button button
button button button
button button button

__l____l___
l l
``l````l````


with 9 buttons up top and the actual tic tac toe board below..

could someone explain how i would set up the display like this? i understand the logic of making this work i just cant figure out how to make the display look like this

thanks

Sane Apr 9th, 2008 5:46 PM

Re: tic tac toe help
 
I'd suggest using an HTML table with 3x3 cells. Set one of three possible images inside each cell (E.G. "X.jpg", "O.jpg", "Empty.jpg"). And give each cell's image a unique ID attribute (E.G. "topleft", "topmiddle", "topright", etc...).

Then whenever you need to change the pieces, simply use Javascript to dynamically modify the "src" attribute of the image. For example, if the user sets an "X" in the top-left cell, change the "src" attribute of the element with the ID "topleft" to "X.jpg".

Ooble Apr 9th, 2008 7:03 PM

Re: tic tac toe help
 
Why not make the images clickable (use the onclick HTML attribute and set the "pointer" CSS attribute to "cursor")? Also, this is exactly what JavaScript is for.


All times are GMT -5. The time now is 5:01 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC