Buckster_uk
10-27-2004, 09:02 PM
Hi guys, posted few days back, and have been creating a javascript game, namely Snake.
I have created an arena for the game below with document.write methods and a for loop to write in the rows.
I have to create the start of a snake in the arena at a random place when the page loads up, I am guessing I would use the random method in the Maths bit of javascript.
How can I move the pixel about? I am stuck on this bit. Total novice really and would like some help.
This is my code so far...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>Group Project Task #1 - Snake Game Arena</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
table {
margin: 0 auto;
border: 2px solid blue;
background-color: red;
}
td {
height: 1px;
width: 1px;
}
h1{color: blue; text-align: center; text-decoration: underline;}
</style>
</head>
<body>
<h1>Snake Game Arena</h1>
<script type="text/javascript">
document.write("<table>")
for (var i = 0; i<=50; i++) {
document.write("<tr>")
for (var j = 0; j<=40; j++) {
document.write("<td>")
document.write("</td>")
}
document.write("</tr>")
}
document.write("</table>")
</script>
</body>
</html>
I have created an arena for the game below with document.write methods and a for loop to write in the rows.
I have to create the start of a snake in the arena at a random place when the page loads up, I am guessing I would use the random method in the Maths bit of javascript.
How can I move the pixel about? I am stuck on this bit. Total novice really and would like some help.
This is my code so far...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>Group Project Task #1 - Snake Game Arena</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
table {
margin: 0 auto;
border: 2px solid blue;
background-color: red;
}
td {
height: 1px;
width: 1px;
}
h1{color: blue; text-align: center; text-decoration: underline;}
</style>
</head>
<body>
<h1>Snake Game Arena</h1>
<script type="text/javascript">
document.write("<table>")
for (var i = 0; i<=50; i++) {
document.write("<tr>")
for (var j = 0; j<=40; j++) {
document.write("<td>")
document.write("</td>")
}
document.write("</tr>")
}
document.write("</table>")
</script>
</body>
</html>