iamabe666 08-15-2005, 02:30 PM ive been working on this game in javascript and i have a couple of questions.
1)how can i make it run faster by either preloading the pix or just using colors(cant figure out anything that can change colors with javascript) when its online? (try it out online and from your comp to see the speed difference)
2)is it possable to make a random level generator that will check if its possable to win?
here's a link to download it
http://www.startbeat.com/games/ColorPuzzle.rar
here it is online
http://games.startbeat.com OR http://www.startbeat.com/games/
please dont rip it off and take credit for it
thanx in advance for any help you can give me
rlemon 08-15-2005, 04:08 PM your game does not work in FireFox, however It loads fine in IE.
Good Work soo far, btw the colour thingy you wanted is easy.
I havn't looked at the code so i don't know what your using for the blocks. i'm assuming you could use div tags or table cells.
so in javascript
var element = document.getElementById('cellId');
element.style.backgroundColor = "#0000ff";
or just
element.backgroundColor = "#0000ff";
depending on how your making the 'blocks'
iamabe666 08-15-2005, 04:46 PM what do i name, the "td" or "tr" or "table"?
thanx :)
rlemon 08-15-2005, 04:49 PM the 'TD' tag.
<table....>
<tr ..>
<td id="someID" name="someName" class="someClass" .....>
.....
</table>
then document.getElementById('someID');
:thumbsup:
iamabe666 08-15-2005, 05:00 PM GOT IT!!! thanx! :D :D :D
iamabe666 08-15-2005, 05:09 PM hmm, ran into a small problem. can i make the td's into an array?
rlemon 08-15-2005, 05:19 PM you should be able to make the td id values into an array.
var tdId = new Array('tdId1','tdId2','tdId3'.....);
I think there is a better way of doing this using DOM but i'm unsure of the exact code right now. i'l look into it if i get the time and post something later.
iamabe666 08-15-2005, 05:44 PM didnt work, ill look around
rlemon 08-15-2005, 05:55 PM maybe post some code here for me to look at, I'm a little busy at the moment and cannot load your game up and scan the source for the applicable area's.
iamabe666 08-15-2005, 06:06 PM heres a test page i made with everything i need from the game:
<html>
<head><script language=javascript>
function cc(tdidnum, colornum) {
var tdidar = new Array('document.getElementById(tdid1)','document.getElementById(tdid2)');
var element = tdidar[tdidnum];
element.style.backgroundColor = colornum;
}
</script>
</head>
<body>
<table><tr><td id="tdid1" bgcolor="red" width="50" height="50"></td><td id="tdid2" bgcolor="#FF0000" width="50" height="50"></td></tr></table>
<input type="button" onClick="cc('1','#0000FF')">
</body>
</html>
thanx for ur help
rlemon 08-15-2005, 06:18 PM <html>
<head><script language=javascript>
function cc(tdidnum, colornum) {
var tdidar = new Array('tdid1','tdid2');
var element = document.getElementById([tdidnum]);
element.style.backgroundColor = colornum;
}
</script>
</head>
<body>
<table><tr><td id="tdid1" bgcolor="red" width="50" height="50"></td><td id="tdid2" bgcolor="#FF0000" width="50" height="50"></td></tr></table>
<input type="button" onClick="cc('1','#0000FF')">
</body>
</html>
also, I think you might need to place something in there for the <td> element to take the background color. I would suggest using the same image file for them all. Make the image a fully transparent gif 1px*1px
<td id="tdid1"...><img src="path/to/blank.gif" alt="" height="50px" width="50px" border="0"></td>
iamabe666 08-15-2005, 06:23 PM didnt work
error line 6: object required
iamabe666 08-15-2005, 06:26 PM nvr mind, got it
thanx!!!
rlemon 08-15-2005, 06:29 PM sorry, I messed up a line there
<html>
<head><script language=javascript>
function cc(tdidnum, colornum) {
var tdidar = new Array('tdid1','tdid2');
var element = document.getElementById(tdidar[tdidnum]);
element.style.backgroundColor = colornum;
}
</script>
</head>
<body>
<table><tr><td id="tdid1" bgcolor="red" width="50" height="50"></td><td id="tdid2" bgcolor="#FF0000" width="50" height="50"></td></tr></table>
<input type="button" onClick="cc('0','#0000FF')">
</body>
</html>
Also, rememember when using the Array that the first element is actually number '0' not number '1'.
tip:
to return the actuall number of elements in the array you would use
var num_of_elements = ArrayName.length-1;
you minus one because it registers 0 as a number.
rlemon 08-15-2005, 06:33 PM Also, for the random level thing.
I'm assuming there is a seperate page / function for the new levels?
If so, you should only need to generate a random number to distinguish between them and navigate to them.. so...
var randomNum = (Math.Random()*(numberYouWant-1))+1;
the random number will be between 0 and the number you times it by.
so if you wanted a random number between 1 and 9 you would use the following.
var rnd = Math.Round(Math.Random()*8)+1;
iamabe666 08-15-2005, 06:39 PM i no, but anything random might be impossable to win, im gonna try to have a function that checks if the level is possable to beat and if not trys again, im not gonna work on that till later tho. thanx for your help
rlemon 08-15-2005, 06:53 PM well if you have say, 50 levels mapped out (however your defining the levels) then you could have a 'load random level' function that just selects from the group.
Might be an easier temporary solution.
iamabe666 08-15-2005, 07:03 PM i made a level editor, the idea of the random levels is so i dont have to go through each one making it and testing to see if its beatable
iamabe666 08-15-2005, 07:30 PM does anyone have like 10mins to look through this and see whats wrong, i did the whole table thing and i got an error and i cant seem to find it. heres the link: http://games.startbeat.com/color.html
heres the old one: http://games.startbeat.com/OLDcolor.html
ill post if i fugure it out
rlemon 08-15-2005, 08:02 PM when defining what values are to be passed to the function you need to encase them in quotes. unless of course you want to pass a variable, or a constant.
so line 18, cc(youold,#ff0000) should be cc(youold,'#ff0000') *assuming youold is a variable.
try that and see if it solves the 'iniGame() is not defined' error as well.
iamabe666 08-15-2005, 08:36 PM ya, fixed it, it works ill upload it now! thanx!!
UPDATE: uploaded it
|