给大家提供几个小游戏,复制应该难度都不大
#include <cstdlib>
#include <bits/stdc++.h>
#include <queue>
#include <stack>
#include <ctime>
using namespace std;
int money=100;
int t=0;
int tt=-1;
int v;
int d;
void borrow()
{
if(tt!=-1)
{
cout<<"你现在不能借钱"<<endl;
return;
}
cout<<"你要借多少钱?"<<endl;
cin>>v;
if (d==1||d==2)
{
if (v>1000) cout<<"你不能借这么多钱!"<<endl,cout<<"你要借多少钱?"<<endl,cin>>v;
if (v<=1000) money+=v,cout<<"10天以后你要还"<<2*v<<"美元"<<endl;
return;
}
else
{
if (v>100) cout<<"你不能借这么多钱!"<<endl,cout<<"你要借多少钱?"<<endl,cin>>v;
if (v<=100) money+=v,cout<<"10天以后你要还"<<2*v<<"美元"<<endl;
return;
}
}
bool pay()
{
cout<<"你现在要还 "<<2*v<<endl;
money-=2*v;
tt=-1;
v=0;
if(money<=0) return false;
else return true;
}
int main(int argc, char *argv[])
{
cout<<"欢迎来到彩票游戏!"<<endl<<endl<<"温馨提示:在游戏内请勿使用小数、负数、英文字母、特殊字符(游戏中另说明除外),"<<endl<<"否则后果自负。"<<endl<<endl;
cout<<"请选择难度(输入序号即可):"<<endl<<"1:入门"<<" "<<"2:简单"<<" "<<"3:普通"<<" "<<"4:中等"<<" "<<"5:困难"<<endl;
cin>>d;
if (d==1) cout<<"已选择难度:入门"<<endl<<endl;
if (d==2) cout<<"已选择难度:简单"<<endl<<endl;
if (d==3) cout<<"已选择难度:普通"<<endl<<endl;
if (d==4) cout<<"已选择难度:中等"<<endl<<endl;
if (d==5) cout<<"已选择难度:困难"<<endl<<endl;
while(1)
{
if (d<1) cout<<"没有这个选项"<<endl<<"请选择难度(输入序号即可):"<<endl<<"1:入门"<<" "<<"2:简单"<<" "<<"3:普通"<<" "<<"4:中等"<<" "<<"5:困难"<<endl,cin>>d;
if (d>5) cout<<"没有这个选项"<<endl<<"请选择难度(输入序号即可):"<<endl<<"1:入门"<<" "<<"2:简单"<<" "<<"3:普通"<<" "<<"4:中等"<<" "<<"5:困难"<<endl,cin>>d;
if (d==1 || d==2 || d==3 || d==4 || d==5) break;
}
bool flag=true;
srand(time(0));
int a[10000];
int n,p;
char c[4];
if (d==1)
{
cout<<"每张彩票 购入价为1美元,出售价为5美元,有五个奖项"<<endl<<"小奖:10美元"<<endl<<"中奖:20美元"<<endl<<"大奖:100美元"<<endl<<"巨额奖金:1,000美元"<<endl<<"杰克壶:10,000美元"<<endl;
cout<<"你有100美元,当你赚了超过10,000美元,你就发财了。"<<endl<<"但如果你失去了所有的钱,你破产了。"<<endl;
cout<<"你可能想借钱(最多1,000美元),如果你想,按0。"<<endl<<"请记住,当你借了十天以后。你必须偿还两倍,"<<endl;
cout<<"你想买彩票还是卖彩票?(buy/sell)"<<endl;
}
if (d==2)
{
cout<<"每张彩票 购入价为2美元,出售价为3美元,有五个奖项"<<endl<<"小奖:5美元"<<endl<<"中奖:20美元"<<endl<<"大奖:100美元"<<endl<<"巨额奖金:1,000美元"<<endl<<"杰克壶:10,000美元"<<endl;
cout<<"你有100美元,当你赚了超过10,000美元,你就发财了。"<<endl<<"但如果你失去了所有的钱,你破产了。"<<endl;
cout<<"你可能想借钱(最多1,000美元),如果你想,请按0。"<<endl<<"请记住,当你借了十天以后。你必须偿还两倍,"<<endl;
cout<<"你想买彩票还是卖彩票?(buy/sell)"<<endl;
}
if (d==3)
{
cout<<"每张彩票 售价2美元,有五个奖项"<<endl<<"小奖:5美元"<<endl<<"中奖:20美元"<<endl<<"大奖:100美元"<<endl<<"巨额奖金:1,000美元"<<endl<<"杰克壶:10,000美元"<<endl;
cout<<"你有100美元,当你赚了超过10,000美元,你就发财了。"<<endl<<"但如果你失去了所有的钱,你破产了。"<<endl;
cout<<"你可能想借钱(最多100美元),如果你想,请按0。"<<endl<<"请记住,当你借了十天以后。你必须偿还两倍,"<<endl;
cout<<"你想买彩票还是卖彩票?(buy/sell)"<<endl;
}
if (d==4)
{
cout<<"每张彩票 售价3美元,有五个奖项"<<endl<<"小奖:5美元"<<endl<<"中奖:20美元"<<endl<<"大奖:100美元"<<endl<<"巨额奖金:1,000美元"<<endl<<"杰克壶:10,000美元"<<endl;
cout<<"你有100美元,当你赚了超过100,000美元,你就发财了。"<<endl<<"但如果你失去了所有的钱,你破产了。"<<endl;
cout<<"你可能想借钱(最多100美元),如果你想,请按0。"<<endl<<"请记住,当你借了七天以后。你必须偿还两倍,"<<endl;
cout<<"你想买彩票还是卖彩票?(buy/sell)"<<endl;
}
if (d==5)
{
cout<<"每张彩票 购入价为5美元,出售价为2美元,有五个奖项"<<endl<<"小奖:5美元"<<endl<<"中奖:20美元"<<endl<<"大奖:100美元"<<endl<<"巨额奖金:1,000美元"<<endl<<"杰克壶:5,000美元"<<endl;
cout<<"你有100美元,当你赚了超过100,000美元,你就发财了。"<<endl<<"但如果你失去了所有的钱,你就破产了。"<<endl;
cout<<"你可能想借钱(最多100美元),如果你想,请按0。"<<endl<<"请记住,当你借了五天以后。你必须偿还两倍,"<<endl;
cout<<"你想买彩票还是卖彩票?(buy/sell)"<<endl;
}
cin>>c;
if(c[0]=='b'||c[0]=='B')
{
while(money>0)
{
if (d==1||d==2||d==3) if(money>=10000)
{
cout<<"你发财了! "<<endl;
cout<<"你花了 "<<t<<"天"<<endl;
system("pause");
return 0;
}
if (d==4||d==5) if(money>=100000)
{
cout<<"你发财了! "<<endl;
cout<<"你花了 "<<t<<"天"<<endl;
system("pause");
return 0;
}
t++;
cout<<"你要买几张票?"<<" "<<"你有$"<<money<<endl;
cin>>n;
if(n==0)
{
if (d=4)
{
borrow();
tt=t+7;
}
if (d=5)
{
borrow();
tt=t+5;
}
else
{
borrow();
tt=t+10;
}
}
if(t==tt)
{
flag=pay();
}
if(t==tt-1) cout<<"[警告]你必须在明天还钱!"<<endl;
if(flag==false)
{
cout<<"你不能偿还你借的钱!"<<endl;
cout<<"你破产了。"<<endl;
cout<<"你生存了"<<t<<"天。"<<endl;
system("pause");
return 0;
}
flag=true;
if(n<0)
{
cout<<"因为你违反规则,所以系统强制停止了你的游戏"<<endl;
system("pause");
}
if (d==1) money=money-n;
if (d==2||d==3) money=money-n*2;
if (d==4) money=money-n*3;
if (d==5) money=money-n*5;
if(money<0)
{
cout<<"你破产了。"<<endl;
cout<<"你生存了"<<t<<"天"<<endl;
system("pause");
return 0;
}
for(int i=0; i<n; i++)
{
p=rand()%12000;
if(p==0)
{
int q=0;
q=rand()%4;
if(q==1)
{
cout<<"你获得了杰克壶!"<<endl;
if (d==5) money+=5000;
else money+=10000;
}
}
else if(p>=1&&p<=8)
{
int g=0;
g=rand()%2;
if(g==0)
{
cout<<"你获得了巨额奖金! "<<endl;
money+=1000;
}
}
else if(p>=9&&p<=99)
{
cout<<"你获得了大奖!"<<endl;
money+=100;
}
else if((p>=100&&p<=399)||(p>1500&&p<=1600))
{
cout<<"你获得了中间奖!"<<endl;
money+=20;
}
else if(p>=400&&p<=1500)
{
cout<<"你获得了小奖!"<<endl;
if (d==1) money+=10;
else money+=5;
}
}
if(money<=0)
{
cout<<"你破产了。"<<endl;
cout<<"你生存了"<<t<<"天。"<<endl;
system("pause");
return 0;
}
}
}
if(c[0]=='s'||c[0]=='S')
{
if (d==1)
{
cout<<"你有$"<<money<<endl;
cout<<"你必须付25美元买一个商店。 "<<endl;
cout<<"你只能卖同样数量的票作为你的钱。 "<<endl;
money-=25;
}
if (d==2)
{
cout<<"你有$"<<money<<endl;
cout<<"你必须付35美元买一个商店。 "<<endl;
cout<<"你只能卖同样数量的票作为你的钱。 "<<endl;
money-=35;
}
if (d==3||d==4)
{
cout<<"你有$"<<money<<endl;
cout<<"你必须付50美元买一个商店。 "<<endl;
cout<<"你只能卖同样数量的票作为你的钱。 "<<endl;
money-=50;
}
if (d==5)
{
cout<<"你有$"<<money<<endl;
cout<<"你必须付60美元买一个商店。 "<<endl;
cout<<"你只能卖同样数量的票作为你的钱。 "<<endl;
money-=60;
}
cout<<"你有$"<<money<<endl;
while(money>0)
{
if (d==1||d==2||d==3) if(money>=10000)
if (d==4||d==5) if(money>=100000)
{
cout<<"你发财了!"<<endl;
cout<<"你花了"<<t<<"天。"<<endl;
system("pause");
return 0;
}
t++;
cout<<"你要卖几张票? "<<" "<<"你有$"<<money<<endl;
cin>>n;
if(n==0)
{
borrow();
tt=t+10;
}
if(t==tt) bool flag=pay();
if(flag==false)
{
cout<<"你不能偿还你借的钱。"<<endl;
cout<<"你破产了!"<<endl;
cout<<"你生存了"<<t<<" 天。"<<endl;
system("pause");
return 0;
}
if(n<0 || n>money)
{
cout<<"注意"<<endl;
cout<<"你破产了!"<<endl;
cout<<"你生存了"<<t<<" 天"<<endl;
system("pause");
return 0;
}
if (d=1) money=money+n*5;
if (d=2) money=money+n*3;
else money=money+n*2;
if(money<0)
{
cout<<"你破产了!"<<endl;
cout<<"你生存了"<<t<<" 天"<<endl;
system("pause");
return 0;
}
for(int i=0; i<n; i++)
{
p=rand()%12000;
if(p==0)
{
int y;
y=rand()%4;
if(y==1)
{
cout<<"你失去了杰克壶!"<<endl;
if (d==5) money-=5000;
else money-=10000;
}
}
else if(p>=1&&p<=8)
{
cout<<"你失去了巨额奖金!"<<endl;
money-=1000;
}
else if(p>=15&&p<=50)
{
cout<<"你失去了大奖!"<<endl;
money-=100;
}
else if(p>=61&&p<=360)
{
cout<<"你失去了中奖!"<<endl;
money-=20;
}
else if(p>=401&&p<=1500)
{
cout<<"你失去了小奖!"<<endl;
money-=5;
}
}
}
}
if(money<=0)
{
cout<<"你破产了。"<<endl;
cout<<"你生存了"<<t<<"天。"<<endl;
system("pause");
return 0;
}
}#include<bits/stdc++.h>
#include<windows.h>
#include<ctime>
int a[4][4],i,j,xc,yc,mouse=0,ok=0,record[2][9],foot=9,winner,first=0,who=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);}
int search(int x0,int y0,int x,int y)
{
mouse=GetAsyncKeyState(VK_LBUTTON);
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;
}
bool check(int x)
{
int b=0,c=0,d=0,e=0;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++) {b+=a[i][j]; c+=a[j][i];} d+=a[i][i]; e+=a[i][4-i];
if(b==x||c==x||d==x||e==x) return true; b=0; c=0;
}
return false;
}
void pcmove()
{
int x=10,b=0,c=0,d=0,e=0; xc=0; yc=0;
while(x>0)
{
for(i=1;i<=3;i++)
{
b=0; c=0; for(j=1;j<=3;j++) {b+=a[i][j]; c+=a[j][i];} d+=a[i][i]; e+=a[i][4-i];
if(b==x) {for(j=1;j<=3;j++) if(a[i][j]==0) {xc=i; yc=j; return;}} if(c==x) {for(j=1;j<=3;j++) if(a[j][i]==0) {xc=j; yc=i; return;}}
if(d==x) {for(j=1;j<=3;j++) if(a[j][j]==0) {xc=yc=j; return;}} if(e==x) {for(j=1;j<=3;j++) if(a[j][4-j]==0) {xc=j; yc=4-j; return;}}
} x-=8;
}
if(a[2][2]==0) {xc=yc=2; return;} x=2;
while(x>0) {for(i=1;i<=3;i+=x) for(j=1;j<=3;j+=x) if(a[i][j]==0) {xc=i; yc=j; return;} x--;}
}
void show()
{
int x=foot;
for(i=1;i<=3;i++) for(j=1;j<=3;j++) if(a[i][j]!=0) {if(a[i][j]==1) color(15); else color(11); Place(2*i-1,4*j-2); printf("●");}
color(15); Place(7,0);
if(who==0) {if(foot%2==1) printf("1号"); else printf("2号");} else printf("电脑");
if(who==0||first==1) x--;
printf("下子:(%d,%d)",record[0][8-x],record[1][8-x]);
}
void button(int x)
{
if(x<3)
{
Place(x*3,15); printf("┌┄┄┐");
Place(x*3+1,17); if(x==0){if(ok==0) printf("开始"); else printf("悔棋");} if(x==1) printf("重来"); if(x==2) printf("退出");
Place(x*3+2,15); printf("└┄┄┘");
}
if(x>2&&x<6)
{
Place(10,(x-4)*7); printf("┌┄┐");
Place(11,(x-4)*7+2); if(x==4) printf("是"); else printf("否");
Place(12,(x-4)*7); printf("└┄┘");
}
if(x>5&&x<8)
{
Place(10,(x-6)*12); printf("┌┄┄┄┄┐");
Place(11,(x-6)*12+2); if(x==6) printf("人机对战"); else printf("人人对战");
Place(12,(x-6)*12); printf("└┄┄┄┄┘");
}
if(x>7)
{
Place(10,(x-8)*12); printf("┌┄┄┄┄┐");
Place(11,(x-8)*12+2); if(x==8) printf(" 我先手 "); else printf("电脑先手");
Place(12,(x-8)*12); printf("└┄┄┄┄┘");
}
}
void menu(int x)
{
int k,l;
if(x==0)
{
if(ok==0) {ok=1; return;}
else if(9-foot>1)
{
foot+=2; for(i=9-foot;i<=11-foot;i++) {a[record[0][i]][record[1][i]]=0; record[0][i]=record[1][i]=0;}
for(i=1;i<=3;i++) for(j=1;j<=3;j++) {Place(2*i-1,4*j-2); printf(" ");} show();
}
}
if(x>0&&x<3)
{
for(l=10;l<=12;l++) for(j=1;j<=22;j++) {Place(l,j); printf(" ");}
Place(9,1); printf("你想"); if(x==1) printf("重来吗?"); if(x==2) printf("退出吗?");
button(4); button(5);
while(1)
{
mouse=GetAsyncKeyState(VK_LBUTTON);
for(i=0;i<=1;i++)
{
k=search(7+i*55,165,40+i*55,200);
if(k!=2) {if(k==1) color(15); else color(7); button(i+4);}
else
{for(l=9;l<=12;l++) for(j=1;j<=12;j++) {Place(l,j); printf(" ");}
if(i==0) {if(x==1) ok=2; else exit(0);} return;
}
}
Sleep(50);
}
}
if(x>2&&x<5) {if(x==3) {who=1; return;} else {who=0; return;}}
if(x>4) {if(x==5) {first=0; return;} else {first=1; return;}}
}
void click()
{
for(i=0;i<=2;i++)
{ mouse=GetAsyncKeyState(VK_LBUTTON);
int k=search(125,i*50+5,175,i*50+40);
if(k!=2) {if(k==1) color(15); else color(7); button(i); color(7);}
else{menu(i); return;}
}
Sleep(50);
}
void humove()
{
while(1)
{
for(i=1;i<=3;i++) for(j=1;j<=3;j++) if(search(7+(i-1)*32,7+(j-1)*32,7+i*32,7+j*32)==2&&a[j][i]==0)
{if(who==0&&foot%2!=1) a[j][i]=5; else a[j][i]=1; record[0][9-foot]=j; record[1][9-foot]=i; return;} click(); if(ok==2) return;
}
}
void replace()
{
int k,l,p,q;
Place(7,0); for(i=1;i<=15;i++) printf(" "); for(i=1;i<=3;i++) for(j=1;j<=3;j++) {Place(2*i-1,4*j-2); printf(" "); a[i][j]=0;}
for(i=0;i<2;i++) for(j=0;j<9;j++) record[i][j]=0; foot=9; winner=0; first=0; who=0; ok=1; button(6); button(7);
while(1)
{
for(i=0;i<=1;i++)
{
mouse=GetAsyncKeyState(VK_LBUTTON); k=search(i*80+7,165,i*80+103,200); q=search(125,105,175,140);
if(k!=2) {if(k==1) color(15); else color(7); button(i+6); color(7);}
else
{
menu(i+3); for(l=10;l<=12;l++) for(j=1;j<=22;j++) {Place(l,j); printf(" ");}
if(who==1)
{
button(7); button(8);
while(1)
{
for(j=0;j<=1;j++)
{
mouse=GetAsyncKeyState(VK_LBUTTON); k=search(j*80+7,165,j*80+103,200); q=search(125,105,175,140);
if(k!=2) {if(k==1) color(15); else color(7); button(j+8); color(7);}
else{menu(j+5); for(l=10;l<=12;l++) for(p=1;p<=22;p++) {Place(l,p); printf(" ");} return;}
if(q!=2) {if(q==1) color(15); else color(7); button(2); color(7);} else menu(2);
} Sleep(50);
}
}
return;
}
if(q!=2) {if(q==1) color(15); else color(7); button(2); color(7);} else menu(2);
}
Sleep(50);
}
}
int main()
{
printf("┌─┬─┬─┐\n\n├─┼─┼─┤\n\n├─┼─┼─┤\n\n└─┴─┴─┘\n\n");
for(i=0;i<3;i++) button(i);
while(ok==0) click();
while(1)
{
replace();
while(foot>0&&ok!=0)
{
if(first!=1) {humove(); show(); if(check(3)) {winner=1; ok=0; break;} foot--; if(foot<=0||ok==0||ok==2) break;}
if(who==0&&check(15)) {winner=2;ok=0;break;}
if(who!=0) {pcmove(); record[0][9-foot]=xc; record[1][9-foot]=yc; a[xc][yc]=5; show(); if(check(15)) {winner=2;ok=0;} foot--; first=0;}
}
if(ok==2) {ok=1; continue;} Place(7,0); for(i=1;i<=15;i++) printf(" ");
Place(7,4); color(15); if(winner==0) printf("平局!");
if(who!=0) {if(winner==1) printf("你赢了!"); if(winner==2) printf("你输了!"); Sleep(50);}
else {if(winner==1) printf("1号赢了!"); if(winner==2) printf("2号赢了!"); Sleep(50);}
ok=0; while(ok==0) click();
}
}#include<cstdio>
#include<windows.h>
#include<ctime>
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("┆start ┆"); else printf("┆pause ┆");}
if(x==1) printf("┆reset ┆"); if(x==2) printf("┆ exit ┆");
}
Place(24,m); printf("└┄┄┄┘");
}
else
{
Place(9,m-33); printf("┌┄┄┐");
Place(10,m-33);
{
if(x==4) printf("┆yes ┆"); else printf("┆ no ┆");
}
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("pause");
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); printf("Do you want to "); if(x==1) printf("reset?"); if(x==2) printf("exit?");
button(4); button(5);
while(1)
{
mouse=GetAsyncKeyState(VK_LBUTTON);
for(i=0;i<=1;i++)
{
k=search(63+i*80,150,110+i*80,180);
if(k!=2) {if(k==1) color(15); else color(7); button(i+4);}
else
{for(l=7;l<=12;l++) for(j=2;j<=30;j++) {Place(l,j); printf(" ");}
if(i==0) {if(x==1) ok=2; else exit(0);} return;
}
}
Sleep(50);
}
}
}
void click()
{
for(i=0;i<=2;i++)
{ mouse=GetAsyncKeyState(VK_LBUTTON);
int k=search(i*80+7,360,i*80+71,390);
if(k!=2) {if(k==1) color(15); else color(7); button(i); color(7);}
else{menu(i); return;}
}
Sleep(50);
}
void ss()
{
Place(9,39); printf("%d",score);
if(score>=speed*100)
{
speed++; ti=ti-200;
if(ti<0) ti=0;
else
{
for(i=1;i<=4;i++)
{
Place(9,12); printf("speed up!"); Sleep(70);
Place(9,12); for(j=1;j<=9;j++) printf(" "); Sleep(70);
}Sleep(200);
}
}
if(best<score) best=score;
appear(); Place(12,39); printf("%d",speed); Place(15,39); printf("%d",best);
}
void replace()
{
for(i=1;i<=20;i++) for(j=2;j<=30;j++) {Place(i,j); printf(" ");}
for(i=0;i<=22;i++) for(j=1;j<=15;j++) a[i][j]=0; for(i=1;i<=15;i++) a[23][i]=1; for(i=1;i<=23;i++) {a[i][0]=1; a[i][16]=1;} ss();
tim=800;ti=800;shape=0;add=0;score=0;speed=1;
}
void change(int x)
{
int q=0,l;
for(l=1;l<=x;l++)
{
for(j=0;j<=2+add;j++)
{
for(i=2+add;i>=0;i--)
{
turn[j][q]=ta[i][j];
q++;
if(q>2+add) q=0;
}
}
for(i=0;i<=3;i++) for(j=0;j<=3;j++) ta[i][j]=turn[i][j];
}
}
void born()
{
int x,q=0; srand(time(NULL)); bn=b; shape=nextshape; x=rand()%12+1; if(b==5&&x>1) {x--; add=1;}
for(i=0;i<=2+add;i++) for(j=x;j<=x+2+add;j++) {a[i][j]=nex[i][q]; q++; if(q>2+add) q=0;}add=0;
}
void next()
{
srand(time(NULL)); b=rand()%7; nextshape=rand()%4; add=0;
for(i=3;i<=6;i++) for(j=37;j<=45;j++) {Place(i,j); printf(" ");}
for(i=0;i<=3;i++) for(j=0;j<=3;j++) nex[i][j]=turn[i][j]=ta[i][j]=0; ta[1][1]=2;
if(b==0) ta[1][2]=ta[1][0]=ta[0][1]=2; if(b==1) ta[1][2]=ta[1][0]=ta[0][0]=2; if(b==2) ta[1][2]=ta[1][0]=ta[0][2]=2; if(b==3) ta[1][0]=ta[0][1]=ta[0][2]=2;
if(b==4) ta[0][0]=ta[0][1]=ta[1][2]=2; if(b==5) {ta[1][0]=ta[1][2]=ta[1][3]=2; add=1;} if(b==6) ta[0][0]=ta[0][1]=ta[1][0]=2;
if(nextshape>0&&b!=6)
{change(nextshape); for(i=0;i<=3;i++) for(j=0;j<=3;j++) {nex[i][j]=turn[i][j]; if(nex[i][j]==2) {Place(i+3,j*2+37); printf("■");}}}
else {for(i=0;i<=3;i++) for(j=0;j<=3;j++) {nex[i][j]=ta[i][j]; if(nex[i][j]==2) {Place(i+3,j*2+37); printf("■");}}}
}
void clear()
{
int c=0,f=0,l[23],s=0,k;
for(i=3;i<=22;i++)
{
l[i]=0;
for(j=1;j<=15;j++) c=a[i][j]+c;
if(c==15)
{
for(j=1;j<=15;j++) a[i][j]=0;
for(k=i-1;k>=2;k--) for(j=1;j<=15;j++) a[k+1][j]=a[k][j];
f++; l[i]=1; s=5;
}
c=0;
}
score=score+f*10; while(f>1) {score=score+f*5; f--;} f=0;
while(s>0)
{
for(i=22;i>=3;i--) if(l[i]==1) { Place(i-2,2); for(j=1;j<=15;j++) printf("■");}Sleep(70);
for(i=22;i>=3;i--) if(l[i]==1) { Place(i-2,2); for(j=1;j<=30;j++) printf(" ");}Sleep(70);s--;
}
for(i=3;i<=22;i++) for(j=1;j<=15;j++) {Place(i-2,2*j); printf(" ");} appear();
}
void control()
{
int up,down,right,left,c=0,d=0,x,y,no=0,k,l=0,q=0; k=shape; add=0;
up=GetAsyncKeyState(VK_UP); down=GetAsyncKeyState(VK_DOWN); right=GetAsyncKeyState(VK_RIGHT); left=GetAsyncKeyState(VK_LEFT);
if(down!=0) { tim=0;}
if(left!=0||right!=0)
{
Sleep(100);disappear();
for(i=0;i<=22;i++) for(j=1;j<=15;j++)
{
if(a[i][j]==2&&a[i][j-1]!=1) c++; if(a[i][j]==2&&a[i][j+1]!=1) d++;
}
for(i=0;i<=22;i++) for(j=1;j<=15;j++) if(left!=0&&c==4&&a[i][j]==2) {a[i][j-1]=a[i][j]; a[i][j]=0;}
for(i=0;i<=22;i++) for(j=15;j>=1;j--) if(right!=0&&d==4&&a[i][j]==2) {a[i][j+1]=a[i][j];a[i][j]=0;} appear();
}
if(up!=0&&bn!=6)
{
Sleep(150); disappear();
for(i=0;i<=22;i++)
{
for(j=1;j<=15;j++) if(a[i][j]==2) {x=i; no=1; break;}
if(no==1) break;
} no=0;
for(j=1;j<=15;j++)
{
for(i=0;i<=22;i++) if(a[i][j]==2) {y=j; no=1; break;}
if(no==1) break;
} no=0;
if(k==1) y--; if(k==2) x--; add=0;
if(bn==5) {add=1; if(k==0||k==2) x--; if(k==1||k==3) y--;}
for(i=0;i<=3;i++) for(j=0;j<=3;j++) ta[i][j]=a[x+i][y+j];
if(bn>=0&&bn<5)
{
if(k==0) ta[2][0]=0; if(k==1) ta[0][0]=0; if(k==2) ta[0][2]=0; if(k==3) ta[2][2]=0;
}
if(bn==5)
{ if(k==0) ta[0][3]=ta[2][0]=ta[2][1]=ta[3][1]=ta[3][0]=0;
if(k==1) ta[0][0]=ta[1][0]=ta[0][1]=ta[1][1]=ta[3][3]=0;
if(k==2) ta[3][0]=ta[0][2]=ta[0][3]=ta[1][2]=ta[1][3]=0;
if(k==3) ta[0][0]=ta[2][2]=ta[2][3]=ta[3][2]=ta[3][3]=0;
}
for(i=0;i<=2+add;i++) for(j=0;j<=2+add;j++) if(ta[i][j]!=1) l++;
if(l==9+add*7)
{
change(1);
for(i=0;i<=22;i++) for(j=1;j<=15;j++) if(a[i][j]==2) a[i][j]=0;
for(i=0;i<=2+add;i++) for(j=0;j<=2+add;j++) if(turn[i][j]==2) a[x+i][y+j]=turn[i][j]; shape++;
}
if(shape>3) shape=0; appear();
}
}
int main()
{
int k,start,finish,d; printf("┌"); for(i=1;i<=15;i++) printf("┄"); printf("┐\n");
for(i=1;i<=20;i++) printf("┆\n"); printf("└");
for(i=1;i<=15;i++) printf("┄"); printf("┘"); for(i=1;i<=20;i++) {Place(i,32); printf("┆\n");}
Place(2,37); printf("NEXT"); Place(8,37); printf("SCORE"); Place(14,37); printf("BEST"); Place(11,37); printf("SPEED");
for(i=0;i<=2;i++) button(i);
while(ok==1) click();
while(ok!=1)
{
replace(); next();
while(1)
{
born();
next();
while(1)
{
appear();
k=0;
start=clock();
while(1)
{
finish=clock(); d=finish-start;
if(d>=tim) break;
control(); click(); if(ok==2) break;
}
if(ok==2) break; disappear();
for(i=22;i>=0;i--) for(j=1;j<=15;j++) if(a[i][j]==2&&a[i+1][j]!=1) k++;
if(k==4)
{
for(i=22;i>=0;i--) for(j=1;j<=15;j++) if(a[i][j]==2)
{
a[i+1][j]=2;a[i][j]=0;
}
}
else
{
for(i=22;i>=0;i--) for(j=1;j<=15;j++) if(a[i][j]==2) a[i][j]=1;
break;
}
tim=ti; appear();
}
if(ok==2) break;
appear();clear();ss();
for(i=1;i<=15;i++) if(a[2][i]==1) {ok=1; break;}
}
if(ok==2) {ok=0; continue;}
for(i=1;i<=20;i++) for(j=2;j<=30;j++) {Place(i,j); printf(" ");}
Place(9,12); printf("GAME OVER!");
while(ok==1) click();
}
return 0;
}