Uploaded by 5A15 Tsang Hoi Lam

f5 Javascript horse racing

advertisement
ICT/Core/Programming/Javascript/horse racing
Write a webpage to simulate horse racing
[Basic requirement]
When the webpage starts, the horses will run by themselves towards the right.
[Resources]
You can download the horses and the race course with
http:/leungwo.com/program/proglib/horse.zip
You are required to make one transparent gif by yourself.
[Suggested layout]
background:
<body background=racecourse.jpg>
first row of table contains a paragraph:
<table border=1 style=…………>
<tr><td></td><td><p id=result>…….</p></td></tr>
other row contain number and the image:
<tr><td>1</td><td><img src=… id=….></td></tr>
……..
……..
</body
[skills invoved]
1. To let a function, say process(), run one time per second, we can write
tostart=setInterval(process,1000);
2. To define the style of table to be 50px font size and font colour white,
left margin
we have
style="font-size:50px;color:white;"
3. To control the left margin of a horse (say h1), we can define its style
document.getElementById("h1").style="margin:0px 0px 0px "+a+"px";
4. You are suggest to use five integer variable to control the left margins of horses
<script>
a=0;b=0;c=0;d=0;e=0;
5.
to increment variable a randomly, we have
a=a+Math.floor(Math.random()*20);
[More to do]
1. Add a button <input type=button value=start onclick=start()> to run the function start to run
tostart=setInterval(…….)
2. Stop the race if any one horse reaches, say 800.
To stop, we have
clearInterval(tostart);
3. The paragraph will show which horse wins.
4.
Add a button to restart the race. It runs a function to
either
location.reload();
or
window.open("…..","_self");
The name of this webpage, say
horse.html
Download