用户:小苏打_查看:0 回复:0 评论:0 创建时间:2020-11-15T09:45:18
<html>
<head>
<title id="title">loading</title>
</head>
<body>
<h1 id=load>loading...</h1>
<h3 id=loads><em>load jquery...</em></h3>
<p></p>
<hr>
<hr>
<hr>
<p></p>
<canvas id="tcc" width="500" height="500"></canvas>
<!--load jquery-->
<script src="https://code.jquery.com/jquery-2.1.0.js"></script>
<!-- -->
<script>
$("#title").text("welcome");
$("#load").text("welcome!");
$("#loads").text("");
$("#loads").append("<p>this is home of <em>myself<em></p>");
$("#load").fadeOut(3000);
$("#load").slideDown(1000);
$("#load").slideUp(1000);
$("#load").slideDown(1000);
var canvas = document.getElementById("tcc");
var ctx = canvas.getContext("2d");
var snakeDirection = 4; //1= ↑ 2= ↓ 3= ← 4= →
var snakelong = 3;
var snakes = [
[0, 0]
];
function tcc() {
/*
var canvas = document.getElementById("tcc");
var ctx = canvas.getContext("2d");
var snakeDirection = 4; //1= ↑ 2= ↓ 3= ← 4= →
var snakelong = 3;
var snakes = [
[0, 0]
];*/
ctx.fillStyle = "orange";
ctx.fillRect(0, 0, 500, 500);
//function drow()
function drowto(x, y, color = "blue") {
ctx.fillStyle = color;
ctx.fillRect(x * 10, y * 10, 10, 10);
}
//function drowsnake()
function drowSnake(snakeList) {
var list = snakeList;
for (list.length; list.length == 0;) {
drowto(list[list.length - 1][1], list[list.length - 1][2]);
list.pop();
}
}
//function runsnake()
function runsnake() {
if (snakelong > snakes) {
if (snakeDirection = 1) { //上
snakes.unshift([snakes.length - 1[1], snakes.length - 1[2] - 1]);
}
if (snakeDirection = 2) { //下
snakes.unshift([snakes.length - 1[1], snakes.length - 1[2] + 1]);
}
if (snakeDirection = 3) { //左
snakes.unshift([snakes.length - 1[1] - 1, snakes.length - 1[2]]);
}
if (snakeDirection = 3) { //右
snakes.unshift([snakes.length - 1[1] + 1, snakes.length - 1[2]]);
}
}
if (snakelong > snakes) {
snakes.shift();
}
drowSnake(snakes)
setInterval(runsnake, 1000);
}
}
//$("body").keydown(tcc());
tcc();
</script>
</body>
</html>