⑴ 如何用python寫俄羅斯方塊

把俄羅斯方塊裡面的圖片全部替換成各種LOGO

⑵ 求俄羅斯方塊源代碼

馬上發給你

⑶ 俄羅斯方塊如何編寫及代碼

網上很多呀,有很多javascript寫的網頁俄羅斯方塊游戲,可以直接查看網頁源碼,偷懶的話修改成c++的就成了。
但也不要太懶了,如果你是學生的話。。。。。。

⑷ 求俄羅斯方塊html代碼

<html>
<head>
<title>標題</title>
</head>
<body>

<style>
span.btn
{
BORDER-RIGHT: #7b9ebd 1px solid;
PADDING-RIGHT: 2px;
BORDER-TOP: #7b9ebd 1px solid;
PADDING-LEFT: 2px;
FONT-SIZE: 12px;
FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
BORDER-LEFT: #7b9ebd 1px solid;
COLOR: black;
PADDING-TOP: 2px;
BORDER-BOTTOM: #7b9ebd 1px solid;
background-color: #CCCCCC;
}
</style>
<script language="javascript">
var doing;
var candown=0;
var wnum=13;
var hnum=18;
var grid=new Array();
var gridBuf=new Array();
for(i=0;i<=hnum;i++){
grid[i]=new Array();
gridBuf[i]=new Array();
for(j=0;j<=wnum;j++){
if(j>0 && j<wnum && i<hnum){
grid[i][j]=0;
gridBuf[i][j]=0;
}else{
grid[i][j]=1;
gridBuf[i][j]=1;
}
}
}

var boxdata=
[
[
[1,1,1,1],
[0,0,0,0],
[0,0,0,0],
[0,0,0,0]
],
[
[1,1,1,0],
[1,0,0,0],
[0,0,0,0],
[0,0,0,0],

],
[
[1,1,1,0],
[0,1,0,0],
[0,0,0,0],
[0,0,0,0]
],
[
[1,1,1,0],
[0,0,1,0],
[0,0,0,0],
[0,0,0,0]
],
[
[1,1,0,0],
[0,1,1,0],
[0,0,0,0],
[0,0,0,0]
],
[
[0,1,1,0],
[1,1,0,0],
[0,0,0,0],
[0,0,0,0]
],
[
[1,1,0,0],
[1,1,0,0],
[0,0,0,0],
[0,0,0,0]
]
];

var colors=["black","#A0A0A0","red","#FF8000","yellow","pink"];
var gotLine=0;
var box;
var bGameOver=false;
function getHeight(arr)
{
var i,j;
for(i=3;i>=0;i--)
for(j=0;j<4;j++)
if(arr[i][j]) return i;
}

function getWidth(arr)
{
var i,j;
for(i=3;i>=0;i--)
for(j=0;j<4;j++)
if(arr[j][i]) return i;
}

function Box(x,y,arr,color)
{
this.arr=arr;
this.x=x;
this.y=y;
this.w=getWidth(arr);
this.h=getHeight(arr);
this.color=color;
this.active=true;

this.clearOldBox=function()
{
for(var j=0;j<=this.h;j++)
for(var i=0;i<=this.w;i++)
if(this.arr[j][i]>0) grid[this.y+j][this.x+i]=0;
}

this.putNewBox=function()
{
for(var j=0;j<=this.h;j++)
for(var i=0;i<=this.w;i++)
if(this.arr[j][i]>0) grid[this.y+j][this.x+i]=this.color;

}

this.moveLeft=function()
{
this.clearOldBox();
var _x=this.x-1;
if(this.canMove(_x,this.y)) this.x=_x;
this.putNewBox();
drawGrid();
}
this.moveRight=function()
{
this.clearOldBox();
var _x=this.x+1;
if(this.canMove(_x,this.y)) this.x=_x;
this.putNewBox();
drawGrid();
}

this.moveDown=function()
{
this.clearOldBox();

var _y=this.y+1;
if(this.canMove(this.x,_y)){
this.y=_y;
this.putNewBox();
drawGrid();

}else{
this.putNewBox();
drawGrid();
checkLineFull();
return;
}

}

this.rotate=function()
{
var tmp=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]];
for(j=0;j<=this.h;j++)
for(i=0;i<=this.w;i++)
tmp[this.w-i][j]=this.arr[j][i];
var newBox=new Box(this.x,this.y,tmp,this.color);
this.clearOldBox();
if(! newBox.canMove(this.x,this.y)) this.putNewBox();
else
{
box=newBox;
box.putNewBox();
drawGrid();
}
}
this.canMove=function(x,y)
{
for(var j=0;j<=this.h;j++)
for(var i=0;i<=this.w;i++)
{
if(grid[y+j][x+i]!=0 && this.arr[j][i]!=0){ candown=1;return false; }
}
return true;
}

}

function drawGrid()
{
for(var j=0;j<hnum;j++)
for(var i=0;i<wnum;i++)
{
if( grid[j][i]!=gridBuf[j][i])
{
paintCell(j,i,grid[j][i]);
}
gridBuf[j][i]=grid[j][i];

}
}

function paintCell(i,j,color)
{
var htmlGrid=document.getElementById("TetrisGrid").firstChild;
htmlGrid.childNodes[i].childNodes[j].style.backgroundColor=colors[color];

}
function init()
{
var html='<table id="TetrisGrid" cellspacing=1 style="background-color:green"><tbody>';
for(var i=0;i<=hnum;i++)
{
html+='<tr>';
for(var j=0;j<=wnum;j++)
{

html+='<td width="20" height="20" style="background-color:'+colors[grid[i][j]]+';"></td>';
}
html+='</tr> \r\n';
}
html+='</tbody></table>';
document.write(html);

}

function checkLineFull()
{
var full,i,j,i2;
var y3=box.y+box.h;
var y4=box.y;
for(i=y3;i>=y4;)
{
full=1;
for(j=0;j<wnum;j++)
if(grid[i][j]==0){full=0; break;}
if(full==0){ --i; continue;}
for(i2=i; i2>0;i2--)
for(j=0;j<wnum;j++)
grid[i2][j]=grid[i2-1][j];
drawGrid();
y4++;
gotLine++;
}
checkGameOver();
}

function checkGameOver()
{
var bOver=false;
for(var j=1;j<wnum;j++)
if(grid[0][j]>0){ bOver=true; break;}
if(!bOver){
box=new Box((wnum-1)/2,0,boxdata[Math.floor(Math.random()*7)],Math.floor(Math.random()*5)+1);
box.putNewBox();
}
else
{
bGameOver=true;
msg.innerHTML="游戲結束! 您的得分為"+gotLine*100;
window.clearTimeout(doing);
}
}
function document_onkeydown()
{
if(bGameOver) return;
switch(event.keyCode)
{
case 32:
down();
break;
case 37:
box.moveLeft();
break;
case 39:
box.moveRight();
break;
case 38:
box.rotate();
break;
case 40:
box.moveDown();
break;
case 80:
stop();
break;
case 66:
window.location.reload();
break;
case 67:
restart();
break;
}
}
function down(){
if(window.event.keyCode==32){
clearTimeout(doing);
for(i=0;i<hnum;i++){
if(candown==0){
box.moveDown();
}else{
break;
}
}
candown=0;
doing=window.setTimeout('moveDownBox()',interval);
}
}
var interval;
function moveDownBox()
{
interval=1000-10*(gotLine>80?80 :gotLine);
msg.innerHTML=" 等級:"+Math.floor(gotLine/10)+";得分:"+gotLine*100;
box.moveDown();
doing=window.setTimeout('moveDownBox()',interval);
}
function startGame()
{
init();
doing=window.setTimeout('moveDownBox()',1000);
bGameOver=false;
box=new Box((wnum-1)/2,0,boxdata[Math.floor(Math.random()*7)],Math.floor(Math.random()*5)+1);
box.putNewBox();
drawGrid();
}
var status;
function stop(){
status=1;
window.clearTimeout(doing);
}
function restart(){
if(status==1){
status=0;
doing=window.setTimeout('moveDownBox()',1000);
}
}
function keydown(){
if (document.all)document_onkeydown()
}
</script>

<BODY onLoad="window.focus()" onkeydown="keydown()">
<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<table id="maintable" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<span class="btn" style="width:100%; height:24px;background-color:#F0C0C0;color:#0000FF;vertical-align:middle;text-align:center">俄羅斯方塊</span></td>
</tr>
<tr>
<td style="height:20px;background-color:black;color:#00FF00;font-size:12px;"><table height="20" border="0" cellpadding="0" cellspacing="0">
<tr style="font-size:12px; color:#FFFFFF">
<td width="100%"> <a style="cursor:hand" onclick="window.location.reload()">開始(B)</a> <a style="cursor:hand" onclick="stop();">暫停(P)</a> <a style="cursor:hand" onclick="restart();">繼續(C)</a></td>
</tr>
</table></td>
</tr>
<tr>
<td style="height:20px;background-color:black;color:#00FF00;font-size:12px;" id="msg"> 等級:0;得分:0</td>
</tr>
<tr>
<td height="20">
<script language=javascript>
maintable.style.width=(wnum+1)*20;
startGame();
</script>
</td>
</tr>
</table></td>
</tr>
</table>

</body>
</html>

⑸ 我想用python編寫一個俄羅斯方塊的問題

這是用PyQT寫的抄,建議看一下QT的signal slot機制,幾句話說不清楚。你可以理解為當信號觸發時,會調用connect到對象的SIGNAL的slot函數。這里在隨後的代碼中emit了自定義的messageToStatusbar(QString)信號。 網上有解釋:www. czug. org/python/pyqt4/11.htm

⑹ 俄羅斯方塊的源代碼

你會用c編么??編好後,反匯編一下,就可以了。。

⑺ 求C語言俄羅斯方塊代碼

俄羅斯方塊C源代碼

#include<stdio.h>

#include<windows.h>

#include<conio.h>

#include<time.h>

#defineZL4 //坐標增量,不使游戲窗口靠邊

#defineWID36 //游戲窗口的寬度

#defineHEI20 //游戲窗口的高度

inti,j,Ta,Tb,Tc; //Ta,Tb,Tc用於記住和轉換方塊變數的值

inta[60][60]={0}; //標記游戲屏幕各坐標點:0,1,2分別為空、方塊、邊框

intb[4]; //標記4個"口"方塊:1有,0無,類似開關

intx,y,level,score,speed; //方塊中心位置的x,y坐標,游戲等級、得分和游戲速度

intflag,next; //當前要操作的方塊類型序號,下一個方塊類型序號

voidgtxy(intm,intn); //以下聲明要用到的自編函數

voidgflag(); //獲得下一方塊序號

voidcsh(); //初始化界面

voidstart(); //開始部分

voidprfk(); //列印方塊

voidclfk(); //清除方塊

voidmkfk(); //製作方塊

voidkeyD(); //按鍵操作

intifmov(); //判斷方塊能否移動或變體

void clHA(); //清除滿行的方塊

voidclNEXT(); //清除邊框外的NEXT方塊

intmain()

{csh();

while(1)

{start();//開始部分

while(1)

{prfk();

Sleep(speed); //延時

clfk();

Tb=x;Tc=flag;//臨存當前x坐標和序號,以備撤銷操作

keyD();

y++;//方塊向下移動

if(ifmov()==0){y--;prfk();dlHA();break;}//不可動放下,刪行,跨出循環

}

for(i=y-2;i<y+2;i++){if(i==ZL){j=0;}} //方塊觸到框頂

if(j==0){system("cls");gtxy(10,10);printf("游戲結束!");getch();break;}

clNEXT(); //清除框外的NEXT方塊

}

return0;

}

voidgtxy(intm,intn)//控制游標移動

{COORDpos;//定義變數

pos.X=m;//橫坐標

pos.Y=n;//縱坐標

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);

}

voidcsh()//初始化界面

{gtxy(ZL+WID/2-5,ZL-2);printf("俄羅斯方塊");//列印游戲名稱

gtxy(ZL+WID+3,ZL+7);printf("*******NEXT:");//列印菜單信息

gtxy(ZL+WID+3,ZL+13);printf("**********");

gtxy(ZL+WID+3,ZL+15);printf("Esc:退出遊戲");

gtxy(ZL+WID+3,ZL+17);printf("↑鍵:變體");

gtxy(ZL+WID+3,ZL+19);printf("空格:暫停游戲");

gtxy(ZL,ZL);printf("╔");gtxy(ZL+WID-2,ZL);printf("╗");//列印框角

gtxy(ZL,ZL+HEI);printf("╚");gtxy(ZL+WID-2,ZL+HEI);printf("╝");

a[ZL][ZL+HEI]=2;a[ZL+WID-2][ZL+HEI]=2;//記住有圖案

for(i=2;i<WID-2;i+=2){gtxy(ZL+i,ZL);printf("═");}//列印上橫框

for(i=2;i<WID-2;i+=2){gtxy(ZL+i,ZL+HEI);printf("═");a[ZL+i][ZL+HEI]=2;}//下框

for(i=1;i<HEI;i++){gtxy(ZL,ZL+i);printf("║");a[ZL][ZL+i]=2;}//左豎框記住有圖案

for(i=1;i<HEI;i++){gtxy(ZL+WID-2,ZL+i);printf("║");a[ZL+WID-2][ZL+i]=2;}//右框

CONSOLE_CURSOR_INFOcursor_info={1,0};//以下是隱藏游標的設置

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);

level=1;score=0;speed=400;

gflag();flag=next;//獲得一個當前方塊序號

}

voidgflag() //獲得下一個方塊的序號

{srand((unsigned)time(NULL));next=rand()%19+1; }

voidstart()//開始部分

{gflag();Ta=flag;flag=next;//保存當前方塊序號,將下一方塊序號臨時操作

x=ZL+WID+6;y=ZL+10;prfk();//給x,y賦值,在框外列印出下一方塊

flag=Ta;x=ZL+WID/2;y=ZL-1;//取回當前方塊序號,並給x,y賦值

}

voidprfk()//列印俄羅斯方塊

{for(i=0;i<4;i++){b[i]=1;}//數組b[4]每個元素的值都為1

mkfk();//製作俄羅斯方塊

for(i=x-2;i<=x+4;i+=2)//列印方塊

{for(j=y-2;j<=y+1;j++){if(a[i][j]==1&&j>ZL){gtxy(i,j);printf("□");}}}

gtxy(ZL+WID+3,ZL+1); printf("level:%d",level); //以下列印菜單信息

gtxy(ZL+WID+3,ZL+3); printf("score:%d",score);

gtxy(ZL+WID+3,ZL+5); printf("speed:%d",speed);

}

voidclfk()//清除俄羅斯方塊

{for(i=0;i<4;i++){b[i]=0;}//數組b[4]每個元素的值都為0

mkfk();//製作俄羅斯方塊

for(i=x-2;i<=x+4;i+=2)//清除方塊

{for(j=y-2;j<=y+1;j++){if(a[i][j]==0&&j>ZL){gtxy(i,j);printf("");}}}

}

voidmkfk()//製作俄羅斯方塊

{a[x][y]=b[0];//方塊中心位置狀態:1-有,0-無

switch(flag)//共6大類,19種小類型

{case1:{a[x][y-1]=b[1];a[x+2][y-1]=b[2];a[x+2][y]=b[3];break;}//田字方塊

case2:{a[x-2][y]=b[1];a[x+2][y]=b[2];a[x+4][y]=b[3];break;}//直線方塊:----

case3:{a[x][y-1]=b[1];a[x][y-2]=b[2];a[x][y+1]=b[3];break;}//直線方塊:|

case4:{a[x-2][y]=b[1];a[x+2][y]=b[2];a[x][y+1]=b[3];break;}//T字方塊

case5:{a[x][y-1]=b[1];a[x][y+1]=b[2];a[x-2][y]=b[3];break;}//T字順時針轉90度

case6:{a[x][y-1]=b[1];a[x-2][y]=b[2];a[x+2][y]=b[3];break;}//T字順轉180度

case7:{a[x][y-1]=b[1];a[x][y+1]=b[2];a[x+2][y]=b[3];break;}//T字順轉270度

case8:{a[x][y+1]=b[1];a[x-2][y]=b[2];a[x+2][y+1]=b[3];break;}//Z字方塊

case9:{a[x][y-1]=b[1];a[x-2][y]=b[2];a[x-2][y+1]=b[3];break;}//Z字順轉90度

case10:{a[x][y-1]=b[1];a[x-2][y-1]=b[2];a[x+2][y]=b[3];break;}//Z字順轉180度

case11:{a[x][y+1]=b[1];a[x+2][y-1]=b[2];a[x+2][y]=b[3];break;}//Z字順轉270度

case12:{a[x][y-1]=b[1];a[x][y+1]=b[2];a[x-2][y-1]=b[3];break;}//7字方塊

case13:{a[x-2][y]=b[1];a[x+2][y-1]=b[2];a[x+2][y]=b[3];break;}//7字順轉90度

case14:{a[x][y-1]=b[1];a[x][y+1]=b[2];a[x+2][y+1]=b[3];break;}//7字順轉180度

case15:{a[x-2][y]=b[1];a[x-2][y+1]=b[2];a[x+2][y]=b[3];break;}//7字順轉270度

case16:{a[x][y+1]=b[1];a[x][y-1]=b[2];a[x+2][y-1]=b[3];break;}//倒7字方塊

case17:{a[x-2][y]=b[1];a[x+2][y+1]=b[2];a[x+2][y]=b[3];break;}//倒7字順轉90度

case18:{a[x][y-1]=b[1];a[x][y+1]=b[2];a[x-2][y+1]=b[3];break;}//倒7字順轉180度

case19:{a[x-2][y]=b[1];a[x-2][y-1]=b[2];a[x+2][y]=b[3];break;}//倒7字順轉270度

}

}

voidkeyD()//按鍵操作

{if(kbhit())

{intkey;

key=getch();

if(key==224)

{key=getch();

if(key==75){x-=2;}//按下左方向鍵,中心橫坐標減2

if(key==77){x+=2;}//按下右方向鍵,中心橫坐標加2

if(key==72)//按下向上方向鍵,方塊變體

{if(flag>=2&&flag<=3){flag++;flag%=2;flag+=2;}

if(flag>=4&&flag<=7){flag++;flag%=4;flag+=4;}

if(flag>=8&&flag<=11){flag++;flag%=4;flag+=8;}

if(flag>=12&&flag<=15){flag++;flag%=4;flag+=12;}

if(flag>=16&&flag<=19){flag++;flag%=4;flag+=16;}}

}

if(key==32)//按空格鍵,暫停

{prfk();while(1){if(getch()==32){clfk();break;}}} //再按空格鍵,繼續游戲

if(ifmov()==0){x=Tb;flag=Tc;} //如果不可動,撤銷上面操作

else{prfk();Sleep(speed);clfk();Tb=x;Tc=flag;} //如果可動,執行操作

}

}

intifmov()//判斷能否移動

{if(a[x][y]!=0){return0;}//方塊中心處有圖案返回0,不可移動

else{if((flag==1&&(a[x][y-1]==0&&a[x+2][y-1]==0&&a[x+2][y]==0))||

(flag==2&&(a[x-2][y]==0&&a[x+2][y]==0&&a[x+4][y]==0))||

(flag==3&&(a[x][y-1]==0&&a[x][y-2]==0&&a[x][y+1]==0))||

(flag==4&&(a[x-2][y]==0&&a[x+2][y]==0&&a[x][y+1]==0))||

(flag==5&&(a[x][y-1]==0&&a[x][y+1]==0&&a[x-2][y]==0))||

(flag==6&&(a[x][y-1]==0&&a[x-2][y]==0&&a[x+2][y]==0))||

(flag==7&&(a[x][y-1]==0&&a[x][y+1]==0&&a[x+2][y]==0))||

(flag==8&&(a[x][y+1]==0&&a[x-2][y]==0&&a[x+2][y+1]==0))||

(flag==9&&(a[x][y-1]==0&&a[x-2][y]==0&&a[x-2][y+1]==0))||

(flag==10&&(a[x][y-1]==0&&a[x-2][y-1]==0&&a[x+2][y]==0))||

(flag==11&&(a[x][y+1]==0&&a[x+2][y-1]==0&&a[x+2][y]==0))||

(flag==12&&(a[x][y-1]==0&&a[x][y+1]==0&&a[x-2][y-1]==0))||

( flag==13 && ( a[x-2][y]==0 && a[x+2][y-1]==0 && a[x+2][y]==0 ) ) ||

( flag==14 && ( a[x][y-1]==0 && a[x][y+1]==0 && a[x+2][y+1]==0 ) ) ||

(flag==15 && ( a[x-2][y]==0 && a[x-2][y+1]==0 && a[x+2][y]==0 ) ) ||

(flag==16 && ( a[x][y+1]==0 && a[x][y-1]==0 && a[x+2][y-1]==0 ) ) ||

( flag==17 && ( a[x-2][y]==0 && a[x+2][y+1]==0 && a[x+2][y]==0 ) ) ||

(flag==18 && ( a[x][y-1]==0 &&a[x][y+1]==0 && a[x-2][y+1]==0 ) ) ||

(flag==19 && ( a[x-2][y]==0 && a[x-2][y-1]==0

&&a[x+2][y]==0))){return1;}

}

return0; //其它情況返回0

}

voidclNEXT() //清除框外的NEXT方塊

{flag=next;x=ZL+WID+6;y=ZL+10;clfk();}

void clHA() //清除滿行的方塊

{intk,Hang=0; //k是某行方塊個數,Hang是刪除的方塊行數

for(j=ZL+HEI-1;j>=ZL+1;j--)//當某行有WID/2-2個方塊時,則為滿行

{k=0;for(i=ZL+2;i<ZL+WID-2;i+=2)

{if(a[i][j]==1)//豎坐標從下往上,橫坐標由左至右依次判斷是否滿行

{k++; //下面將操作刪除行

if(k==WID/2-2) { for(k=ZL+2;k<ZL+WID-2;k+=2)

{a[k][j]=0;gtxy(k,j);printf("");Sleep(1);}

for(k=j-1;k>ZL;k--)

{for(i=ZL+2;i<ZL+WID-2;i+=2)//已刪行數上面有方塊,先清除再全部下移一行

{if(a[i][k]==1){a[i][k]=0;gtxy(i,k);printf("");a[i][k+1]=1;

gtxy(i,k+1);printf("□");}}

}

j++;//方塊下移後,重新判斷刪除行是否滿行

Hang++;//記錄刪除方塊的行數

}

}

}

}

score+=100*Hang; //每刪除一行,得100分

if(Hang>0&&(score%500==0||score/500>level-1)) //得分滿500速度加快升一級

{speed-=20;level++;if(speed<200)speed+=20; }

}

⑻ c++俄羅斯方塊代碼

||#include <iostream>
#include <windows.h>
#include <vector>
#include <mmsystem.h>
#include <cstdio>

#pragma comment(lib, "winmm.lib")
using namespace std;

#define GameW 10
#define GameH 20
const int CtrlLeft = GameW*2+4 + 3;

struct Point {
Point(){}
Point(int x, int y) {_x = x, _y = y;}
int _x, _y;
};

HANDLE g_hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE g_hInput = GetStdHandle(STD_INPUT_HANDLE);

Point g_ptCursor(0,0);
BOOL isChecking = FALSE;
BOOL g_bGameOver = FALSE;
int g_nGameBack[GameH][GameW], Case;
int nowKeyInfo = -1;
int g_nDiff = 1;
int g_nLife = 2;
int g_nScore = 0;

void SetCursor(COORD cd) {
SetConsoleCursorPosition(g_hOutput, cd);
}
void SetCursor(int x, int y){
COORD cd = {x, y};
SetCursor(cd);
}
void SetBlockCursor(int x, int y){
COORD cd = {2*x + 2, y + 1};
SetCursor(cd);
}

void SetBack(int x, int y, BOOL bk) {
SetBlockCursor(x, y);
if (bk)
printf("%s", "■");
else
printf("");
}

bool Out(int x, int y) {
return x < 0 || y < 0 || x >= GameW || y >= GameH;
}

struct xBlock {
public:
int len;
int nowRotateID;
BOOL mask[4][4][4];
static vector <xBlock> List;

xBlock() { len = 0; }
xBlock(int l, char *str) {
int i, j, k;
len = l;
memset(mask, FALSE, sizeof(mask));
for (i = 0; i < l; i++) {
for (j = 0; j < l; j++) {
mask[0][i][j] = str[i*l + j] - '0';
}
}
for (k = 1; k < 4; k++) {
for (i = 0; i < len; i++) {
for (j = 0; j < len; j++) {
mask[k][i][j] = mask[k-1][j][len-1-i];
}
}
}
nowRotateID = rand() % 4;
}

void rotate() {
nowRotateID ++;
if (nowRotateID >= 4)
nowRotateID = 0;
}

BOOL getUnit(int x, int y, int roID) {
if (roID == -1) {
roID = nowRotateID;
}
return mask[roID][y][x];
}
};

vector <xBlock> xBlock::List;

class Block {
public:
int x, y;
int ID;
xBlock bk;

void reset(xBlock *pbk) {
bk = *pbk;

x = 4, y = 0;
ID = ++ Case;

if (collide(0,0)) {
lifeDown();
}
draw();

*pbk = xBlock::List[rand() % xBlock::List.size()];
}

void lifeDown() {
int i, j;
for (i = 0; i < GameH; i++) {
for (j = 0; j < GameW; j++) {
SetBack(j, i, TRUE);
Sleep(10);
}
}
if (g_nLife) {
g_nLife --;
for (i = g_nLife; i < 6; i++) {
SetCursor(CtrlLeft + i, 15);
printf("%c", ' ');
}
for (i = GameH-1; i >= 0; i--) {
for (j = GameW-1; j >= 0; j--) {
SetBack(j, i, FALSE);
Sleep(10);
g_nGameBack[i][j] = 0;
}
}
}else {
g_bGameOver = TRUE;
}
}

void erase() {
int i, j;
for (i = 0; i < bk.len; i++) {
for (j = 0; j < bk.len; j++) {
if (bk.getUnit(j, i, -1)) {
if (! Out(j+x, i+y) && g_nGameBack[i+y][j+x]) {
SetBack(j+x, i+y, FALSE);
g_nGameBack[i+y][j+x] = 0;
}
}
}
}
}
void draw() {
int i, j;
for (i = 0; i < bk.len; i++) {
for (j = 0; j < bk.len; j++) {
if (bk.getUnit(j, i, -1)) {
if (! Out(j+x, i+y) && ! g_nGameBack[i+y][j+x]) {
SetBack(j+x, i+y, TRUE);
g_nGameBack[i+y][j+x] = ID;
}
}
}
}
}
void draw(int x, int y) {
int i, j;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
SetCursor(x + 2*j, y + i);
if (bk.getUnit(j, i, -1)) {
printf("%s", "■");
}else
printf("");
}
}
}
bool collide(int dx, int dy, int roID = -1) {
int i, j;
for (i = 0; i < bk.len; i++) {
for (j = 0; j < bk.len; j++) {
if (bk.getUnit(j, i, roID)) {
Point ptPos(j + x + dx, i + y + dy);
if (Out(ptPos._x, ptPos._y)
|| g_nGameBack[ptPos._y][ptPos._x] && ID != g_nGameBack[ptPos._y][ptPos._x]) {
return TRUE;
}
}
}
}
return FALSE;
}

void rotate(int nTimes = 1) {
int nextro = (bk.nowRotateID + nTimes) % 4;
if (collide(0, 0, nextro)) {
return ;
}
Beep(12000, 50);
erase();
bk.nowRotateID = nextro;
draw();
}

BOOL changepos(int dx, int dy) {
if (collide(dx, dy)) {
return FALSE;
}
erase();
x += dx;
y += dy;
draw();
return TRUE;
}
};

void GameInit() {
CONSOLE_CURSOR_INFO cursor_info;
cursor_info.bVisible = FALSE;
cursor_info.dwSize = 100;
SetConsoleCursorInfo(g_hOutput, &cursor_info);
xBlock::List.push_back(xBlock(3, "010111000"));
xBlock::List.push_back(xBlock(3, "110110000"));
xBlock::List.push_back(xBlock(3, "111001000"));
xBlock::List.push_back(xBlock(3, "111100000"));
xBlock::List.push_back(xBlock(3, "110011000"));
xBlock::List.push_back(xBlock(3, "011110000"));
xBlock::List.push_back(xBlock(4, "1000100010001000"));
}

void DrawFrame(int x, int y, int nWidth, int nHeight) {
int i;
for (i = 0; i < nWidth; i++) {
SetCursor(x + 2*i + 2, y);
printf("%s", "一");
SetCursor(x + 2*i + 2, y + nHeight+1);
printf("%s", "┄");
}
for (i = 0; i < nHeight; i++) {
SetCursor(x, y + i + 1);
printf("%s", "┆");
SetCursor(x + nWidth*2+2, y + i + 1);
printf("%s", "┆");
}
SetCursor(x, y);
printf("%s", "┌");
SetCursor(x, y + nHeight+1);
printf("%s", "└");
SetCursor(x + nWidth*2+2, y);
printf("%s", "┐");
SetCursor(x + nWidth*2+2, y + nHeight+1);
printf("%s", "┘");
}

void MissionInit() {
memset(g_nGameBack, FALSE, sizeof(g_nGameBack));
Case = 1;
int i;
DrawFrame(0, 0, GameW, GameH);
DrawFrame(GameW*2+4, 0, 4, GameH);
SetCursor(CtrlLeft, 2);
printf("Next");

SetCursor(CtrlLeft, 8);
printf("Speed");
for (i = 0; i < g_nDiff; i++) {
SetCursor(CtrlLeft + i, 9);
printf("%c", 1);
}

SetCursor(CtrlLeft, 11);
printf("Score");
SetCursor(CtrlLeft, 12);
printf("%d", g_nScore);

SetCursor(CtrlLeft, 14);
printf("Life");
for (i = 0; i < g_nLife; i++) {
SetCursor(CtrlLeft + i, 15);
printf("%c", 3);
}
}

void Check() {
isChecking = TRUE;
int i, j, k;
vector <int> line;
for (i = 0; i < GameH; i++) {
for (j = 0; j < GameW; j++) {
if (! g_nGameBack[i][j])
break;
}
if (j == GameW) {
line.push_back(i);
}
}
if (line.size()) {
int nCount = 7;
while (nCount --) {
for (i = 0; i < line.size(); i++) {
for (j = 0; j < GameW; j++) {
SetBack(j, line[i], nCount&1);
}
}
Sleep(70);
}
for (i = 0; i < line.size(); i++) {
for (j = 0; j < GameW; j++) {
g_nGameBack[line[i]][j] = 0;
}
}

for (i = 0; i < GameW; i++) {
int next = GameH-1;
for (j = GameH-1; j >= 0; j--) {
for (k = next; k >= 0; k--) {
if (g_nGameBack[k][i])
break;
}
next = k - 1;
BOOL is = (k >= 0);
SetBack(i, j, is);
g_nGameBack[j][i] = is;
}
}

g_nScore += 2*line.size()-1;
SetCursor(CtrlLeft, 12);
printf("%d", g_nScore);

if ( g_nScore >= g_nDiff * g_nDiff * 10) {
if (g_nDiff <= 6)
g_nDiff ++;
}
if ( g_nScore >= 50 * (g_nLife+1)) {
if (g_nLife <= 6)
g_nLife ++;
}
}

isChecking = FALSE;
}
int main() {
Block* obj = new Block();
Block* buf = new Block();

BOOL bCreateNew = FALSE;
int nTimer = GetTickCount();
int LastKeyDownTime = GetTickCount();

GameInit();
MissionInit();

buf -> bk = xBlock::List[rand() % xBlock::List.size()];
while (1) {
if (! bCreateNew) {
bCreateNew = TRUE;
obj -> reset(&buf -> bk);
if (g_bGameOver)
break;
buf -> draw(CtrlLeft - 1, 4);
}
if (GetTickCount() - nTimer >= 1000 / g_nDiff) {
nTimer = GetTickCount();
if (! obj -> collide(0, 1))
obj -> changepos(0, 1);
else {
Check();
bCreateNew = FALSE;
}
}
if (GetTickCount() - LastKeyDownTime >= 100) {
if (FALSE == isChecking) {
LastKeyDownTime = GetTickCount();
if (GetAsyncKeyState(VK_UP)) {
obj -> rotate();
}
if (GetAsyncKeyState(VK_LEFT)) {
obj -> changepos(-1, 0);
}
if (GetAsyncKeyState(VK_RIGHT)) {
obj -> changepos(1, 0);
}
if (GetAsyncKeyState(VK_DOWN)) {
if ( FALSE == obj -> changepos(0, 2) )
obj -> changepos(0, 1);
}
}
}
}
SetCursor(8, 10);
printf("Game Over!");

SetCursor(0, GameH + 3);

while (1) {
if (GetAsyncKeyState(VK_ESCAPE))
break;
}
return 0;
}