Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,263 Programmers. There are 1,895 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Function Malfunction

 
Reply to this topicStart new topic

Function Malfunction, Trouble writing a funciton for a child's small game

jackbergman
post 2 May, 2008 - 07:00 PM
Post #1


New D.I.C Head

*
Joined: 2 May, 2008
Posts: 0



I am having the hardest time with this function. I have a table with randomized "water" images in it. When the user clicks on the "water" they can lay a lily pad down. When the user clicks the button, a frog should replace the first lily pad image, and then appear to move to each lily pad that the user placed on the screen. Each time the frog "jumps", the lily pad should return so it looks like the image is moving in a defined pattern.

If the user clicks lily pads into a rectangle pattern, I want one frog to look like it is moving the whole way around it.

Can anyone help me? I am trying to make a simple little game for my daughter and she would be quite pleased to see it work. Thanks in advance.

CODE

<html><head><title>Frog takes a walk</title>
<script>
function pond() {
document.write ("<table border=0 cellspacing=0 cellpadding=0>")
for (i = 1; i <= 10; i++) {
document.write ("<tr>")
for (j = 1; j <= 10; j++) {
document.write ("<td>")
document.write ("<img src='water1.jpg' width='60' height='60' ")
document.write ("name='row" + i + "col" + j + "'")
document.write (" onmousedown=lily(" + i + "," + j + ")>")
document.write ("</td>")
}
document.write ("</tr>")
}
document.write ("</table><br>")
for(p=0;p<document.images.length;p++){
r=Math.ceil(Math.random()*9)
document.images[p].src="water" + r +".jpg"
}
}

function lily(i,j){
document.images['row' + i + 'col' + j].src = "R.jpg"
}


function frog(i,j){
//Help needed here. When you click the button, I want the frog image to "jump" onto the lily
//pads that the user clicked onto the screen via the onmousedown. What I really mean is when
//the button is clicked, the lily pad image should be replaced with a frog image and when the frog
//jumps to the next image, the lily pad should return and so on. The whole thing
//should appear to be moving in the pattern defined by the user.

}
</script>
</head>
<body bgcolor="blue">
<script>
pond()
</script>
<form>
<input type="button" onclick="frog(' + i + ',' + j + ')" value="Frog Take a Walk" >
</form>
</body>
</html>
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


rgfirefly24
post 5 May, 2008 - 10:54 AM
Post #2


D.I.C Head

Group Icon
Joined: 7 Apr, 2008
Posts: 135

now i cant offer any code unfortunatly since i have no knowledge of Javascript, but i can suggest this

if there is a way can you just onmousedown replace the images? I.E lillypad goes to frog frog goes to lillypad?
User is online!Profile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 10:23AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month