<body> <div id="header"> <h1>别踩白块儿</h1> <div id="timer" >0.0000</div> </div> <div id="container"> <div class="grid" id="grid-0-0"></div> <div class="grid" id="grid-0-1"></div> <div class="grid" id="grid-0-2"></div> <div class="grid" id="grid-1-0"></div> <div class="grid" id="grid-1-1"></div> <div class="grid" id="grid-1-2"></div> <div class="grid" id="grid-2-0"></div> <div class="grid" id="grid-2-1"></div> <div class="grid" id="grid-2-2"></div> <div class="grid" id="grid-3-0"></div> <div class="grid" id="grid-3-1"></div> <div class="grid" id="grid-3-2"></div> </div> </body>
body{
background-color: #008694;
font: 12px/20px "黑体" ,arial;
}
#header {
display: block;
margin: 0 auto;
width: 500px;
text-align: center;
}
#header h1 {
font-family: Arial;
font-size: 40px;
font-weight: bold;
}
#timer {
z-index: 4;
font-size: 24px;
color: #fa3c3c;
font-weight: 700;
text-shadow: 2px 2px 3px rgba(0, 0, 0, .3)
}
#container{
width: 302px;
height: 402px;
margin: 50px auto;
background-color: #55d769;
border: 5px solid #000;
position: relative;
}
.grid {
width: 100px;
height: 100px;
background-color: #fff;
border: 1px solid #000;
position: absolute;
}
.block {
width: 100px;
height: 100px;
border: 1px solid #000;
font-family: Arial;
font-weight: bold;
font-size: 20px;
color: #fff;
text-align: center;
position: absolute;
}
.coBlock{
background-color: #000;
}
.gameover {
display: block;
margin: 0 auto;
width: 300px;
text-align: center;
vertical-align: middle;
position: absolute;
}
.gameover p {
font-family: Arial;
font-size: 50px;
color: white;
margin: 50px auto;
margin-top: 150px;
}
.gameover span {
font-family: Arial;
font-size: 50px;
color: white;
margin: 50px auto;
}
.restartGame {
display: block;
margin: 20px auto;
width: 180px;
padding: 10px 10px;
background-color: #8f7a66;
font-family: Arial;
font-size: 30px;
color: white;
border-radius: 10px;
text-decoration: none;
}
.restartGame:hover {
background-color: #9f8b77;
}
function init(){
timerRan = 0.000;
keyDown = true;
for(var i=0;i<4;i++){
board[i] = [];
for(var j=0;j<3;j++){
board[i][j] = [];
var grid = $('#grid-'+ i +'-'+ j);
grid.css({
'top':getPosTop(i,j),
'left':getPosLeft(i,j)
});
$('#container').append('<div class="block" id="block-'+ i +'-'+ j +'"></div>');
var block = $('#block-'+ i +'-'+ j);
block.css({
'top':getPosTop(i,j),
'left':getPosLeft(i,j)
});
board[i][j] = 0;
}
}
function getPosTop(i,j){
return i*100;
}
function getPosLeft(i,j){
return j*100;
}
for(var i=0;i<4;i++){
var randj = parseInt(Math.floor(Math.random() * 3));
if(i >0 && board[i-1][randj] == 1){
randj = parseInt(Math.floor(Math.random() * 3));
}
$('#block-'+ i +'-'+ randj).addClass('coBlock');
board[i][randj] = 1;
}
$('#block-3-0').text('按J开始游戏');
$('#block-3-1').text('按K开始游戏');
$('#block-3-2').text('按L开始游戏');
$(document).keydown(function(event) {
switch(event.keyCode){
case 74:
if(board[3][0] == 1 && keyDown){
timeRan();
clearText();
moveDown();
}else{
isgameover();
}
break;
case 75:
if(board[3][1] == 1 && keyDown){
timeRan();
clearText();
moveDown();
}else{
isgameover();
}
break;
case 76:
if(board[3][2] == 1 && keyDown){
timeRan();
clearText();
moveDown();
}else{
isgameover();
}
break;
}
});
function timeRan(){
clearTimeout(timer);
timerRan += 0.001;
$('#timer').text(timerRan.toString().slice(0,5));
timer = setTimeout(function(){
timeRan();
},1);
}
function clearText(){
$("#block-3-0").text("");
$("#block-3-1").text("");
$("#block-3-2").text("");
}
function moveDown(){
for(var i=3;i>=0;i--){
for(var j=2;j>=0;j--){
if(board[i][j] == 1){
if(i == 3){
$('#block-'+ i +'-'+ j).removeClass('coBlock');
board[i][j] = 0;
}else{
$('#block-'+ i +'-'+ j).removeClass('coBlock');
board[i][j] = 0;
$('#block-'+ (i+1) +'-'+ j).addClass('coBlock');
board[i+1][j] = 1;
}
}
}
}
var randj = parseInt(Math.floor(Math.random() * 3));
$('#block-0-'+ randj).addClass('coBlock');
board[0][randj] = 1;
}
function isgameover(){
keyDown = false;
clearTimeout(timer);
$('#container').append('<div id="gameover" class="gameover"><p>本次用时</p><span>'+ timerRan.toString().slice(0,5) +'</span><a href="javascript:restartGame()" class="restartGame">重新开始</a></div>');
var gameover = $("#gameover");
gameover.css("width", "300px");
gameover.css("height", "400px");
gameover.css("background-color", "rgba(0, 0, 0, 0.5)");
}
function restartGame(){
$('#timer').text('0.000');
$('#gameover').remove();
$('.block').remove();
init();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有