复制代码代码如下:
<! doctype html> <html> <éadf> <style type = "text / css">
corps {arrière-plan: # 000; Police: 25px / 25px 宋体;}
#box {float: gauche; largeur: 252px; bordure: # 999 20px crête; couleur: # 9f9; text-shadow: 2px 3px 1px # 0f0; }
#info {float: gauche; couleur: #cfc; padding: 24px; }
#Next {padding: 8px; largeur: 105px; couleur: # 9f9; text-shadow: 2px 3px 1px # 0f0; }
</ style> </ head> <body>
<div id = "box"> </ div> <div id = "info"> Suivant: <div id = "next"> </ div> <div id = "text"> </div> </div>
<script type = "text / javascript">
var map = eval ("[" + array (23) .join ("0x801,") + "0xfff]");
var tatris = [[0x6600], [0x2222,0xf00], [0xc600,0x2640], [0x6c00,0x4620], [0x4460,0x2e0,0x6220,0x740], [0x2260,0xe20,0x64440,0x4700 , 0x2320,0x2700]];
var char = {x: "/ u3000", s: "/ u25a0", t: "/ u25a1"};
var keycom = {"38": "rotation (1)", "40": "down ()", "37": "Move (2,1)", "39": "Move (0,5, -1) "," 32 ":" 0; pause =! Pause "};
var dia, pos, bak, run, suivant, pause = false, info = {Speed: 1, lignes: 0, score: 0};
fonction start () {
dia = next.d;
bak = pos = {fk: [], y: 0, x: 4, s: next.s};
NextDia ();
document.getElementById ("Next"). innerHtml = (next.d [next.s% next.d.length] | 0x10000) .tostring (2) .slice (-16) .replace (/..../ g , "$ & <br/>") .replace (/1/g,char.t) .replace (/0/g,char.x);
document.getElementById ("texte"). innerhtml = "score:" + info.score + "<br/> <br/> lignes:" + info.lines + "<br/> <br/> vitesse:" + info. vitesse;
tourner (0);
run = setInterval ("Pause || down ()", ~~ (math.pow (1.3,12-info.speed) * 30 + 20));
}
fonction sur () {
document.onkeydown = null;
alert ("jeu over");
}
fonction NextDia () {
suivant = {d: tatris [~~ (math.random () * 7)], s: ~~ (math.random () * 4)};
}
Function Update (t) {
bak = {fk: pos.fk.slice (0), y: pos.y, x: pos.x, s: pos.s};
if (t) retour;
pour (var i = 0, a2 = ""; i <22; i ++)
a2 + = map [i] .tostring (2) .slice (1, -1) + "<br/>";
pour (var i = 0, n; i <4; i ++)
if (/ ([^ 0] +) /. Test (bak.fk [i] .tostring (2) .replace (/1/g,char.t))))
a2 = a2.substr (0, n = (bak.y + i + 1) * 15-regexp. $ _. Longueur-4) + regexp. $ 1 + a2.slice (n + regexp. 1.Length);
document.getElementById ("Box"). InnerHtml = a2.replace (/1/g,char.s) .replace (/0/g,char.x);
}
La fonction est () {
pour (var i = 0; i <4; i ++)
if ((pos.fk [i] & map [pos.y + i])! = 0) return pos = bak;
}
fonction rotation (r) {
var f = dia [pos.s = (pos.s + r)% dia.length];
pour (var i = 0; i <4; i ++)
pos.fk [i] = (f >> (12-i * 4) & 15) << pos.x;
Mise à jour (IS ());
}
fonction down () {
++ pos.y;
if (is ()) {
pour (var i = 0, r = 0; i <4 && pos.y + i <22; i ++)
if ((map [pos.y + i] | = pos.fk [i]) == 0xfff) {
map.splice (pos.y + i, 1), map.unshift (0x801);
++ info.lines% 20 == 0 && info.Speed ++, r ++;
}
ClearInterval (Run);
if (map [1]! = 0x801) return over ();
info.score + = ~~ (math.pow (r, 1.5) * 10) +2;
commencer();
}
mise à jour();
}
Fonction Move (t, k) {
pos.x + = k;
pour (var i = 0; i <4; i ++)
pos.fk [i] * = t;
Mise à jour (IS ());
}
document.onkeydown = fonction (e) {
eval ("Pause ||" + keycom [(e? e: événement) .KeyCode]);
};
NextDia ();
commencer();
</cript> </ body> </html>