目录
俄罗斯方块(上下左右键控制)
Fly bird
贪吃蛇
吃豆人
迷宫(随机)
打方块
狼人杀(人机)
俄罗斯方块(上下左右键控制)
//上下左右键控制
#include
#include
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);
printf("你想要 ");
if(x==1) printf("重置?");
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("加速!");
Sleep(70);
Place(9,12);
for(j=1; j<=9; j++) printf(" ");
Sleep(70);
}
Sleep(200);
}
}
if(best=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("下一个");
Place(8,37);
printf("得分");
Place(14,37);
printf("最高分");
Place(11,37);
printf("速度");
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("游戏结束!");
while(ok==1) click();
}
return 0;
}
Fly bird
#include
#include
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade=1,C_Gold=0,C_Ag=0,Score=0,Delay_time=1000,Max_blank=9,Distance=18;
struct Birds {
int x,y;
int condition;
};
Birds*Bird=(Birds*)malloc(sizeof(Birds));
struct Bg {
int x,y;
int l_blank;
int reward[9];
Bg*pri;
Bg*next;
};
Bg*Bg1=new Bg[sizeof(Bg)];
void Position(int x,int y) {
COORD pos= {x-1,y-1};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out,pos);
}
void CreatBird() {
Bird->x=41;
Bird->y=10;
Bird->condition=0;
}
void CreatBg() {
Bg*Bg2=(Bg*)malloc(sizeof(Bg));
Bg1->x=90;
Bg1->y=8;
Bg2->x=Bg1->x+Distance;
Bg2->y=9;
Bg1->l_blank=Max_blank-Grade;
Bg2->l_blank=Max_blank-Grade;
Bg1->next=Bg2;
Bg1->pri=Bg2;
Bg2->next=Bg1;
Bg2->pri=Bg1;
}
void InsertBg(Bg*p) {
int temp;
Bg*Bgs=(Bg*)malloc(sizeof(Bg));
Bgs->x=p->pri->x+Distance;
Bgs->l_blank=Max_blank-Grade;
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->pri->y+Max_blank-Grade)<21)Bgs->y=p->pri->y+temp%4;
else Bgs->y=p->pri->y;
} else {
if((p->pri->y-temp%4)>2)Bgs->y=p->pri->y-temp%4;
else Bgs->y=p->pri->y;
}
Bgs->pri=p->pri;
Bgs->next=p;
p->pri->next=Bgs;
p->pri=Bgs;
}
void Check_Bg(Bg*q) {
Bg*p=q;
int i=0,temp;
while(++i<=5) {
if(p->x>-4)p=p->next;
else {
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->y+Max_blank-Grade)<21)p->y=p->y+temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
} else {
if((p->y-temp%4)>2)p->y=p->y-temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
}
}
}
}
void Loop_Bg(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
p->x=p->x-1;
p=p->next;
if(Bird->x==p->x) {
Score+=1;
if(Score%4==0&&Grade<4)Grade++;
}
}
}
void Prt_Bg(Bg*q) {
Bg*p=q;
int i=0,k,j;
while(++i<=5) {
if(p->x>0&&p->x<=78) {
for(k=2; ky; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank
}
Position(p->x,p->y);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
Position(p->x,p->y+p->l_blank);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
k=k+p->l_blank+1;
for(k; k<=22; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank;
}
Position(p->x,23);
for(k=1; knext;
if(p->x==0) {
for(j=2; jy; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
Position(p->x+1,p->y);
PR_Blank;
PR_Blank;
PR_Blank;
Position(p->x+1,p->y+Max_blank-Grade);
PR_Blank;
PR_Blank;
PR_Blank;
j=j+Max_blank-Grade+1;
for(j; j<=22; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
}
}
}
void PrtBg() {
int i;
Position(1,1);
PR_Bg_TL;
Position(79,1);
PR_Bg_TR;
Position(1,24);
PR_Bg_DL;
Position(79,24);
PR_Bg_DR;
for(i=3; i<=78; i+=2) {
Position(i,1);
PR_Bg_X;
Position(i,24);
PR_Bg_X;
}
}
void PrtBird() {
Position(Bird->x,Bird->y-1);
PR_Blank;
Position(Bird->x,Bird->y);
PR_FBird;
Position(38,2);
printf("Score:%d",Score);
}
int CheckYN(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
if(Bird->y>23)return 0;
if(Bird->x==p->x&&Bird->y<=p->y)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y)return 0;
if(Bird->x==p->x&&Bird->y>p->y+p->l_blank)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y+p->l_blank)return 0;
p=p->next;
}
return 1;
}
void Prtfirst() {
printf("══════════════════════════════════════n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■ C++语言版 Flappy Birdn");
printf(" ■■ ■■ 瞎搞人:侦探鼠n");
printf(" ■■ ■■ 瞎搞日期:2019.7.3n");
printf(" ■■ ■■ 耗时:2.46小时n");
printf(" ■■■ ■■ 游戏说明:n");
printf(" ■■ 1-按上箭头使鸟起飞n");
printf(" ■■ 2-等级越高,难度越大!n");
printf(" Ю ■■■n");
printf("n");
printf(" nnnnnnnn");
printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳n");
system("pause");
Position(1,1);
int i=0;
while(i++<40*25)PR_Blank;
}
int main() {
int i=0;
char ch;
Prtfirst();
PrtBg();
CreatBg();
InsertBg(Bg1);
InsertBg(Bg1);
InsertBg(Bg1);
CreatBird();
while(1) {
if(!CheckYN(Bg1))break;
Check_Bg(Bg1);
Prt_Bg(Bg1);
PrtBird();
Loop_Bg(Bg1);
Bird->y=Bird->y+1;
if(GetAsyncKeyState(VK_UP)) {
Position(Bird->x,Bird->y-1);
PR_Blank;
Bird->y=Bird->y-4;
}
while(i++<500);
{
Sleep(100);
}
i=0;
}
Position(38,10);
printf("Game Over!");
Position(1,25);
system("pause");
}
Fly bird
贪吃蛇
吃豆人
迷宫(随机)
打方块
狼人杀(人机)
俄罗斯方块(上下左右键控制)
//上下左右键控制
#include
#include
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);
printf("你想要 ");
if(x==1) printf("重置?");
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("加速!");
Sleep(70);
Place(9,12);
for(j=1; j<=9; j++) printf(" ");
Sleep(70);
}
Sleep(200);
}
}
if(best=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("下一个");
Place(8,37);
printf("得分");
Place(14,37);
printf("最高分");
Place(11,37);
printf("速度");
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("游戏结束!");
while(ok==1) click();
}
return 0;
}
Fly bird
#include
#include
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade=1,C_Gold=0,C_Ag=0,Score=0,Delay_time=1000,Max_blank=9,Distance=18;
struct Birds {
int x,y;
int condition;
};
Birds*Bird=(Birds*)malloc(sizeof(Birds));
struct Bg {
int x,y;
int l_blank;
int reward[9];
Bg*pri;
Bg*next;
};
Bg*Bg1=new Bg[sizeof(Bg)];
void Position(int x,int y) {
COORD pos= {x-1,y-1};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out,pos);
}
void CreatBird() {
Bird->x=41;
Bird->y=10;
Bird->condition=0;
}
void CreatBg() {
Bg*Bg2=(Bg*)malloc(sizeof(Bg));
Bg1->x=90;
Bg1->y=8;
Bg2->x=Bg1->x+Distance;
Bg2->y=9;
Bg1->l_blank=Max_blank-Grade;
Bg2->l_blank=Max_blank-Grade;
Bg1->next=Bg2;
Bg1->pri=Bg2;
Bg2->next=Bg1;
Bg2->pri=Bg1;
}
void InsertBg(Bg*p) {
int temp;
Bg*Bgs=(Bg*)malloc(sizeof(Bg));
Bgs->x=p->pri->x+Distance;
Bgs->l_blank=Max_blank-Grade;
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->pri->y+Max_blank-Grade)<21)Bgs->y=p->pri->y+temp%4;
else Bgs->y=p->pri->y;
} else {
if((p->pri->y-temp%4)>2)Bgs->y=p->pri->y-temp%4;
else Bgs->y=p->pri->y;
}
Bgs->pri=p->pri;
Bgs->next=p;
p->pri->next=Bgs;
p->pri=Bgs;
}
void Check_Bg(Bg*q) {
Bg*p=q;
int i=0,temp;
while(++i<=5) {
if(p->x>-4)p=p->next;
else {
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->y+Max_blank-Grade)<21)p->y=p->y+temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
} else {
if((p->y-temp%4)>2)p->y=p->y-temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
}
}
}
}
void Loop_Bg(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
p->x=p->x-1;
p=p->next;
if(Bird->x==p->x) {
Score+=1;
if(Score%4==0&&Grade<4)Grade++;
}
}
}
void Prt_Bg(Bg*q) {
Bg*p=q;
int i=0,k,j;
while(++i<=5) {
if(p->x>0&&p->x<=78) {
for(k=2; ky; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank
}
Position(p->x,p->y);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
Position(p->x,p->y+p->l_blank);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
k=k+p->l_blank+1;
for(k; k<=22; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank;
}
Position(p->x,23);
for(k=1; knext;
if(p->x==0) {
for(j=2; jy; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
Position(p->x+1,p->y);
PR_Blank;
PR_Blank;
PR_Blank;
Position(p->x+1,p->y+Max_blank-Grade);
PR_Blank;
PR_Blank;
PR_Blank;
j=j+Max_blank-Grade+1;
for(j; j<=22; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
}
}
}
void PrtBg() {
int i;
Position(1,1);
PR_Bg_TL;
Position(79,1);
PR_Bg_TR;
Position(1,24);
PR_Bg_DL;
Position(79,24);
PR_Bg_DR;
for(i=3; i<=78; i+=2) {
Position(i,1);
PR_Bg_X;
Position(i,24);
PR_Bg_X;
}
}
void PrtBird() {
Position(Bird->x,Bird->y-1);
PR_Blank;
Position(Bird->x,Bird->y);
PR_FBird;
Position(38,2);
printf("Score:%d",Score);
}
int CheckYN(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
if(Bird->y>23)return 0;
if(Bird->x==p->x&&Bird->y<=p->y)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y)return 0;
if(Bird->x==p->x&&Bird->y>p->y+p->l_blank)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y+p->l_blank)return 0;
p=p->next;
}
return 1;
}
void Prtfirst() {
printf("══════════════════════════════════════n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■ C++语言版 Flappy Birdn");
printf(" ■■ ■■ 瞎搞人:侦探鼠n");
printf(" ■■ ■■ 瞎搞日期:2019.7.3n");
printf(" ■■ ■■ 耗时:2.46小时n");
printf(" ■■■ ■■ 游戏说明:n");
printf(" ■■ 1-按上箭头使鸟起飞n");
printf(" ■■ 2-等级越高,难度越大!n");
printf(" Ю ■■■n");
printf("n");
printf(" nnnnnnnn");
printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳n");
system("pause");
Position(1,1);
int i=0;
while(i++<40*25)PR_Blank;
}
int main() {
int i=0;
char ch;
Prtfirst();
PrtBg();
CreatBg();
InsertBg(Bg1);
InsertBg(Bg1);
InsertBg(Bg1);
CreatBird();
while(1) {
if(!CheckYN(Bg1))break;
Check_Bg(Bg1);
Prt_Bg(Bg1);
PrtBird();
Loop_Bg(Bg1);
Bird->y=Bird->y+1;
if(GetAsyncKeyState(VK_UP)) {
Position(Bird->x,Bird->y-1);
PR_Blank;
Bird->y=Bird->y-4;
}
while(i++<500);
{
Sleep(100);
}
i=0;
}
Position(38,10);
printf("Game Over!");
Position(1,25);
system("pause");
}
吃豆人
迷宫(随机)
打方块
狼人杀(人机)
俄罗斯方块(上下左右键控制)
//上下左右键控制
#include
#include
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);
printf("你想要 ");
if(x==1) printf("重置?");
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("加速!");
Sleep(70);
Place(9,12);
for(j=1; j<=9; j++) printf(" ");
Sleep(70);
}
Sleep(200);
}
}
if(best=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("下一个");
Place(8,37);
printf("得分");
Place(14,37);
printf("最高分");
Place(11,37);
printf("速度");
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("游戏结束!");
while(ok==1) click();
}
return 0;
}
Fly bird
#include
#include
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade=1,C_Gold=0,C_Ag=0,Score=0,Delay_time=1000,Max_blank=9,Distance=18;
struct Birds {
int x,y;
int condition;
};
Birds*Bird=(Birds*)malloc(sizeof(Birds));
struct Bg {
int x,y;
int l_blank;
int reward[9];
Bg*pri;
Bg*next;
};
Bg*Bg1=new Bg[sizeof(Bg)];
void Position(int x,int y) {
COORD pos= {x-1,y-1};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out,pos);
}
void CreatBird() {
Bird->x=41;
Bird->y=10;
Bird->condition=0;
}
void CreatBg() {
Bg*Bg2=(Bg*)malloc(sizeof(Bg));
Bg1->x=90;
Bg1->y=8;
Bg2->x=Bg1->x+Distance;
Bg2->y=9;
Bg1->l_blank=Max_blank-Grade;
Bg2->l_blank=Max_blank-Grade;
Bg1->next=Bg2;
Bg1->pri=Bg2;
Bg2->next=Bg1;
Bg2->pri=Bg1;
}
void InsertBg(Bg*p) {
int temp;
Bg*Bgs=(Bg*)malloc(sizeof(Bg));
Bgs->x=p->pri->x+Distance;
Bgs->l_blank=Max_blank-Grade;
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->pri->y+Max_blank-Grade)<21)Bgs->y=p->pri->y+temp%4;
else Bgs->y=p->pri->y;
} else {
if((p->pri->y-temp%4)>2)Bgs->y=p->pri->y-temp%4;
else Bgs->y=p->pri->y;
}
Bgs->pri=p->pri;
Bgs->next=p;
p->pri->next=Bgs;
p->pri=Bgs;
}
void Check_Bg(Bg*q) {
Bg*p=q;
int i=0,temp;
while(++i<=5) {
if(p->x>-4)p=p->next;
else {
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->y+Max_blank-Grade)<21)p->y=p->y+temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
} else {
if((p->y-temp%4)>2)p->y=p->y-temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
}
}
}
}
void Loop_Bg(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
p->x=p->x-1;
p=p->next;
if(Bird->x==p->x) {
Score+=1;
if(Score%4==0&&Grade<4)Grade++;
}
}
}
void Prt_Bg(Bg*q) {
Bg*p=q;
int i=0,k,j;
while(++i<=5) {
if(p->x>0&&p->x<=78) {
for(k=2; ky; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank
}
Position(p->x,p->y);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
Position(p->x,p->y+p->l_blank);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
k=k+p->l_blank+1;
for(k; k<=22; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank;
}
Position(p->x,23);
for(k=1; knext;
if(p->x==0) {
for(j=2; jy; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
Position(p->x+1,p->y);
PR_Blank;
PR_Blank;
PR_Blank;
Position(p->x+1,p->y+Max_blank-Grade);
PR_Blank;
PR_Blank;
PR_Blank;
j=j+Max_blank-Grade+1;
for(j; j<=22; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
}
}
}
void PrtBg() {
int i;
Position(1,1);
PR_Bg_TL;
Position(79,1);
PR_Bg_TR;
Position(1,24);
PR_Bg_DL;
Position(79,24);
PR_Bg_DR;
for(i=3; i<=78; i+=2) {
Position(i,1);
PR_Bg_X;
Position(i,24);
PR_Bg_X;
}
}
void PrtBird() {
Position(Bird->x,Bird->y-1);
PR_Blank;
Position(Bird->x,Bird->y);
PR_FBird;
Position(38,2);
printf("Score:%d",Score);
}
int CheckYN(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
if(Bird->y>23)return 0;
if(Bird->x==p->x&&Bird->y<=p->y)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y)return 0;
if(Bird->x==p->x&&Bird->y>p->y+p->l_blank)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y+p->l_blank)return 0;
p=p->next;
}
return 1;
}
void Prtfirst() {
printf("══════════════════════════════════════n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■ C++语言版 Flappy Birdn");
printf(" ■■ ■■ 瞎搞人:侦探鼠n");
printf(" ■■ ■■ 瞎搞日期:2019.7.3n");
printf(" ■■ ■■ 耗时:2.46小时n");
printf(" ■■■ ■■ 游戏说明:n");
printf(" ■■ 1-按上箭头使鸟起飞n");
printf(" ■■ 2-等级越高,难度越大!n");
printf(" Ю ■■■n");
printf("n");
printf(" nnnnnnnn");
printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳n");
system("pause");
Position(1,1);
int i=0;
while(i++<40*25)PR_Blank;
}
int main() {
int i=0;
char ch;
Prtfirst();
PrtBg();
CreatBg();
InsertBg(Bg1);
InsertBg(Bg1);
InsertBg(Bg1);
CreatBird();
while(1) {
if(!CheckYN(Bg1))break;
Check_Bg(Bg1);
Prt_Bg(Bg1);
PrtBird();
Loop_Bg(Bg1);
Bird->y=Bird->y+1;
if(GetAsyncKeyState(VK_UP)) {
Position(Bird->x,Bird->y-1);
PR_Blank;
Bird->y=Bird->y-4;
}
while(i++<500);
{
Sleep(100);
}
i=0;
}
Position(38,10);
printf("Game Over!");
Position(1,25);
system("pause");
}
打方块
狼人杀(人机)
俄罗斯方块(上下左右键控制)
//上下左右键控制
#include
#include
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);
printf("你想要 ");
if(x==1) printf("重置?");
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("加速!");
Sleep(70);
Place(9,12);
for(j=1; j<=9; j++) printf(" ");
Sleep(70);
}
Sleep(200);
}
}
if(best=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("下一个");
Place(8,37);
printf("得分");
Place(14,37);
printf("最高分");
Place(11,37);
printf("速度");
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("游戏结束!");
while(ok==1) click();
}
return 0;
}
Fly bird
#include
#include
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade=1,C_Gold=0,C_Ag=0,Score=0,Delay_time=1000,Max_blank=9,Distance=18;
struct Birds {
int x,y;
int condition;
};
Birds*Bird=(Birds*)malloc(sizeof(Birds));
struct Bg {
int x,y;
int l_blank;
int reward[9];
Bg*pri;
Bg*next;
};
Bg*Bg1=new Bg[sizeof(Bg)];
void Position(int x,int y) {
COORD pos= {x-1,y-1};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out,pos);
}
void CreatBird() {
Bird->x=41;
Bird->y=10;
Bird->condition=0;
}
void CreatBg() {
Bg*Bg2=(Bg*)malloc(sizeof(Bg));
Bg1->x=90;
Bg1->y=8;
Bg2->x=Bg1->x+Distance;
Bg2->y=9;
Bg1->l_blank=Max_blank-Grade;
Bg2->l_blank=Max_blank-Grade;
Bg1->next=Bg2;
Bg1->pri=Bg2;
Bg2->next=Bg1;
Bg2->pri=Bg1;
}
void InsertBg(Bg*p) {
int temp;
Bg*Bgs=(Bg*)malloc(sizeof(Bg));
Bgs->x=p->pri->x+Distance;
Bgs->l_blank=Max_blank-Grade;
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->pri->y+Max_blank-Grade)<21)Bgs->y=p->pri->y+temp%4;
else Bgs->y=p->pri->y;
} else {
if((p->pri->y-temp%4)>2)Bgs->y=p->pri->y-temp%4;
else Bgs->y=p->pri->y;
}
Bgs->pri=p->pri;
Bgs->next=p;
p->pri->next=Bgs;
p->pri=Bgs;
}
void Check_Bg(Bg*q) {
Bg*p=q;
int i=0,temp;
while(++i<=5) {
if(p->x>-4)p=p->next;
else {
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->y+Max_blank-Grade)<21)p->y=p->y+temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
} else {
if((p->y-temp%4)>2)p->y=p->y-temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
}
}
}
}
void Loop_Bg(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
p->x=p->x-1;
p=p->next;
if(Bird->x==p->x) {
Score+=1;
if(Score%4==0&&Grade<4)Grade++;
}
}
}
void Prt_Bg(Bg*q) {
Bg*p=q;
int i=0,k,j;
while(++i<=5) {
if(p->x>0&&p->x<=78) {
for(k=2; ky; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank
}
Position(p->x,p->y);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
Position(p->x,p->y+p->l_blank);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
k=k+p->l_blank+1;
for(k; k<=22; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank;
}
Position(p->x,23);
for(k=1; knext;
if(p->x==0) {
for(j=2; jy; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
Position(p->x+1,p->y);
PR_Blank;
PR_Blank;
PR_Blank;
Position(p->x+1,p->y+Max_blank-Grade);
PR_Blank;
PR_Blank;
PR_Blank;
j=j+Max_blank-Grade+1;
for(j; j<=22; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
}
}
}
void PrtBg() {
int i;
Position(1,1);
PR_Bg_TL;
Position(79,1);
PR_Bg_TR;
Position(1,24);
PR_Bg_DL;
Position(79,24);
PR_Bg_DR;
for(i=3; i<=78; i+=2) {
Position(i,1);
PR_Bg_X;
Position(i,24);
PR_Bg_X;
}
}
void PrtBird() {
Position(Bird->x,Bird->y-1);
PR_Blank;
Position(Bird->x,Bird->y);
PR_FBird;
Position(38,2);
printf("Score:%d",Score);
}
int CheckYN(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
if(Bird->y>23)return 0;
if(Bird->x==p->x&&Bird->y<=p->y)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y)return 0;
if(Bird->x==p->x&&Bird->y>p->y+p->l_blank)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y+p->l_blank)return 0;
p=p->next;
}
return 1;
}
void Prtfirst() {
printf("══════════════════════════════════════n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■ C++语言版 Flappy Birdn");
printf(" ■■ ■■ 瞎搞人:侦探鼠n");
printf(" ■■ ■■ 瞎搞日期:2019.7.3n");
printf(" ■■ ■■ 耗时:2.46小时n");
printf(" ■■■ ■■ 游戏说明:n");
printf(" ■■ 1-按上箭头使鸟起飞n");
printf(" ■■ 2-等级越高,难度越大!n");
printf(" Ю ■■■n");
printf("n");
printf(" nnnnnnnn");
printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳n");
system("pause");
Position(1,1);
int i=0;
while(i++<40*25)PR_Blank;
}
int main() {
int i=0;
char ch;
Prtfirst();
PrtBg();
CreatBg();
InsertBg(Bg1);
InsertBg(Bg1);
InsertBg(Bg1);
CreatBird();
while(1) {
if(!CheckYN(Bg1))break;
Check_Bg(Bg1);
Prt_Bg(Bg1);
PrtBird();
Loop_Bg(Bg1);
Bird->y=Bird->y+1;
if(GetAsyncKeyState(VK_UP)) {
Position(Bird->x,Bird->y-1);
PR_Blank;
Bird->y=Bird->y-4;
}
while(i++<500);
{
Sleep(100);
}
i=0;
}
Position(38,10);
printf("Game Over!");
Position(1,25);
system("pause");
}
俄罗斯方块(上下左右键控制)
//上下左右键控制
#include
#include
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);
printf("你想要 ");
if(x==1) printf("重置?");
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("加速!");
Sleep(70);
Place(9,12);
for(j=1; j<=9; j++) printf(" ");
Sleep(70);
}
Sleep(200);
}
}
if(best=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("下一个");
Place(8,37);
printf("得分");
Place(14,37);
printf("最高分");
Place(11,37);
printf("速度");
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("游戏结束!");
while(ok==1) click();
}
return 0;
}
Fly bird
#include
#include
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade=1,C_Gold=0,C_Ag=0,Score=0,Delay_time=1000,Max_blank=9,Distance=18;
struct Birds {
int x,y;
int condition;
};
Birds*Bird=(Birds*)malloc(sizeof(Birds));
struct Bg {
int x,y;
int l_blank;
int reward[9];
Bg*pri;
Bg*next;
};
Bg*Bg1=new Bg[sizeof(Bg)];
void Position(int x,int y) {
COORD pos= {x-1,y-1};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out,pos);
}
void CreatBird() {
Bird->x=41;
Bird->y=10;
Bird->condition=0;
}
void CreatBg() {
Bg*Bg2=(Bg*)malloc(sizeof(Bg));
Bg1->x=90;
Bg1->y=8;
Bg2->x=Bg1->x+Distance;
Bg2->y=9;
Bg1->l_blank=Max_blank-Grade;
Bg2->l_blank=Max_blank-Grade;
Bg1->next=Bg2;
Bg1->pri=Bg2;
Bg2->next=Bg1;
Bg2->pri=Bg1;
}
void InsertBg(Bg*p) {
int temp;
Bg*Bgs=(Bg*)malloc(sizeof(Bg));
Bgs->x=p->pri->x+Distance;
Bgs->l_blank=Max_blank-Grade;
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->pri->y+Max_blank-Grade)<21)Bgs->y=p->pri->y+temp%4;
else Bgs->y=p->pri->y;
} else {
if((p->pri->y-temp%4)>2)Bgs->y=p->pri->y-temp%4;
else Bgs->y=p->pri->y;
}
Bgs->pri=p->pri;
Bgs->next=p;
p->pri->next=Bgs;
p->pri=Bgs;
}
void Check_Bg(Bg*q) {
Bg*p=q;
int i=0,temp;
while(++i<=5) {
if(p->x>-4)p=p->next;
else {
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->y+Max_blank-Grade)<21)p->y=p->y+temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
} else {
if((p->y-temp%4)>2)p->y=p->y-temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
}
}
}
}
void Loop_Bg(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
p->x=p->x-1;
p=p->next;
if(Bird->x==p->x) {
Score+=1;
if(Score%4==0&&Grade<4)Grade++;
}
}
}
void Prt_Bg(Bg*q) {
Bg*p=q;
int i=0,k,j;
while(++i<=5) {
if(p->x>0&&p->x<=78) {
for(k=2; ky; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank
}
Position(p->x,p->y);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
Position(p->x,p->y+p->l_blank);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
k=k+p->l_blank+1;
for(k; k<=22; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank;
}
Position(p->x,23);
for(k=1; knext;
if(p->x==0) {
for(j=2; jy; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
Position(p->x+1,p->y);
PR_Blank;
PR_Blank;
PR_Blank;
Position(p->x+1,p->y+Max_blank-Grade);
PR_Blank;
PR_Blank;
PR_Blank;
j=j+Max_blank-Grade+1;
for(j; j<=22; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
}
}
}
void PrtBg() {
int i;
Position(1,1);
PR_Bg_TL;
Position(79,1);
PR_Bg_TR;
Position(1,24);
PR_Bg_DL;
Position(79,24);
PR_Bg_DR;
for(i=3; i<=78; i+=2) {
Position(i,1);
PR_Bg_X;
Position(i,24);
PR_Bg_X;
}
}
void PrtBird() {
Position(Bird->x,Bird->y-1);
PR_Blank;
Position(Bird->x,Bird->y);
PR_FBird;
Position(38,2);
printf("Score:%d",Score);
}
int CheckYN(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
if(Bird->y>23)return 0;
if(Bird->x==p->x&&Bird->y<=p->y)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y)return 0;
if(Bird->x==p->x&&Bird->y>p->y+p->l_blank)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y+p->l_blank)return 0;
p=p->next;
}
return 1;
}
void Prtfirst() {
printf("══════════════════════════════════════n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■n");
printf(" ■■ ■■ C++语言版 Flappy Birdn");
printf(" ■■ ■■ 瞎搞人:侦探鼠n");
printf(" ■■ ■■ 瞎搞日期:2019.7.3n");
printf(" ■■ ■■ 耗时:2.46小时n");
printf(" ■■■ ■■ 游戏说明:n");
printf(" ■■ 1-按上箭头使鸟起飞n");
printf(" ■■ 2-等级越高,难度越大!n");
printf(" Ю ■■■n");
printf("n");
printf(" nnnnnnnn");
printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳n");
system("pause");
Position(1,1);
int i=0;
while(i++<40*25)PR_Blank;
}
int main() {
int i=0;
char ch;
Prtfirst();
PrtBg();
CreatBg();
InsertBg(Bg1);
InsertBg(Bg1);
InsertBg(Bg1);
CreatBird();
while(1) {
if(!CheckYN(Bg1))break;
Check_Bg(Bg1);
Prt_Bg(Bg1);
PrtBird();
Loop_Bg(Bg1);
Bird->y=Bird->y+1;
if(GetAsyncKeyState(VK_UP)) {
Position(Bird->x,Bird->y-1);
PR_Blank;
Bird->y=Bird->y-4;
}
while(i++<500);
{
Sleep(100);
}
i=0;
}
Position(38,10);
printf("Game Over!");
Position(1,25);
system("pause");
}
#include#include #define PR_Box printf("■") #define PR_Gold printf("★") #define PR_Ag printf("☆") #define PR_FBird printf("Ю") #define PR_DBird printf("Ф") #define PR_Land printf("┳┳┯") #define PR_Bg_TL printf("╔") #define PR_Bg_TR printf("╗") #define PR_Bg_DL printf("╚") #define PR_Bg_DR printf("╝") #define PR_Bg_X printf("═") #define PR_Bg_Y printf("║") #define PR_Blank printf(" "); int Grade=1,C_Gold=0,C_Ag=0,Score=0,Delay_time=1000,Max_blank=9,Distance=18; struct Birds { int x,y; int condition; }; Birds*Bird=(Birds*)malloc(sizeof(Birds)); struct Bg { int x,y; int l_blank; int reward[9]; Bg*pri; Bg*next; }; Bg*Bg1=new Bg[sizeof(Bg)]; void Position(int x,int y) { COORD pos= {x-1,y-1}; HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(Out,pos); } void CreatBird() { Bird->x=41; Bird->y=10; Bird->condition=0; } void CreatBg() { Bg*Bg2=(Bg*)malloc(sizeof(Bg)); Bg1->x=90; Bg1->y=8; Bg2->x=Bg1->x+Distance; Bg2->y=9; Bg1->l_blank=Max_blank-Grade; Bg2->l_blank=Max_blank-Grade; Bg1->next=Bg2; Bg1->pri=Bg2; Bg2->next=Bg1; Bg2->pri=Bg1; } void InsertBg(Bg*p) { int temp; Bg*Bgs=(Bg*)malloc(sizeof(Bg)); Bgs->x=p->pri->x+Distance; Bgs->l_blank=Max_blank-Grade; srand((int)time(0)); temp=rand(); if(temp%2==0) { if((temp%4+p->pri->y+Max_blank-Grade)<21)Bgs->y=p->pri->y+temp%4; else Bgs->y=p->pri->y; } else { if((p->pri->y-temp%4)>2)Bgs->y=p->pri->y-temp%4; else Bgs->y=p->pri->y; } Bgs->pri=p->pri; Bgs->next=p; p->pri->next=Bgs; p->pri=Bgs; } void Check_Bg(Bg*q) { Bg*p=q; int i=0,temp; while(++i<=5) { if(p->x>-4)p=p->next; else { srand((int)time(0)); temp=rand(); if(temp%2==0) { if((temp%4+p->y+Max_blank-Grade)<21)p->y=p->y+temp%4; else p->y=p->y; p->x=p->pri->x+Distance; p->l_blank=Max_blank-Grade; } else { if((p->y-temp%4)>2)p->y=p->y-temp%4; else p->y=p->y; p->x=p->pri->x+Distance; p->l_blank=Max_blank-Grade; } } } } void Loop_Bg(Bg*q) { Bg*p=q; int i=0; while(++i<=5) { p->x=p->x-1; p=p->next; if(Bird->x==p->x) { Score+=1; if(Score%4==0&&Grade<4)Grade++; } } } void Prt_Bg(Bg*q) { Bg*p=q; int i=0,k,j; while(++i<=5) { if(p->x>0&&p->x<=78) { for(k=2; k y; k++) { Position(p->x+1,k); PR_Box; PR_Box; PR_Blank } Position(p->x,p->y); PR_Box; PR_Box; PR_Box; PR_Blank; Position(p->x,p->y+p->l_blank); PR_Box; PR_Box; PR_Box; PR_Blank; k=k+p->l_blank+1; for(k; k<=22; k++) { Position(p->x+1,k); PR_Box; PR_Box; PR_Blank; } Position(p->x,23); for(k=1; k next; if(p->x==0) { for(j=2; j y; j++) { Position(p->x+1,j); PR_Blank; PR_Blank; } Position(p->x+1,p->y); PR_Blank; PR_Blank; PR_Blank; Position(p->x+1,p->y+Max_blank-Grade); PR_Blank; PR_Blank; PR_Blank; j=j+Max_blank-Grade+1; for(j; j<=22; j++) { Position(p->x+1,j); PR_Blank; PR_Blank; } } } } void PrtBg() { int i; Position(1,1); PR_Bg_TL; Position(79,1); PR_Bg_TR; Position(1,24); PR_Bg_DL; Position(79,24); PR_Bg_DR; for(i=3; i<=78; i+=2) { Position(i,1); PR_Bg_X; Position(i,24); PR_Bg_X; } } void PrtBird() { Position(Bird->x,Bird->y-1); PR_Blank; Position(Bird->x,Bird->y); PR_FBird; Position(38,2); printf("Score:%d",Score); } int CheckYN(Bg*q) { Bg*p=q; int i=0; while(++i<=5) { if(Bird->y>23)return 0; if(Bird->x==p->x&&Bird->y<=p->y)return 0; if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y)return 0; if(Bird->x==p->x&&Bird->y>p->y+p->l_blank)return 0; if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y+p->l_blank)return 0; p=p->next; } return 1; } void Prtfirst() { printf("══════════════════════════════════════n"); printf(" ■■ ■■n"); printf(" ■■ ■■n"); printf(" ■■ ■■n"); printf(" ■■ ■■n"); printf(" ■■ ■■ C++语言版 Flappy Birdn"); printf(" ■■ ■■ 瞎搞人:侦探鼠n"); printf(" ■■ ■■ 瞎搞日期:2019.7.3n"); printf(" ■■ ■■ 耗时:2.46小时n"); printf(" ■■■ ■■ 游戏说明:n"); printf(" ■■ 1-按上箭头使鸟起飞n"); printf(" ■■ 2-等级越高,难度越大!n"); printf(" Ю ■■■n"); printf("n"); printf(" nnnnnnnn"); printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳n"); system("pause"); Position(1,1); int i=0; while(i++<40*25)PR_Blank; } int main() { int i=0; char ch; Prtfirst(); PrtBg(); CreatBg(); InsertBg(Bg1); InsertBg(Bg1); InsertBg(Bg1); CreatBird(); while(1) { if(!CheckYN(Bg1))break; Check_Bg(Bg1); Prt_Bg(Bg1); PrtBird(); Loop_Bg(Bg1); Bird->y=Bird->y+1; if(GetAsyncKeyState(VK_UP)) { Position(Bird->x,Bird->y-1); PR_Blank; Bird->y=Bird->y-4; } while(i++<500); { Sleep(100); } i=0; } Position(38,10); printf("Game Over!"); Position(1,25); system("pause"); }
贪吃蛇
#include#include #include #include #include //停顿:Sleep(); #include //清屏:system("cls"); #include //1:'◎' 2:'⊙' 3:'▲' 4:'◆' 5:'■' using namespace std; int a[100][100], dir[100][100]; //string guo[5]={'▲','◆','■','▼','★'}; int fx[4][2] = { {0,-1},{1,0},{0,1},{-1,0} }; //ap来记录奖励块的分 int n, m, ff, f = 1, t = 50, T = 50, ap = 10, egg[2], danshu, headx, heady, endx, endy, point = 0, apple = 0, fangx, stopp = 0, panduan = 0; //ff用来判断 panduan 0:中途退出;1:咬到自己;2:重置 int lastfx; int zuobi = 0; int fff[110][110]; string print[4][4] = { {"═","╔"," ","╚"},{"╝","║","╚"," "},{" ","╗","═","╝"},{"╗"," ","╔","║"} }; void color(int a)//颜色函数 { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a); } void gotoxy(int x, int y)//位置函数(行为x 列为y) { COORD pos; pos.X = 2 * y; pos.Y = x; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } void reset() { system("cls"); color(7); printf(" ★"); color(10); printf("贪吃蛇"); color(11); printf("★nn"); color(7); printf("⊙打印若有错位请调整窗口大小或按r重输小点的数⊙nn 请输入场地大小(格式:行数 列数) 推荐(20 20) nn>>"); scanf("%d%d", &n, &m); system("cls"); color(14); for (int i = 1; i <= m; i++) { gotoxy(0, i); printf("※"); gotoxy(n + 1, i); printf("※"); } for (int i = 1; i <= n; i++) { gotoxy(i, 0); printf("※"); gotoxy(i, m + 1); printf("※"); } color(10); memset(fff, 0, sizeof(fff)); gotoxy(0, 0); printf("┍"); gotoxy(n + 1, 0); printf("┕"); gotoxy(0, m + 1); printf("┑"); gotoxy(n + 1, m + 1); printf("┙"); color(7); gotoxy(0, m + 5); printf("方向:a/s/d/w | 1/2/3/5"); gotoxy(1, m + 5); printf("暂停:p | 0"); gotoxy(2, m + 5); printf("减速:q/j | 4/7"); gotoxy(3, m + 5); printf("加速:e/k | 6/9"); gotoxy(4, m + 5); printf("重置:r | ."); gotoxy(5, m + 5); printf("地图:h | +"); headx = endx = endy = 1; heady = 3; f = 1; ff = 3; memset(a, 1, sizeof(a)); memset(dir, 0, sizeof(dir)); a[1][1] = a[1][2] = a[1][3] = 0; gotoxy(1, 1); printf("⊙"); gotoxy(1, 2); printf("⊙"); gotoxy(1, 3); printf("◎"); dir[1][1] = dir[1][2] = dir[1][3] = 2; apple = 0; fangx = 2; point = 0; danshu = 0; lastfx = 2; stopp = 0; if (zuobi) { color(12); gotoxy(12, m + 5); printf("作弊可耻!"); gotoxy(m + 4, 0); printf("做了弊还没路走那就救不了你了,乖乖重来吧......"); color(7); } } void haha() { char ch = getch(); if ((ch == 'a' || ch == '1') && dir[headx][heady] != 2) { fangx = 0; return; } if ((ch == 's' || ch == '2') && dir[headx][heady] != 3) { fangx = 1; return; } if ((ch == 'd' || ch == '3') && dir[headx][heady] != 0) { fangx = 2; return; } if ((ch == 'w' || ch == '5') && dir[headx][heady] != 1) { fangx = 3; return; } if (ch == 'p' || ch == '0') { stopp = (stopp + 1) % 2; return; } if (ch == 'q' || ch == '4') { T += 10; if (T >= 1005) T = 1005; return; } if (ch == 'e' || ch == '6') { T -= 10; if (T <= 1) T = 2; return; } if (ch == 'j' || ch == '7') { T += 1; if (T >= 1005) T = 1005; return; } if (ch == 'k' || ch == '9') { T -= 1; if (T <= 1) T = 2; return; } if (ch == 'r' || ch == '.') { ff = 2; f = 0; panduan = 0; return; } if (ch == 'h' || ch == '8') { zuobi += 1; zuobi %= 2; if (zuobi) { color(12); gotoxy(12, m + 5); printf("作弊可耻!"); gotoxy(m + 4, 0); printf("做了弊还没路走那就救不了你了,乖乖重来吧......"); color(7); } else { printf(" "); gotoxy(m + 4, 0); printf(" "); } } if (ch == 'g' || ch == '+') { gotoxy(n + 50, 0); printf("现在切换到地图编辑模式nnq/4 为开始放置模式(光标移动过的痕迹会留下障碍物)nne/6 为取消放置障碍物模式nnj/0 为橡皮模式(再按一次退出橡皮模式)nn按 h/+ 继续游戏nn"); printf("n按任意键开始编辑地图"); color(13); int x = 1, y = 1, dfx, moshi = 0; ch = getch(); gotoxy(0, 0); gotoxy(1, 1); while (ch != 'h' && ch != '+') { if (ch == 'a' || ch == '1') dfx = 0; else if (ch == 's' || ch == '2') dfx = 1; else if (ch == 'd' || ch == '3') dfx = 2; else if (ch == 'w' || ch == '5') dfx = 3; else dfx = 5; if (ch == 'q' || ch == '4') moshi = 1; if (ch == 'e' || ch == '6') moshi = 0; if (ch == 'j' || ch == '0') if (moshi - 2) moshi = 2; else moshi = 0; if (dfx <= 4) { if (x + fx[dfx][0] > 0 && x + fx[dfx][0] <= n && y + fx[dfx][1] > 0 && y + fx[dfx][1] <= m) { x += fx[dfx][0]; y += fx[dfx][1]; } if (x > 0 && x <= n && y > 0 && y <= m) { gotoxy(x, y); if (moshi == 1 && a[x][y] && !fff[x][y]) { a[x][y] = 0; fff[x][y] = 1; printf("□"); } if (moshi == 2 && fff[x][y]) { a[x][y] = 1; fff[x][y] = 0; printf(" "); } gotoxy(x, y); } } ch = getch(); } color(7); } } void findegg() { srand(time(NULL)); int aa = 1; while (!a[egg[0]][egg[1]]) { egg[0] = (rand() % (n)) + 1; egg[1] = (rand() % m) + 1; } a[egg[0]][egg[1]] = 0; point += ap; gotoxy(egg[0], egg[1]); if (!apple) { printf("★"); ap = 8000 / T; if (ap >= 200) ap = 200; } else { printf("●"); ap = 10; } apple++; apple = apple % 10; gotoxy(n + 2, 0); printf("距离下一个奖励蛋还有 "); color(11); cout << 9 - (8 + apple) % 10; color(7); printf(" 个"); danshu++; return; } int gg() { if (ff == 0) return(0); if (ff == 1) { gotoxy(n + 2, 1); Sleep(3000); gotoxy(n + 26, 1); gotoxy(n + 10, 0); printf("哦豁~ 你咬到自己了o( ̄▽ ̄)dnnn你共吃蛋 %d 个nnn你共得分 %d 分,恭喜!nnn等一下就继续", danshu, point); Sleep(5000); if (kbhit) return(1); } if (ff == 2) return(1); return 0; } void dong() { gotoxy(11, m + 3); printf("当前的蛋有 %d 分 ", ap); if (ap - 3 > 10) ap -= 3; if (ap != 10) { gotoxy(egg[0], egg[1]); color(ap % 10); printf("★"); color(7); } int x, y; x = (headx + fx[fangx][0] - 1 + n) % (n)+1; y = (heady + fx[fangx][1] - 1 + m) % (m)+1; dir[headx][heady] = fangx; if (x == egg[0] && y == egg[1]) { gotoxy(headx, heady); cout << print[lastfx][fangx]; dir[headx][heady] = fangx; headx = x; heady = y; a[x][y] = 0; gotoxy(headx, heady); printf("◎"); findegg(); } else if (a[x][y]) { gotoxy(headx, heady); cout << print[lastfx][fangx]; headx = x; heady = y; a[x][y] = 0; gotoxy(headx, heady); printf("◎"); gotoxy(endx, endy); printf(" "); a[endx][endy] = 1; x = endx; y = endy; endx += fx[dir[x][y]][0]; endx = (endx - 1 + n) % (n)+1; endy += fx[dir[x][y]][1]; endy = (endy - 1 + m) % (m)+1; dir[x][y] = -1; } else if (!zuobi) { f = 0; ff = 1; } dir[headx][heady] = fangx; lastfx = fangx; return; } int main() { while (1) { srand(time(NULL)); reset(); egg[0] = (rand() % n - 1) + 2; egg[1] = (rand() % m) + 1; a[egg[0]][egg[1]] = 0; gotoxy(egg[0], egg[1]); if (apple) { printf("★"); ap = 100; } else printf("●"); while (f) { if (kbhit()) haha(); gotoxy(9, m + 5); printf("吃蛋:%d 个", danshu); gotoxy(8, m + 5); printf("速度: %d ", 1005 - T); //while (stopp) {Sleep(10); if (kbhit()) haha();} Sleep(1); t = (t - 1 + T) % T; if (t == 0 && !stopp) dong(); gotoxy(7, m + 5); printf("得分:%d 分", point); gotoxy(12, m + 5); } if (!gg()) return 0; } return 0; }
吃豆人
#include#include #include #include #include //停顿:Sleep(); #include //清屏:system("cls"); #include //1:'◎' 2:'⊙' 3:'▲' 4:'◆' 5:'■' using namespace std; int a[100][100], dir[100][100]; //string guo[5]={'▲','◆','■','▼','★'}; int fx[4][2] = { {0,-1},{1,0},{0,1},{-1,0} }; //ap来记录奖励块的分 int n, m, ff, f = 1, t = 50, T = 50, ap = 10, egg[2], danshu, headx, heady, endx, endy, point = 0, apple = 0, fangx, stopp = 0, panduan = 0; //ff用来判断 panduan 0:中途退出;1:咬到自己;2:重置 int lastfx; int zuobi = 0; int fff[110][110]; string print[4][4] = { {"═","╔"," ","╚"},{"╝","║","╚"," "},{" ","╗","═","╝"},{"╗"," ","╔","║"} }; void color(int a)//颜色函数 { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a); } void gotoxy(int x, int y)//位置函数(行为x 列为y) { COORD pos; pos.X = 2 * y; pos.Y = x; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } void reset() { system("cls"); color(7); printf(" ★"); color(10); printf("贪吃蛇"); color(11); printf("★nn"); color(7); printf("⊙打印若有错位请调整窗口大小或按r重输小点的数⊙nn 请输入场地大小(格式:行数 列数) 推荐(20 20) nn>>"); scanf("%d%d", &n, &m); system("cls"); color(14); for (int i = 1; i <= m; i++) { gotoxy(0, i); printf("※"); gotoxy(n + 1, i); printf("※"); } for (int i = 1; i <= n; i++) { gotoxy(i, 0); printf("※"); gotoxy(i, m + 1); printf("※"); } color(10); memset(fff, 0, sizeof(fff)); gotoxy(0, 0); printf("┍"); gotoxy(n + 1, 0); printf("┕"); gotoxy(0, m + 1); printf("┑"); gotoxy(n + 1, m + 1); printf("┙"); color(7); gotoxy(0, m + 5); printf("方向:a/s/d/w | 1/2/3/5"); gotoxy(1, m + 5); printf("暂停:p | 0"); gotoxy(2, m + 5); printf("减速:q/j | 4/7"); gotoxy(3, m + 5); printf("加速:e/k | 6/9"); gotoxy(4, m + 5); printf("重置:r | ."); gotoxy(5, m + 5); printf("地图:h | +"); headx = endx = endy = 1; heady = 3; f = 1; ff = 3; memset(a, 1, sizeof(a)); memset(dir, 0, sizeof(dir)); a[1][1] = a[1][2] = a[1][3] = 0; gotoxy(1, 1); printf("⊙"); gotoxy(1, 2); printf("⊙"); gotoxy(1, 3); printf("◎"); dir[1][1] = dir[1][2] = dir[1][3] = 2; apple = 0; fangx = 2; point = 0; danshu = 0; lastfx = 2; stopp = 0; if (zuobi) { color(12); gotoxy(12, m + 5); printf("作弊可耻!"); gotoxy(m + 4, 0); printf("做了弊还没路走那就救不了你了,乖乖重来吧......"); color(7); } } void haha() { char ch = getch(); if ((ch == 'a' || ch == '1') && dir[headx][heady] != 2) { fangx = 0; return; } if ((ch == 's' || ch == '2') && dir[headx][heady] != 3) { fangx = 1; return; } if ((ch == 'd' || ch == '3') && dir[headx][heady] != 0) { fangx = 2; return; } if ((ch == 'w' || ch == '5') && dir[headx][heady] != 1) { fangx = 3; return; } if (ch == 'p' || ch == '0') { stopp = (stopp + 1) % 2; return; } if (ch == 'q' || ch == '4') { T += 10; if (T >= 1005) T = 1005; return; } if (ch == 'e' || ch == '6') { T -= 10; if (T <= 1) T = 2; return; } if (ch == 'j' || ch == '7') { T += 1; if (T >= 1005) T = 1005; return; } if (ch == 'k' || ch == '9') { T -= 1; if (T <= 1) T = 2; return; } if (ch == 'r' || ch == '.') { ff = 2; f = 0; panduan = 0; return; } if (ch == 'h' || ch == '8') { zuobi += 1; zuobi %= 2; if (zuobi) { color(12); gotoxy(12, m + 5); printf("作弊可耻!"); gotoxy(m + 4, 0); printf("做了弊还没路走那就救不了你了,乖乖重来吧......"); color(7); } else { printf(" "); gotoxy(m + 4, 0); printf(" "); } } if (ch == 'g' || ch == '+') { gotoxy(n + 50, 0); printf("现在切换到地图编辑模式nnq/4 为开始放置模式(光标移动过的痕迹会留下障碍物)nne/6 为取消放置障碍物模式nnj/0 为橡皮模式(再按一次退出橡皮模式)nn按 h/+ 继续游戏nn"); printf("n按任意键开始编辑地图"); color(13); int x = 1, y = 1, dfx, moshi = 0; ch = getch(); gotoxy(0, 0); gotoxy(1, 1); while (ch != 'h' && ch != '+') { if (ch == 'a' || ch == '1') dfx = 0; else if (ch == 's' || ch == '2') dfx = 1; else if (ch == 'd' || ch == '3') dfx = 2; else if (ch == 'w' || ch == '5') dfx = 3; else dfx = 5; if (ch == 'q' || ch == '4') moshi = 1; if (ch == 'e' || ch == '6') moshi = 0; if (ch == 'j' || ch == '0') if (moshi - 2) moshi = 2; else moshi = 0; if (dfx <= 4) { if (x + fx[dfx][0] > 0 && x + fx[dfx][0] <= n && y + fx[dfx][1] > 0 && y + fx[dfx][1] <= m) { x += fx[dfx][0]; y += fx[dfx][1]; } if (x > 0 && x <= n && y > 0 && y <= m) { gotoxy(x, y); if (moshi == 1 && a[x][y] && !fff[x][y]) { a[x][y] = 0; fff[x][y] = 1; printf("□"); } if (moshi == 2 && fff[x][y]) { a[x][y] = 1; fff[x][y] = 0; printf(" "); } gotoxy(x, y); } } ch = getch(); } color(7); } } void findegg() { srand(time(NULL)); int aa = 1; while (!a[egg[0]][egg[1]]) { egg[0] = (rand() % (n)) + 1; egg[1] = (rand() % m) + 1; } a[egg[0]][egg[1]] = 0; point += ap; gotoxy(egg[0], egg[1]); if (!apple) { printf("★"); ap = 8000 / T; if (ap >= 200) ap = 200; } else { printf("●"); ap = 10; } apple++; apple = apple % 10; gotoxy(n + 2, 0); printf("距离下一个奖励蛋还有 "); color(11); cout << 9 - (8 + apple) % 10; color(7); printf(" 个"); danshu++; return; } int gg() { if (ff == 0) return(0); if (ff == 1) { gotoxy(n + 2, 1); Sleep(3000); gotoxy(n + 26, 1); gotoxy(n + 10, 0); printf("哦豁~ 你咬到自己了o( ̄▽ ̄)dnnn你共吃蛋 %d 个nnn你共得分 %d 分,恭喜!nnn等一下就继续", danshu, point); Sleep(5000); if (kbhit) return(1); } if (ff == 2) return(1); return 0; } void dong() { gotoxy(11, m + 3); printf("当前的蛋有 %d 分 ", ap); if (ap - 3 > 10) ap -= 3; if (ap != 10) { gotoxy(egg[0], egg[1]); color(ap % 10); printf("★"); color(7); } int x, y; x = (headx + fx[fangx][0] - 1 + n) % (n)+1; y = (heady + fx[fangx][1] - 1 + m) % (m)+1; dir[headx][heady] = fangx; if (x == egg[0] && y == egg[1]) { gotoxy(headx, heady); cout << print[lastfx][fangx]; dir[headx][heady] = fangx; headx = x; heady = y; a[x][y] = 0; gotoxy(headx, heady); printf("◎"); findegg(); } else if (a[x][y]) { gotoxy(headx, heady); cout << print[lastfx][fangx]; headx = x; heady = y; a[x][y] = 0; gotoxy(headx, heady); printf("◎"); gotoxy(endx, endy); printf(" "); a[endx][endy] = 1; x = endx; y = endy; endx += fx[dir[x][y]][0]; endx = (endx - 1 + n) % (n)+1; endy += fx[dir[x][y]][1]; endy = (endy - 1 + m) % (m)+1; dir[x][y] = -1; } else if (!zuobi) { f = 0; ff = 1; } dir[headx][heady] = fangx; lastfx = fangx; return; } int main() { while (1) { srand(time(NULL)); reset(); egg[0] = (rand() % n - 1) + 2; egg[1] = (rand() % m) + 1; a[egg[0]][egg[1]] = 0; gotoxy(egg[0], egg[1]); if (apple) { printf("★"); ap = 100; } else printf("●"); while (f) { if (kbhit()) haha(); gotoxy(9, m + 5); printf("吃蛋:%d 个", danshu); gotoxy(8, m + 5); printf("速度: %d ", 1005 - T); //while (stopp) {Sleep(10); if (kbhit()) haha();} Sleep(1); t = (t - 1 + T) % T; if (t == 0 && !stopp) dong(); gotoxy(7, m + 5); printf("得分:%d 分", point); gotoxy(12, m + 5); } if (!gg()) return 0; } return 0; }
迷宫(随机)
#include#include #include #include #define Height 25 //迷宫的高度,必须为奇数 #define Width 25 //迷宫的宽度,必须为奇数 #define Wall 1 #define Road 0 #define Start 2 #define End 3 #define Esc 5 #define Up 1 #define Down 2 #define Left 3 #define Right 4 int map[Height+2][Width+2]; void gotoxy(int x,int y) { //移动坐标 COORD coord; coord.X=x; coord.Y=y; SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord ); } void hidden() { //隐藏光标 HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cci; GetConsoleCursorInfo(hOut,&cci); cci.bVisible=0;//赋1为显示,赋0为隐藏 SetConsoleCursorInfo(hOut,&cci); } void create(int x,int y) { //随机生成迷 int c[4][2]= {0,1,1,0,0,-1,-1,0}; //四个方向 int i,j,t; //将方向打乱 for(i=0; i<4; i++) { j=rand()%4; t=c[i][0]; c[i][0]=c[j][0]; c[j][0]=t; t=c[i][1]; c[i][1]=c[j][1]; c[j][1]=t; } map[x][y]=Road; for(i=0; i<4; i++) if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall) { map[x+c[i][0]][y+c[i][1]]=Road; create(x+2*c[i][0],y+2*c[i][1]); } } int get_key() { //接收按键 char c; while(c=getch()) { if(c==27) return Esc; //Esc if(c!=-32)continue; c=getch(); if(c==72) return Up; //上 if(c==80) return Down; //下 if(c==75) return Left; //左 if(c==77) return Right; //右 } return 0; } void paint(int x,int y) { //画迷宫 gotoxy(2*y-2,x-1); switch(map[x][y]) { case Start: printf("入"); break; //画入口 case End: printf("出"); break; //画出口 case Wall: printf("▇"); break; //画墙 case Road: printf(" "); break; //画路 } } void game() { int x=2,y=1; //玩家当前位置,刚开始在入口处 int c; //用来接收按键 while(1) { gotoxy(2*y-2,x-1); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED); printf("▇▇"); //画出玩家当前位置 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN); if(map[x][y]==End) { //判断是否到达出口 gotoxy(30,24); printf("到达终点,按任意键结束"); getch(); break; } c=get_key(); if(c==Esc) { gotoxy(0,24); break; } switch(c) { case Up: //向上走 if(map[x-1][y]!=Wall) { paint(x,y); x--; } break; case Down: //向下走 if(map[x+1][y]!=Wall) { paint(x,y); x++; } break; case Left: //向左走 if(map[x][y-1]!=Wall) { paint(x,y); y--; } break; case Right: //向右走 if(map[x][y+1]!=Wall) { paint(x,y); y++; } break; } } } int main() { int i,j; srand((unsigned)time(NULL)); //初始化随即种子 hidden(); //隐藏光标 for(i=0; i<=Height+1; i++) for(j=0; j<=Width+1; j++) if(i==0||i==Height+1||j==0||j==Width+1) //初始化迷宫 map[i][j]=Road; else map[i][j]=Wall; create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1)); //从随机一个点开始生成迷宫,该点行列都为偶数 for(i=0; i<=Height+1; i++) { //边界处理 map[i][0]=Wall; map[i][Width+1]=Wall; } for(j=0; j<=Width+1; j++) { //边界处理 map[0][j]=Wall; map[Height+1][j]=Wall; } map[2][1]=Start; //给定入口 map[Height-1][Width]=End; //给定出口 for(i=1; i<=Height; i++) for(j=1; j<=Width; j++) //画出迷宫 paint(i,j); game(); //开始游戏 getch(); return 0; }
打方块
#include//打方块 Windows10
#include
using namespace std;
int fen,mb[10][18],leaf;
void kg(int a) {
for(int i=0; i2&&x<11) {
go(x-1,y+1);
cout<<"■■■";
} else if(x==2) {
go(x,y+1);
cout<<"■■";
} else if(x==11) {
go(x-1,y+1);
cout<<"■■";
} else;
if(a)
for(int i=0; i<18; i++) {
go(2,i+2);
kg(20);
}
Sleep(100);
go(x,y);
kg(2);
if(x>2&&x<11) {
go(x-1,y+1);
kg(6);
} else if(x==2) {
go(x,y+1);
kg(4);
} else if(x==11) {
go(x-1,y+1);
kg(4);
} else;
go(14,5);
kg(4);
cout<<"bbbb"<0; o--)
for(int j=0; j<10; j++)
mb[j][o]=mb[j][o-1];
for(int o=0; o<10; o++)
mb[o][0]=rand()%2;
asd:
;
if(GetAsyncKeyState(VK_RIGHT)!=0&&x<11)x++;
if(GetAsyncKeyState(VK_LEFT)!=0&&x>2)x--;
if(GetAsyncKeyState(VK_UP)!=0)sj(x);
printtu(x,20,i>=wt*10);
if(i1) {
q--;
go(16,11);
cout<<' '<';
go(22,9+2*y);
cout<<'<';
Sleep(100);
}
}
狼人杀(人机)
'; go(22,9+2*y); cout<<'<'; Sleep(100); } }
#includeusing namespace std; int life[7]={1,1,1,1,1,1}; int potions[5]={-1,1}; int vote[7]={0}; string name[7]={"预言家","女巫","平民","平民","狼人","狼人"}; int seer(int x,int y,int n,int p1,int p2,int l1,int l2) { int rescued; int die; int die_potions; bool gameover=false; while(gameover==false) { cout< =0 or life[l2]>=0)) { cout<<"狼人:"< =0) { cout<<"预言家:"< >res; if(name[res]=="平民"||name[res]=="女巫"||name[res]=="预言家") cout<<"好人"< =0) { cout<<"女巫:"< >ps; a[ps]++; } else if(life[j]==1) { srand((unsigned)time(NULL)); int cs; cs=rand()%6; while(life[cs]!=1||cs==j) cs=rand()%6; a[cs]++; } } cout<<"投票结果:"< =0) { cout<<"狼人:"< >die; life[die]--; cout<<"狼人杀了"< =0) { cout<<"狼人:"< =0) { cout<<"预言家:"< =0) { cout<<"女巫:"< >ps; a[ps]++; } else if(life[j]==1) { srand((unsigned)time(NULL)); int cs; cs=rand()%6; while(life[cs]!=1||cs==j) cs=rand()%6; a[cs]++; } } cout<<"投票结果:"< =0 or life[l2]>=0)) { cout<<"狼人:"< =0) { cout<<"预言家:"< =0) { cout<<"女巫:"< >dor; if(dor=='d') { cout<<"请输入0~5号你要杀的人(除了"< >die_potions; life[die_potions]--; potions[0]++; cout<<"女巫杀了"< >ps; a[ps]++; } else if(life[j]==1) { srand((unsigned)time(NULL)); int cs; cs=rand()%6; while(life[cs]!=1||cs==j) cs=rand()%6; a[cs]++; } } cout<<"投票结果:"< =0 or life[l2]>=0)) { cout<<"狼人:"< =0) { cout<<"预言家:"< =0) { cout<<"女巫:"< >ps; a[ps]++; } else if(life[j]==1) { srand((unsigned)time(NULL)); int cs; cs=rand()%6; while(life[cs]!=1||cs==j) cs=rand()%6; a[cs]++; } } cout<<"投票结果:"<



