一个javascript脚本写的俄罗斯方块[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 lxx8402 的 blog

russia.htm

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> 俄罗斯方块 </title>
<meta name="generator" content="editplus">
<meta name="author" content="dolphin">
<meta name="description" content="俄罗斯方块游戏">
<style>
.btnup{
         border-left:solid #ffffff 1px;
         border-top:solid #ffffff 1px;
         border-right:solid #828486 1px;
         border-bottom:solid #828486 1px;
   font-size: 9pt;
   cursor:default
        }
tr{
  font-family:"宋体";
  font-size: 9pt;
  cursor: default
}
</style>
<script language="javascript" src="russia.js"></script>
</head>

<body bgcolor="#ffffff" onload="init()" onkeydown="keydown()">
<table border="0" cellspacing="2" cellpadding="6" align="center" width="60%">
<tr valign="top">
 <td width="120">
  得分: &nbsp;&nbsp;<span id="gscore"></span>&nbsp;&nbsp;<p>
  级别: &nbsp;&nbsp;<span id="glevel"></span>&nbsp;&nbsp;<p>
  行数: &nbsp;&nbsp;<span id="gline"></span>&nbsp;&nbsp;<p>
 </td>
 <td><span id="gamebody"><!-- 游戏主区域 --></span></td>
 <td>
  <span id="gameforecast"><!-- 游戏预报区域 --></span><p>
  <button id="start" onclick="startgame()">开始游戏</button><p>
  <button id="pause" onclick="pausegame()">暂停游戏</button><p>
  <button id="over" onclick="overgame()">结束游戏</button><p>
  <button>帮&nbsp;&nbsp;&nbsp;&nbsp;助</button>
 </td>
</tr>
</table>
</body>
</html>

russia.js

var cols = 10, rows = 20, sqlen = 16;
var color = new array(8);
var delline = new array();
var cloc = new array();
var rloc = new array();
var cursq,nextsq;
var type=-1,oldtype;
var delay = new array(600,500,400,300,200,100,90,80,70);
var timerid;
var pos = 0,end,level=0,score=0,lines=0;
var isover=false,ispause=false;

color[0] = "#d0d0d0";
color[1] = "red";
color[2] = "green"
color[3] = "cyan";
color[4] = "yellow";
color[5] = "orange";
color[6] = "pink";
color[7] = "blue";


function gamearea(row,col,name){
 var s = "<table border=1 cellspacing=0 cellpadding=1 bgcolor=" + color[0] + ">";
 for(var i=0; i<row; i++){
  s = s + "<tr height=" + sqlen + ">";
  for(var j=0; j<col; j++){
   var id = name + i + "#" + j;
   s = s + "<td width=" + sqlen + " class=btnup id=" + id;
   s = s + " style=\"background:" + color[0] + "\">&nbsp;</td>"
  }
  s = s + "</tr>";
 }
 s = s + "</table>";
 return s;
}

function init(){
 gamebody.innerhtml = gamearea(rows,cols,'main');
 gameforecast.innerhtml = gamearea(4,4,'forecast');
}

function square(cols,rows,color){
 this.rows = rows;
 this.cols = cols;
 this.color = color;
}

function choosesquare(type,x,y){
 var sq = new array(4);
 switch(type){
  case 0:
   sq[0] = new square(x-1,y,1);
   sq[1] = new square(x,y,1);
   sq[2] = new square(x+1,y,1);
   sq[3] = new square(x+2,y,1);
   break;
  case 1:
   sq[0] = new square(x,y,5);
   sq[1] = new square(x,y+1,5);
   sq[2] = new square(x+1,y+1,5);
   sq[3] = new square(x,y+2,5);
   break;
  case 2:
   sq[0] = new square(x,y,2);
   sq[1] = new square(x,y+1,2);
   sq[2] = new square(x+1,y+1,2);
   sq[3] = new square(x+1,y+2,2);
   break;
  case 3:
   sq[0] = new square(x+1,y,7);
   sq[1] = new square(x+1,y+1,7);
   sq[2] = new square(x,y+1,7);
   sq[3] = new square(x,y+2,7);
   break;
  case 4:
   sq[0] = new square(x,y,3);
   sq[1] = new square(x+1,y,3);
   sq[2] = new square(x,y+1,3);

本文关键:javascript,俄罗斯方块
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top