以下是C++写俄罗斯方块的具体代码(各位宝子们点个赞吧!谢谢!):
//上下左右键控制
#include<bits/stdc++.h>
#include<windows.h>
int a[24][17],i,j,tim=800,ti=800,shape=0,b,bn,ta[4][4],turn[4][4],nex[4][4],nextshape,add=0,score=0,speed=1,ok=1,mouse=0,best=0;
void Place(const int x, const int y)
{
COORD PlaceCursorHere;
PlaceCursorHere.X = y;
PlaceCursorHere.Y = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), PlaceCursorHere);
return;
}
void color(int x)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
}
void appear()
{
for(i=3; i<=22; i++) for(j=1; j<=15; j++) if(a[i][j]!=0)
{
Place(i-2,2*j);
printf("■");
}
}
void disappear()
{
for(i=3; i<=22; i++) for(j=1; j<=15; j++) if(a[i][j]==2)
{
Place(i-2,2*j);
printf(" ");
}
}
int search(int x0,int y0,int x,int y)
{
POINT pt;
HWND h=GetForegroundWindow();
GetCursorPos(&pt);
ScreenToClient(h,&pt);
if(pt.x>=x0&&pt.y>=y0&&pt.x<=x&&pt.y<=y)
{
if(mouse!=0)
{
Sleep(100);
return 2;
}
else return 1;
}
else return 0;
}
void button(int x)
{
int m=x*10;
if(x<3)
{
Place(22,m);
printf("┌┄┄┄┐");
Place(23,m);
{
if(x==0)
{
if(ok!=0) printf("┆开始 ┆");
else printf("┆暂停 ┆");
}
if(x==1) printf("┆重置 ┆");
if(x==2) printf("┆退出 ┆");
}
Place(24,m);
printf("└┄┄┄┘");
}
else
{
Place(9,m-33);
printf("┌┄┄┐");
Place(10,m-33);
{
if(x==4) printf("┆是┆");
else printf("┆否┆");
}
Place(11,m-33);
printf("└┄┄┘");
}
}
void menu(int x)
{
int k,l;
if(x==0)
{
if(ok!=0)
{
ok=0;
return;
}
else while(1)
{
mouse=GetAsyncKeyState(VK_LBUTTON);
Place(9,13);
printf("暂停");
if(search(7,360,71,390)==2) break;
Sleep(50);
}
Place(9,12);
for(j=1; j<=6; j++) printf(" "); //appear();
}
else
{
for(i=1; i<=20; i++) for(j=2; j<=30; j++)
{
Place(i,j);
printf(" ");
}
Place(7,2);
for(i=1; i<=15; i++) printf("┄");
Place(12,2);
for(i=1; i<=15; i++) printf("┄");
Place(8,6);