当前位置: 代码迷 >> Web开发 >> 分享自个儿写的Javascript的俄罗斯方块+送分(四)
  详细解决方案

分享自个儿写的Javascript的俄罗斯方块+送分(四)

热度:101   发布时间:2013-01-04 10:04:18.0
分享自己写的Javascript的俄罗斯方块+送分(四)
加入按钮支持触屏手机操作,但是遇到一个问题,为神马手机上点按钮反应会那么慢呢???这样完全不能正常游戏嘛,求高人解释一下~~谢谢啦~

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style type="text/css">
  .activityModel{margin:1px; width:19px; height:19px; background:red; position:absolute;}
  .forecastModel{margin:0.5px; width:9.5px; height:9.5px; background:yellow; position:absolute;}
  .stationaryModel{margin:1px; width:19px; height:19px; background:gray; position:absolute;}
  .controlModel{margin:5px; width:50px; height:50px; background:#ADD8E6; position:absolute; text-align:center; font-size:10pt }
  .container{top:0px; left:0px; background:black; position:absolute;}
  .info{top:0px; position:absolute; font-size:10pt; word-break:break-all;}
  .score{width:80px; height:20px; font-size:10pt; text-align:right; color:white; position:absolute;}
  .forecast{top:0px; left:0px; width:48px; height:48px; background:#151515; position:absolute;}
</style>
<script type="text/javascript">

var tetris;
var container;
var intervalId;
var intervalId2;

var speed = 600;
var size = 20;
var forecastSize = 10;
var controlSize = 55;
var rowCount = 18;
var colCount = 10;
var announcement = 6;

var isOver = false;
var isStop = false;
var shapes = ("0,1,1,1,2,1,3,1;1,0,1,1,1,2,2,2;2,0,2,1,2,2,1,2;0,1,1,1,1,2,2,2;1,2,2,2,2,1,3,1;1,1,2,1,1,2,2,2;0,2,1,2,1,1,2,2").split(";");

function createElm(tag,css,id)
{
  var elm = document.createElement(tag);
  elm.className = css;
  if(id) elm.id = id;
  document.body.appendChild(elm);
  return elm;
}

function Tetris(css,x,y,shape)
{
  // 创建4个div用来组合出各种方块
  var myCss = css?css:"activityModel";
  this.divs = [createElm("div",myCss),createElm("div",myCss),createElm("div",myCss),createElm("div",myCss)];
  
  if(!shape)
  {
    // 初始化计分栏  
    this.score = createElm("div","score");
    this.score.style.top = "0px";
    this.score.style.left = 6*size+"px";
    this.score.innerHTML = "score:000";
    
    // 初始化预告栏和预告方块
    var c = "forecastModel";
    this.forecast = createElm("div","forecast");
    this.divs2 = [createElm("div",c),createElm("div",c),createElm("div",c),createElm("div",c)];
  }
  
  this.container = null;
  
  this.refresh = function()
  {
    this.x = (typeof(x)!='undefined')?x:3;
    this.y = (typeof(y)!='undefined')?y:0;
    
    // 如果有传参,优先使用参数的,如果有预告,优先使用预告,都没有就自己生成
  相关解决方案