C++三体星战小游戏
物理小游戏,懒得 写注释。
游戏代码
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int toint(double a){return ((int)(a*10+5))/10;}
int rand(int a){return rand()%a;}
void SlowDisplay(int x,char *p){while(1){if(*p!=0) printf("%c",*p++);else break;Sleep(x);}}
void Setpos(double x,double y){COORD pos;pos.X=toint(y*2),pos.Y=toint(x);SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
void Color(int a){if(a==-1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);if(a==-2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);if(a==-3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED);if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED);if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN);if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED|BACKGROUND_BLUE);if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_BLUE);
}
struct node{int what;double x,y,vx,vy,r,m;bool life;int gun,master=-1;}Sun[1000001];
int b,T,m[41][41],n[41][41],m2[41][41],n2[41][41],dif[11],Speed=10,Ba,Hotguntime,Hotguntimemax=10,Blood,Score;
double Speedmax,Speedless,Speedmore=1,Balljump=-0.7,Fire=0.08;
void Push(int a,int b){if(Sun[a].master==b||Sun[b].master==a) return;if(Sun[a].life==0||Sun[b].life==0) return;if(Sun[a].what==3||Sun[b].what==3) return;if(Sun[a].what==4||Sun[b].what==4) return;double Ax=Sun[a].x-Sun[b].x,Ay=Sun[a].y-Sun[b].y,Dis=sqrt(Ax*Ax+Ay*Ay)*1.0,fDis=sqrt((Sun[a].vx-Sun[b].vx)*(Sun[a].vx-Sun[b].vx)+(Sun[a].vy-Sun[b].vy)*(Sun[a].vy-Sun[b].vy));if(Dis==0) return;if(abs(Ay)<=0.0001) Ay=0.0001;if(Sun[a].what==2||Sun[b].what==2) int c;else if(Dis<=Sun[a].r+Sun[b].r+fDis){double Vx=(Sun[a].vx+Sun[b].vx)/2.0,Vy=(Sun[a].vy+Sun[b].vy)/2.0,aX=(Sun[a].x+Sun[b].x+Sun[a].vx+Sun[b].vx)/2.0,aY=(Sun[a].y+Sun[b].y+Sun[a].vy+Sun[b].vy)/2.0;Sun[a].vx=Sun[b].vx=Vx,Sun[a].vy=Sun[b].vy=Vy;Sun[a].x=aX-(Ax/Dis)/2.0,Sun[b].x=aX+(Ax/Dis)/2.0;Sun[a].y=aY-(Ay/Dis)/2.0,Sun[b].y=aY+(Ay/Dis)/2.0;return;}double ac=Sun[a].m*Sun[b].m/(Dis*Dis)*1.0,afx=0,afy=0,d=abs(Ax/Ay*1.0);afy=sqrt(ac/(1+d*d))*1.0,afx=sqrt(ac/(1+d*d))*d*1.0;if(Ax>0) afx*=-1;if(Ay>0) afy*=-1;
#define A Sun[a].vx+=afx/Sun[a].m*Speedless,Sun[a].vx=max(-Speedmax,min(Speedmax,Sun[a].vx)),Sun[a].vy+=afy/Sun[a].m*Speedless,Sun[a].vy=max(-Speedmax,min(Speedmax,Sun[a].vy))
#define B Sun[b].vx-=afx/Sun[b].m*Speedless,Sun[b].vx=max(-Speedmax,min(Speedmax,Sun[b].vx)),Sun[b].vy-=afy/Sun[b].m*Speedless,Sun[b].vy=max(-Speedmax,min(Speedmax,Sun[b].vy))Speedmax=0.1,Speedless=0.01; if(Sun[a].what==2&&Sun[b].what==2) Speedmax=3.0;if(Sun[a].what==0) {Speedless=0.008;Speedmax=1.0; A;}else if(Sun[a].what==1) {A; if(Sun[b].what==1) B;}else if(Sun[a].what==2) {Speedless=0.8;B;if(Sun[b].what==2) A;}else {A;B;}
}
int Painting[41][41]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,1,1,1,1,1,1,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,3,9,9,9,9,9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,4,9,9,9,9,9,9,9,9,9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},};
void Paint(int a);
void Move(int a){Blood=10000000;memset(m,0,sizeof(m));memset(m2,0,sizeof(m2));#define ix toint(Sun[i].x/1.0)#define iy toint(Sun[i].y/1.0)#define jx toint(Sun[j].x/1.0)#define jy toint(Sun[j].y/1.0)if(Sun[0].life==1){Sun[0].x+=Sun[0].vx/Speedmore;Sun[0].y+=Sun[0].vy/Speedmore;if(Sun[0].x>40) Sun[0].x=40,Sun[0].vx=0;if(Sun[0].x<0) Sun[0].x=0,Sun[0].vx=0;if(Sun[0].y>40) Sun[0].y=40,Sun[0].vy=0;if(Sun[0].y<0) Sun[0].y=0,Sun[0].vy=0;}for(int i=0;i<=b;i++) for(int j=i+1;j<=b;j++) Push(i,j);for(int i=0;i<=b;i++) for(int j=0;j<=b;j++){if(i==j||Sun[i].life==0||Sun[j].life==0) continue;if(Sun[i].what==4&&(Sun[j].what>=100&&Sun[j].what<200)) {if(abs(ix-jx)<1&&abs(iy-jy)<1) Ba--,Sun[i].life=Sun[j].life=0,Score+=10;}if(Sun[i].what==203&&Sun[i].master!=j&&Sun[j].what<200) if(abs(ix-jx)<2&&abs(iy-jy)<2) Sun[j].vx-=Sun[i].vx/10.0,Sun[j].vy-=Sun[i].vy/10.0,Sun[i].life=0;if(Sun[i].what==204&&Sun[i].master!=j&&Sun[j].what<200) if(abs(ix-jx)<2&&abs(iy-jy)<2) Sun[j].vx+=Sun[i].vx/10.0,Sun[j].vy+=Sun[i].vy/10.0,Sun[i].life=0;}int i=0;if(m[ix][iy]>0&&m[ix][iy]<100){if(m[ix][iy]<=1) Blood-=1;else if(m[ix][iy]<=4) Blood-=2;else if(m[ix][iy]<=10) Blood-=3;else if(m[ix][iy]>10&&m[ix][iy]<100) Blood-=4;}for(int i=1;i<=b;i++){if(Sun[i].life==0) continue;Sun[i].x+=Sun[i].vx/Speedmore;Sun[i].y+=Sun[i].vy/Speedmore;Balljump=-0.7;if(Sun[i].what==3) Balljump=-1;if(Sun[i].what==4) Balljump=-1;if(Sun[i].x>40) Sun[i].x=40,Sun[i].vx*=Balljump;if(Sun[i].x<0) Sun[i].x=0,Sun[i].vx*=Balljump;if(Sun[i].y>40) Sun[i].y=40,Sun[i].vy*=Balljump;if(Sun[i].y<0) Sun[i].y=0,Sun[i].vy*=Balljump;if(Sun[i].what==1) {m[ix][iy]+=2;int R;R=rand(3);if(R==0&&ix<40) m[ix+1][iy]++;R=rand(3);if(R==0&&ix>0) m[ix-1][iy]++;R=rand(3);if(R==0&&iy<40) m[ix][iy+1]++;R=rand(3);if(R==0&&iy>0) m[ix][iy-1]++;}if(Sun[i].what==2) {m[ix][iy]+=2;if(ix<40) m[ix+1][iy]+=10;if(ix>0) m[ix-1][iy]+=10;if(iy<40) m[ix][iy+1]+=10;if(iy>0) m[ix][iy-1]+=10;if(ix<40&&iy<40) m[ix+1][iy+1]+=4;if(ix<40&&iy>0) m[ix+1][iy-1]+=4;if(ix>0&&iy<40) m[ix-1][iy+1]+=4;if(ix>0&&iy>0) m[ix-1][iy-1]+=4;m[ix][iy]=10086;} if(Sun[i].what==3) {if(abs(ix-Sun[0].x)<1&&abs(iy-Sun[0].y)<1) Ba--,Sun[i].life=0;else m2[ix][iy]=2;}if(Sun[i].what==4) {m2[ix][iy]=2;}if(Sun[i].what>=100&&Sun[i].what<300){if(Sun[i].x==0||Sun[i].y==0||Sun[i].x==40||Sun[i].y==40||(abs(Sun[i].vx)<=0.5&&abs(Sun[i].vy)<=0.5)) Sun[i].life=0;if(Sun[i].what==203||Sun[i].what==204) {m[ix][iy]=Sun[i].what;if(ix<40) m[ix+1][iy]=Sun[i].what;if(ix>0) m[ix-1][iy]=Sun[i].what;if(iy<40) m[ix][iy+1]=Sun[i].what;if(iy>0) m[ix][iy-1]=Sun[i].what;}else m2[ix][iy]=Sun[i].what;} }if(Sun[0].life==1) m2[toint(Sun[0].x/1.0)][toint(Sun[0].y/1.0)]=1;Paint(a);
}
void Paint(int a){
for(int i=0;i<=40;i++) for(int j=0;j<=40;j++){if(a==0&&Painting[i][j]!=0) continue;if(m2[i][j]!=n2[i][j]){n2[i][j]=m2[i][j];n[i][j]=0;Setpos(i,j);if(m2[i][j]==0) Color(0),cout<<" ";else if(m2[i][j]==1) Color(-1),cout<<"●";else if(m2[i][j]==2) Color(-3),cout<<"◎";else if(m2[i][j]==101) Color(-1),cout<<"☉";else if(m2[i][j]==102) Color(3),cout<<" ";continue;}if(m[i][j]!=n[i][j]){n[i][j]=m[i][j];n2[i][j]=0;Setpos(i,j);if(m[i][j]>=10086) Color(4),cout<<"●";else if(m[i][j]==203) Color(5),cout<<" ";else if(m[i][j]==204) Color(6),cout<<" ";else if(m[i][j]==0) Color(0),cout<<" ";else if(m[i][j]<=1) Color(1),cout<<" ";else if(m[i][j]<=4) Color(2),cout<<" ";else if(m[i][j]<=10) Color(3),cout<<" ";else if(m[i][j]>10&&m[i][j]<100) Color(4),cout<<" ";else Color(0),cout<<"?!";}Color(0);}
}
void RandStart(int a) {for(int i=1;i<=a;i++) {b++;Sun[b].x=rand(41),Sun[b].y=rand(41);Sun[b].vx=(rand(41)-20)/10.0,Sun[b].vy=(rand(41)-20)/10.0,Sun[b].m=1,Sun[b].r=1,Sun[b].life=1,Sun[b].what=1;}}
void CornerStart(int a) {for(int i=1;i<=a;i++) {b++;int k=rand(4);if(k==0||k==2) Sun[b].x=rand(41);else Sun[b].y=rand(41);if(k==0) Sun[b].y=0;if(k==1) Sun[b].x=0;if(k==2) Sun[b].y=40;if(k==3) Sun[b].x=40;Sun[b].vx=(rand(41)-20)/10.0,Sun[b].vy=(rand(41)-20)/10.0,Sun[b].m=1,Sun[b].r=1,Sun[b].life=1,Sun[b].what=1;}}
void SunStart(int x,int y,int r,int vx,int vy) {
b++;Sun[b].x=x,Sun[b].y=y;Sun[b].vx=vx,Sun[b].vy=vy,Sun[b].m=1000,Sun[b].r=1,Sun[b].life=1,Sun[b].what=2;
for(int i=x-r;i<=x+r;i++) for(int j=y-r;j<=y+r;j++){b++;Sun[b].x=i,Sun[b].y=j;Sun[b].vx=(rand(41)-20)/100.0+vx,Sun[b].vy=(rand(41)-20)/100.0+vy,Sun[b].m=1,Sun[b].r=1,Sun[b].life=1,Sun[b].what=1;}
for(float i=(int)(x-r/2)-0.5;i<=(int)(x+r/2)+0.5;i++) for(float j=(int)(y-r/2)-0.5;j<=(int)(y+r/2)+0.5;j++){b++;Sun[b].x=i,Sun[b].y=j;Sun[b].vx=(rand(41)-20)/100.0+vx,Sun[b].vy=(rand(41)-20)/100.0+vy,Sun[b].m=1,Sun[b].r=1,Sun[b].life=1,Sun[b].what=1;}
}
void Shoot(int a,bool q)
{double Sunavx=Sun[a].vx,Sunavy=Sun[a].vy;if(Sun[a].vx==0&&Sun[a].vy==0) Sunavx=-1;if(Sun[a].vy==0) Sunavy=0.001;if(Sun[a].gun>=1&&Sun[a].gun<=4){b++;Sun[b].x=Sun[a].x,Sun[b].y=Sun[a].y;double ac;if(Sun[a].gun==1) ac=3.0; if(Sun[a].gun>=2&&Sun[a].gun<=4) ac=7.0;double d=abs(Sunavx/Sunavy*1.0);Sun[b].vy=sqrt(ac/(1+d*d))*1.0,Sun[b].vx=sqrt(ac/(1+d*d))*d*1.0;if(Sunavx>0) Sun[b].vx*=-1;if(Sunavy>0) Sun[b].vy*=-1;if(q==1) Sun[b].vx*=-1,Sun[b].vy*=-1;Sun[b].life=1;Sun[b].master=a;int bb=b;if(Sun[a].gun==1||Sun[a].gun==2) Sun[b].what=100+Sun[a].gun,Sun[b].m=1;if(Sun[a].gun==3||Sun[a].gun==4) Sun[b].what=200+Sun[a].gun,Sun[b].m=1;if(Sun[a].gun>=2&&Sun[a].gun<=4){double kx=Sun[bb].x,ky=Sun[bb].y;for(int j=1;j<=7;j++){kx-=Sun[bb].vx/3.5,ky-=Sun[bb].vy/3.5;if(kx<0||ky<0||kx>40||ky>40) continue;b++,Sun[b].x=kx,Sun[b].y=ky,Sun[b].vx=Sun[bb].vx,Sun[b].vy=Sun[bb].vy,Sun[b].what=Sun[bb].what,Sun[b].master=a,Sun[b].life=1;}}}
}
void Start(){for(int i=0;i<=40;i++) for(int j=0;j<=40;j++){if(Painting[i][j]==1) Setpos(i,j),Color(-2),cout<<"■";if(Painting[i][j]==2) Setpos(i,j),Color(-2),cout<<"作者:蒟蒻一枚";if(Painting[i][j]==3) Setpos(i,j),Color(-2),cout<<"按 y 开始游戏!";if(Painting[i][j]==4) Setpos(i,j),Color(-2),cout<<"不要搞错成拼音输入法!";if(Painting[i][j]==5) Setpos(i,j),Color(-2),cout<<"Three-Body STAR WARs!";}for(int i=1;i<=3;i++) SunStart(rand(31)+5,rand(31)+5,5,(rand(101)-50)/10.0,(rand(101)-50)/10.0);T=0;while(1){T++;if(T%50==0) CornerStart(1);if(kbhit()){char g=_getch();if(g=='y') break; }Move(0);Sleep(Speed);}Color(0);system("cls");Setpos(10,10);SlowDisplay(30,"你想要教程吗?(y/n)");char g=_getch();if(g!='y') return;Setpos(10,10);SlowDisplay(30,"那我们开始。。。 ");Sleep(500);system("cls");Setpos(30,10);system("cls");memset(Sun,0,sizeof(Sun));memset(m,0,sizeof(m));memset(m2,0,sizeof(m2));Sun[0].x=Sun[0].y=20;Sun[0].life=1;Sun[0].m=10;T=0;int step=0;while(1){T++;if(T==2){Setpos(10,10),SlowDisplay(30,"这是你的飞船,你可以用↑↓←→键来操纵它。");Sleep(500);Setpos(12,10),SlowDisplay(30,"在宇宙航行没有阻力,也就是说你的惯性会主导一切。");Sleep(500);Setpos(14,10),SlowDisplay(30,"当你撞到边界时,你的速度会减为零。");Sleep(1000); Setpos(16,10),SlowDisplay(30,"试试看。");}if(T==200){Setpos(10,10),SlowDisplay(30,"在宇宙航行时有两个小技巧: ");Setpos(12,10),SlowDisplay(30,"1、不要太快。 ");Setpos(14,10),SlowDisplay(30,"2、有时转向比调头更有用。 ");Sleep(1000);Setpos(16,10),SlowDisplay(30,"接下来我们稍稍提高点难度!请到达所有靶位点!");Sleep(500);b++;Sun[b].x=rand(40),Sun[b].y=rand(40);Sun[b].vx=(rand(101)-50)/30.0,Sun[b].vy=(rand(101)-50)/30.0,Sun[b].life=1,Sun[b].what=3;Ba++;Move(1);Sleep(1000); }if(Ba>0) Setpos(1,1),cout<<"剩余靶位点:"<<Ba<<' ';if(step>=1) Setpos(5,1),cout<<"Cooling time: "<<Hotguntime<<" ";if(T>200&&Ba==0&&step==0) T=201,step=1,Setpos(1,1),cout<<" ";if(T>300&&Ba==0&&step==1) T=201,step=2,Setpos(1,1),cout<<" ";if(T==202&&step==1){Setpos(10,10),SlowDisplay(30,"做的好!看来是时候给你装备初始武器了。");Setpos(12,10),SlowDisplay(50,"。。。 星际电磁轨道炮 已装备。");Setpos(14,10),SlowDisplay(30,"按下w/s发射子弹! ");Sun[0].gun=1;Hotguntime=0;}if(T==300&&step==1){Setpos(16,10),SlowDisplay(30,"来吧!请击毁所有靶位点!");Sleep(500);b++;Sun[b].x=rand(40),Sun[b].y=rand(40);Sun[b].vx=(rand(101)-50)/30.0,Sun[b].vy=(rand(101)-50)/30.0,Sun[b].life=1,Sun[b].what=4;Ba++;Move(1);Sleep(1000); Ba=1;}if(T==202&&step==2){Setpos(10,10),SlowDisplay(30,"太阳什么的你也看到过了。 ");Setpos(12,10),SlowDisplay(30,"其旁缠绕着的火会扣你的血。 ");Setpos(14,10),SlowDisplay(30,"打靶位点可以积10分,发射子弹-1分,分数达到20通关,简单吧!");Sleep(1000); Setpos(16,10),SlowDisplay(60,"让 我 们 开 始 吧!!!");Sleep(1000); system("cls");return; }double v=sqrt(Sun[0].vx*Sun[0].vx+Sun[0].vy*Sun[0].vy);if(GetAsyncKeyState(VK_UP)&0x8000) {if(Sun[0].vx>=0) Sun[0].vx-=2*Fire;else if(v<4) Sun[0].vx-=Fire;}else if(GetAsyncKeyState(VK_DOWN)&0x8000) {if(Sun[0].vx<=0) Sun[0].vx+=2*Fire;else if(v<4) Sun[0].vx+=Fire;}if(GetAsyncKeyState(VK_LEFT)&0x8000) {if(Sun[0].vy>=0) Sun[0].vy-=2*Fire;else if(v<4) Sun[0].vy-=Fire;}else if(GetAsyncKeyState(VK_RIGHT)&0x8000) {if(Sun[0].vy<=0) Sun[0].vy+=2*Fire;else if(v<4) Sun[0].vy+=Fire;}if(Hotguntime>0) Hotguntime--;if(kbhit()){char g=_getch();if(Hotguntime==0&&g=='s'){if(abs(Sun[0].vx)>=0.01) Sun[0].vx*=0.7;if(abs(Sun[0].vy)>=0.01) Sun[0].vy*=0.7;Shoot(0,0);Hotguntime=Hotguntimemax;}if(Hotguntime==0&&g=='w'){if(abs(Sun[0].vx)<=2) Sun[0].vx*=1.2;if(abs(Sun[0].vy)<=2) Sun[0].vy*=1.2;Shoot(0,1);Hotguntime=Hotguntimemax;}}Move(1);Sleep(Speed);}
}
int main()
{system("mode con cols=82 lines=43");CONSOLE_CURSOR_INFO cursor_info={1,0};SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);srand((unsigned)time(NULL));Y:Start();memset(Sun,0,sizeof(Sun));memset(m,0,sizeof(m));memset(m2,0,sizeof(m2));YY:system("cls");Setpos(10,10),SlowDisplay(30,"选难度吧,几个太阳?(0~10,回车确定)");int i=10;while(dif[i]!=1&&i>=0){i--;}Setpos(12,10);if(i==-1) printf("推荐难度:0个太阳。");else if(i<10) printf("加油,推荐难度:%d个太阳。",i+1);else if(i==10) printf("你通关了!随便选吧!",i);Setpos(15,10);int p;cin>>p;if(p<0||p>10) {SlowDisplay(150,"输入错误!"),Sleep(1000);goto YY;}for(int i=1;i<=p;i++) SunStart(rand(31)+5,rand(31)+5,5,(rand(101)-50)/10.0,(rand(101)-50)/10.0);Sun[0].x=Sun[0].y=5;Sun[0].vx=0.1;Sun[0].life=1;Sun[0].m=10;T=0;Sun[0].gun=1;Blood=100;Score=0;Ba=0;for(int i=1;i<=10;i++) {b++;Sun[b].x=rand(40),Sun[b].y=rand(40);Sun[b].vx=(rand(101)-50)/30.0,Sun[b].vy=(rand(101)-50)/30.0,Sun[b].life=1,Sun[b].what=4;Ba++;}while(Blood>0&&Score<100){Setpos(1,1),cout<<"Blood: "<<Blood<<" ";Setpos(3,1),cout<<"Score: "<<Score<<" ";Setpos(5,1),cout<<"Cooling time: "<<Hotguntime<<" ";T++;if(T==1) Sleep(1000);if(T%50==0) CornerStart(1);if(T%30==0&&Ba<5) {b++;Sun[b].x=rand(40),Sun[b].y=rand(40);Sun[b].vx=(rand(101)-50)/30.0,Sun[b].vy=(rand(101)-50)/30.0,Sun[b].life=1,Sun[b].what=4;Ba++;}if(T%40==0&&Blood<100) Blood++;double v=sqrt(Sun[0].vx*Sun[0].vx+Sun[0].vy*Sun[0].vy);if(GetAsyncKeyState(VK_UP)&0x8000) {if(Sun[0].vx>=0) Sun[0].vx-=2*Fire;else if(v<4) Sun[0].vx-=Fire;}else if(GetAsyncKeyState(VK_DOWN)&0x8000) {if(Sun[0].vx<=0) Sun[0].vx+=2*Fire;else if(v<4) Sun[0].vx+=Fire;}if(GetAsyncKeyState(VK_LEFT)&0x8000) {if(Sun[0].vy>=0) Sun[0].vy-=2*Fire;else if(v<4) Sun[0].vy-=Fire;}else if(GetAsyncKeyState(VK_RIGHT)&0x8000) {if(Sun[0].vy<=0) Sun[0].vy+=2*Fire;else if(v<4) Sun[0].vy+=Fire;}if(Hotguntime>0) Hotguntime--;if(kbhit()){char g=_getch();if(Hotguntime==0&&g=='s'){if(abs(Sun[0].vx)>=0.01) Sun[0].vx*=0.7;if(abs(Sun[0].vy)>=0.01) Sun[0].vy*=0.7;Shoot(0,0);Score=max(Score-1,0);Hotguntime=Hotguntimemax;}if(Hotguntime==0&&g=='w'){if(abs(Sun[0].vx)<=2) Sun[0].vx*=1.2;if(abs(Sun[0].vy)<=2) Sun[0].vy*=1.2;Shoot(0,1);Score=max(Score-1,0);Hotguntime=Hotguntimemax;}}Move(1);Sleep(Speed);}system("cls");if(Score<20) Setpos(10,10),SlowDisplay(150,"Sorry,你死了。"); else Setpos(10,10),SlowDisplay(10,"赢了!快去挑战下一个难度吧!"),dif[p]=1; Sleep(1000); goto Y;return 0;
}
相关文章:
C++三体星战小游戏
物理小游戏,懒得 写注释。 游戏代码 #include<bits/stdc.h> #include<bits/stdc.h> #include<windows.h> #include<conio.h> using namespace std; int toint(double a){return ((int)(a*105))/10;} int rand(int a){return rand()%a;} vo…...

【zip密码】修改zip压缩包密码
Zip压缩包设置了密码,想要修改密码,我们该如何操作?今天分享两个修改zip压缩包密码的方法。 方法一: 输入密码,将zip压缩包里面的文件解压出来。 然后找到解压出来的文件,将文件重新压缩,并且…...
小小讲一下Linux基本命令
Linux是一套类Unix的操作系统,这套系统最大的优点就是安全便捷,快速高效。这就为它赢得了广大的市场空间。但是呢,Linux系统虽然广为流行,它也不是那么容易就可以学会的。比如说,如果我们不懂得Linux系统的基本操作命令…...
Python数据容器(列表list、元组tuple、字符串str、字典dict、集合set)详解
一、数据容器概念 相关介绍: 一种可以容纳多份数据的数据类型,容纳的每一份数据称之为一个元素。每一个元素,可以是任意类型的数据分为五类:列表[list]、元组(tuple)、字符串(str)、集合{set}、字典{dict} 相应区别:…...

2023高教社杯数学建模思路 - 复盘:人力资源安排的最优化模型
文章目录 0 赛题思路1 描述2 问题概括3 建模过程3.1 边界说明3.2 符号约定3.3 分析3.4 模型建立3.5 模型求解 4 模型评价与推广5 实现代码 建模资料 0 赛题思路 (赛题出来以后第一时间在CSDN分享) https://blog.csdn.net/dc_sinor?typeblog 1 描述 …...

Linux 计算机网络基础概论
一、网络基本概念 1、网络 网络是由若干节点和连接这些结点的链路组成,网络中的结点可以是计算机、交换机、路由器等设备。通俗地说就是把不同的主机连接起来就构成了一个网络,构成网路的目的是为了信息交互、资源共享。 网络设备有:交换机…...

深入理解 C++ 中的 std::cref、std::ref 和 std::reference_wrapper
深入理解 C 中的 std::cref、std::ref 和 std::reference_wrapper 在 C 编程中,有时候我们需要在不进行拷贝的情况下传递引用,或者在需要引用的地方使用常量对象。为了解决这些问题,C 标准库提供了三个有用的工具:std::cref、std:…...

在其他python环境中使用jupyter notebook
1、切换到目标python环境 activate 目标python环境 2、安装notebook内核包 pip install ipykernel 3、加环境加入到notebook中 python -m ipykernel install 目标python环境 4、切换到base环境 activate base 5、打开目标项目的对应盘 如果,项目在c盘&…...

计算机网络-笔记-第二章-计算机网络概述
目录 二、第二章——物理层 1、物理层的基本概念 2、物理层下面的传输媒体 (1)光纤、同轴电缆、双绞线、电力线【导引型】 (2)无线电波、微波、红外线、可见光【非导引型】 (3)无线电【频谱的使用】 …...
Hive字符串数组json类型取某字段再列转行
一、原始数据 acctcontent1232313[{"name":"张三","code":"上海浦东新区89492jfkdaj\r\n福建的卡"...},{"name":"狂徒","code":"select * from table where aa1\r\n and a12"...},{...}]...…...

ElementUI Table 翻页缓存数据
Element UI Table 翻页保存之前的数据,网上找了一些,大部分都是用**:row-key** 和 reserve-selection,但是我觉得有bug,我明明翻页了…但是全选的的个框还是勾着的(可能是使用方法不对,要是有好使的…请cute我一下…感谢) 所以自己写了一个… 思路: 手动勾选的时候,将数据保存…...
使用 AutoGPTQ 和 transformers 让大语言模型更轻量化
大语言模型在理解和生成人类水平的文字方面所展现出的非凡能力,正在许多领域带来应用上的革新。然而,在消费级硬件上训练和部署大语言模型的需求也变得越来越难以满足。 🤗 Hugging Face 的核心使命是 让优秀的机器学习普惠化 ,而…...
AUTOSAR规范与ECU软件开发(实践篇)6.5 BswM模块概念与配置方法介绍
目录 1、BswM模块概念与配置方法介绍 (1) BswMModeRequestPort配置 (2) ModeCondition与LogicalExpression配置...

1.1 VMware Workstation与Kali的安装和配置1
资源见专栏第一篇文章https://blog.csdn.net/algorithmyyds/article/details/132457258 安装VMware 不多加赘述,直接按顺序安装即可。 有以下需注意的地方: 1.建议选择增强型服务; 2.不要加入体验改进计划。是否开启提示更新看你的想法&…...

DDR与PCIe:高性能SoC的双引擎
SoC芯片无处不在,小到家电控制的MCU,大到手机芯片,我们都会接触到。如今大部分芯片设计公司都在开发SoC芯片,一颗SoC芯片可以集成越来越多的功能,俨然它已成为IC设计业界的焦点。 高性能、高速、高带宽的互联和存储的…...

C#_特性反射详解
特性是什么? 为程序元素额外添加声明信息的一种方式。 字面理解:相当于把额外信息写在干胶标签上,然后将其贴在程序集上。 反射是什么? 反射是一种能力,运行时获取程序集中的元数据。 字面理解:程序运行…...
【跟小嘉学 Rust 编程】十三、函数式语言特性:迭代器和闭包
系列文章目录 【跟小嘉学 Rust 编程】一、Rust 编程基础 【跟小嘉学 Rust 编程】二、Rust 包管理工具使用 【跟小嘉学 Rust 编程】三、Rust 的基本程序概念 【跟小嘉学 Rust 编程】四、理解 Rust 的所有权概念 【跟小嘉学 Rust 编程】五、使用结构体关联结构化数据 【跟小嘉学…...

时间复杂度和空间复杂度
全文目录 算法的复杂度时间复杂度大O渐进表示法空间复杂度常见算法复杂度对比 算法的复杂度 算法在编写成可执行程序后,运行时需要耗费时间资源和空间(内存)资源 。因此衡量一个算法的好坏,一般是从时间和空间两个维度来衡量的,即时间复杂度…...
mac docker 卡住解决
文章目录 1、问题简述2、重新安装docker3、docker守护进程4、问题解决方案 1、问题简述 在docker desktop上更改了daemon.json的文件内容,应该是参数写的有问题,修改完配置再启动docker desktop就失败了,然后想着卸载docker desktop…...

linux/centos zookeeper 使用记录
配置cfg 下载zookeeper-3.4.14.tar.gz负责到centos服务器解压 /xxx/zookeeper-3.4.14/conf/下创建zoo.cfg文件并配置以下属性,/bsoft/zookeeperdata/目录先预先创建 tickTime2000 initLimit10 syncLimit5 dataDir/bsoft/zookeeperdata/ clientPort2181zk启动/重启/关…...

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?
编辑:陈萍萍的公主一点人工一点智能 未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战,在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…...

(十)学生端搭建
本次旨在将之前的已完成的部分功能进行拼装到学生端,同时完善学生端的构建。本次工作主要包括: 1.学生端整体界面布局 2.模拟考场与部分个人画像流程的串联 3.整体学生端逻辑 一、学生端 在主界面可以选择自己的用户角色 选择学生则进入学生登录界面…...
MySQL 隔离级别:脏读、幻读及不可重复读的原理与示例
一、MySQL 隔离级别 MySQL 提供了四种隔离级别,用于控制事务之间的并发访问以及数据的可见性,不同隔离级别对脏读、幻读、不可重复读这几种并发数据问题有着不同的处理方式,具体如下: 隔离级别脏读不可重复读幻读性能特点及锁机制读未提交(READ UNCOMMITTED)允许出现允许…...

【机器视觉】单目测距——运动结构恢复
ps:图是随便找的,为了凑个封面 前言 在前面对光流法进行进一步改进,希望将2D光流推广至3D场景流时,发现2D转3D过程中存在尺度歧义问题,需要补全摄像头拍摄图像中缺失的深度信息,否则解空间不收敛…...

Cinnamon修改面板小工具图标
Cinnamon开始菜单-CSDN博客 设置模块都是做好的,比GNOME简单得多! 在 applet.js 里增加 const Settings imports.ui.settings;this.settings new Settings.AppletSettings(this, HTYMenusonichy, instance_id); this.settings.bind(menu-icon, menu…...

DIY|Mac 搭建 ESP-IDF 开发环境及编译小智 AI
前一阵子在百度 AI 开发者大会上,看到基于小智 AI DIY 玩具的演示,感觉有点意思,想着自己也来试试。 如果只是想烧录现成的固件,乐鑫官方除了提供了 Windows 版本的 Flash 下载工具 之外,还提供了基于网页版的 ESP LA…...
在Ubuntu中设置开机自动运行(sudo)指令的指南
在Ubuntu系统中,有时需要在系统启动时自动执行某些命令,特别是需要 sudo权限的指令。为了实现这一功能,可以使用多种方法,包括编写Systemd服务、配置 rc.local文件或使用 cron任务计划。本文将详细介绍这些方法,并提供…...
解决本地部署 SmolVLM2 大语言模型运行 flash-attn 报错
出现的问题 安装 flash-attn 会一直卡在 build 那一步或者运行报错 解决办法 是因为你安装的 flash-attn 版本没有对应上,所以报错,到 https://github.com/Dao-AILab/flash-attention/releases 下载对应版本,cu、torch、cp 的版本一定要对…...
土地利用/土地覆盖遥感解译与基于CLUE模型未来变化情景预测;从基础到高级,涵盖ArcGIS数据处理、ENVI遥感解译与CLUE模型情景模拟等
🔍 土地利用/土地覆盖数据是生态、环境和气象等诸多领域模型的关键输入参数。通过遥感影像解译技术,可以精准获取历史或当前任何一个区域的土地利用/土地覆盖情况。这些数据不仅能够用于评估区域生态环境的变化趋势,还能有效评价重大生态工程…...
【C++从零实现Json-Rpc框架】第六弹 —— 服务端模块划分
一、项目背景回顾 前五弹完成了Json-Rpc协议解析、请求处理、客户端调用等基础模块搭建。 本弹重点聚焦于服务端的模块划分与架构设计,提升代码结构的可维护性与扩展性。 二、服务端模块设计目标 高内聚低耦合:各模块职责清晰,便于独立开发…...