-
个人简介
声明:所有游戏均自测试玩过,下面都有评价,目标是搜集全网游戏,若有投稿会署名
#include<bits/stdc++.h> #include<windows.h> int again,cho,num,about,fla=0,strc; int three=0,five=0,ten=0,dmon,dumo=0,paim=0; long long money=0;long shop[4],pric[5]={0,30,60,90}; int main() { srand(time(NULL)); int b,p,x,c,d,e=0,f=0,g,h=0,i=1,j,l,m,n=5,o=0,flag=0,t1=0,t2=0,last=0; int flog=0,tans=0,change=0,choo,ice,tangc=0,train,goch=0,game=1,choos=1; if(paim!=0&&dumo!=0) { printf("你在赌场投注了赌金\n");Sleep(1000); switch(paim) { case 1:printf("恭喜恭喜!获得了100%的赌金!获得了%d元\n",dumo*2);money+=dumo*2;break; case 2:printf("祝贺祝贺!获得了50%的赌金!获得了%d元\n",dumo*1.5);money+=dumo*1.5;break; case 3:printf("很遗憾!获得了-50%的赌金!挽回了%d元\n",dumo*0.5);money+=dumo*0.5;break; default:printf("继续加油吧,赌金就被赌场收下了\n"); } printf("\n"); Sleep(3000); dumo=0;paim=0; } if(three==3) { printf("恭喜三连胜!\n"); Sleep(1000); printf("我们为你准备了丰厚的奖品:150元,复活卡3张,冰冻卡2张,无敌卡1张\n\n"); money+=150,shop[1]+=3,shop[2]+=2,shop[3]+=1; three=0;Sleep(3000); } if(five==5) { printf("恭喜五连胜!\n"); Sleep(1000); printf("我们为你准备了丰厚的奖品:300元,复活卡6张,冰冻卡4张,无敌卡3张\n\n"); money+=300,shop[1]+=6,shop[2]+=4,shop[3]+=3; five=0;Sleep(3000); } if(ten==10) { printf("恭喜十连胜!\n"); Sleep(1000); printf("我们为你准备了丰厚的奖品:1000元,复活卡15张,冰冻卡12张,无敌卡10张\n\n"); money+=1000,shop[1]+=15,shop[2]+=12,shop[3]+=10; ten=0;Sleep(3000); } printf("按1->开始游戏,按2->商店,按3->赌场,按4->规则,按5->关于,按0->退出\n"); scanf("%d",&strc); if(strc>5) { printf("请不要乱来!\n\n"); Sleep(1000);return main(); } if(strc==0) return 0; if(strc==2) { printf("---------------------------------------------\n杀手商店---"); printf("您现在有%d元\n",money); printf("复活卡30一张,您现在拥有%d张(购买:按1)\n",shop[1]); printf("冰冻卡60一张,您现在拥有%d张(购买:按2)\n",shop[2]); printf("无敌卡90一张,您现在拥有%d张(购买:按3)\n(返回主页:按4)\n",shop[3]); scanf("%d",&cho); if(cho==4) { printf("---------------------------------------------\n\n"); return main(); } printf("请输入购买数量:"); scanf("%d",&train); if(money>=pric[cho]*train) { money-=pric[cho]*train; shop[cho]+=train; printf("购买成功,道具已开始生效!\n---------------------------------------------\n\n"); return main(); } else { printf("钱不够了!\n---------------------------------------------\n\n"); return main(); } } if(strc==3) { printf("---------------------------------------------\n欢迎来到J神赌场!\n"); Sleep(1000); DC:printf("按1开始投注,按2观看规则,按3退出\n"); scanf("%d",&dmon); if(dmon==1) { Sleep(1000);printf("请确认看了规则(没看规则的在下面输入0)!\n"); Sleep(1000);printf("请输入赌金(元):"); scanf("%d",&dumo); if(dumo!=0&&dumo<=money) { printf("投注成功!\n---------------------------------------------\n\n"); money-=dumo;return main(); } if(dumo>money) { printf("钱不够了!\n\n"); dumo=0; goto DC; } } if(dmon!=3) { Sleep(1000); printf("投注后第一局:\n"); printf("第一名:获得赌金的100%\n"); printf("第二名:获得赌金的50%\n"); printf("第三名:获得赌金的-50%\n"); printf("第四名/第五名:赌金就被赌场收下了\n"); printf("\n");goto DC; } printf("---------------------------------------------\n\n"); return main(); } if(strc==4) { Sleep(1000);printf("\n复活卡可死后多加一条命,单局只能使用一次,决斗时无法生效\n"); Sleep(1000);printf("冰冻卡可冰冻指定杀手二回合,死后可随机诅咒,单局只能使用一次\n"); Sleep(1000);printf("无敌卡可开局无敌三回合\n"); Sleep(1000);printf("其他规则参见CSDN: ShineEternal 的博客\n"); Sleep(1000);printf("10秒后返回主页\n\n"); Sleep(10000);return main(); } if(strc==5) { printf("---------------------------------------------\n游戏信息\n"); printf("游戏版本:1.1.1 更新信息按1;\n"); printf("原创: CSDN: ShineEternal ,更新: 51CTO: Jeffrey2020\n"); printf("支持作者请按2,喷作者请按3,返回主页请按4;\n"); scanf("%d",&about); switch(about) { case 1:printf("\n1.1.2版本:\n更新时间:暂不定,让我好好过个生日吧\n更新目标:1.打定药水草稿\n\t 2.开通活动专栏\n\t 3.修复其他bug");break; case 2:printf("爱你哟,么么哒!");if(fla==0) money+=60;break; case 3:printf("我记住你了");Sleep(2000);printf("\n后会无期!");return 0;break; } printf("\n---------------------------------------------\n\n"); return main(); } printf("\n选择你的杀手等级(1-5)\n"); scanf("%d",&b); int a[6]={0,1,2,3,4,5},k[10]={0}; AA:while(n!=1) { printf("\n"); if(game==1&&i==1&&shop[3]>=1) { printf("是否启用无敌卡?是按0,否按1\n"); scanf("%d",&choos); if(choos==0) { Sleep(1000); printf("启用成功!\n"); shop[3]--; } printf("\n"); } if(n==2&&last==0) { Sleep(1000); printf("决斗时刻!\n"); for(int las=1;las<=5;++las) { if(t1==0&&a[las]!=0) t1=las; else if(a[las]!=0&&t1!=0) t2=las; } Sleep(1000); printf("%d号与%d号冠军之争!\n\n",t1,t2); last=1; } if(i==1&&change==0) { Sleep (1000); printf("存活者:%d %d %d %d %d\n\n",a[1],a[2],a[3],a[4],a[5]); } if(i==6) i=1,game++; if(a[i]==0) { i++; continue; } Sleep(1000); if(tangc==0) printf("轮到%d号\n",i); else tangc=0; if(i==b) { Sleep(1000); FF:if(goch==1) Sleep(1000); printf("选择你要攻击的目标:%d %d %d %d %d",a[1],a[2],a[3],a[4],a[5]); if(shop[2]>=1&&change==0) printf(" 若要冰冻敌人请按6"); printf("\n"); scanf("%d",&choo); if(choo==6&&shop[2]>=1) { EE:Sleep(1000); printf("选择你要冰冻的目标:%d %d %d %d %d\n",a[1],a[2],a[3],a[4],a[5]); scanf("%d",&ice); if(a[ice]==0||ice==b||ice>5) { printf("你无法冰冻该杀手!\n"); goto EE; } else printf("冰冻成功!\n"),change=1,tangc=1; shop[2]--; goto AA; } else { p=choo; if(a[p]==0||p==b||p>5) { printf("你无法选择该杀手\n"); goch=1;goto FF; } } } else { do p=rand()%5+1; while(p!=i); while(a[p]==0||p==i) p=rand()%5+1; } if(i==ice&&tans<=1) { Sleep(1000); printf("%d号被冰冻,跳过\n\n",ice); i++;tans++; goto AA; } Sleep(1000); printf("%d号选择了%d号\n",i,p); Sleep(1000); printf("%d号掷出了%d\n",i,c=rand()%6+1); if(i>=c) { if(p==b&&choos==0&&game<=3) { Sleep(1000); printf("%d号无法杀死%d号,因为%d号开启了无敌卡\n\n",i,b,b); i++;goto AA; } a[p]=0; Sleep(1000); printf("%d号杀死了%d号\n\n",i,p); n--; } else {Sleep(1000); printf("%d号没有杀死目标\n\n",i);} if(i==5&&a[p]==0) { if(rand()%3==1||rand()%3==2) { if(p==1&&f<=2) { Sleep(1000); printf("5号无视1号复活权\n"); Sleep(800); printf("直接将其杀死\n\n"); f=3; } if(p==2&&h==0) { Sleep(1000); printf("5号无视2号复活权\n"); Sleep(800); printf("直接将其杀死\n\n"); h=1; } if(p==3&&o==0) { Sleep(1000); printf("5号无视3号复活权\n"); Sleep(800); printf("直接将其杀死\n\n"); o=1; } } } DD:if(a[1]==0) { if(b==1&&flag==1) goto AA; if(f<=2) { Sleep(1000); printf("1号使用复活权\n"); f++; n++; a[1]=1; if(f==1) { do g=rand()%5+1; while(a[g]==0||g==1); Sleep(1000); printf("并随机诅咒了%d号\n",g); if(g==b&&choos==0&&game<=3) { Sleep(1000); printf("%d号开启了无敌卡,免疫诅咒\n\n",b); i++;goto AA; } Sleep(1000); printf("%d号死了\n\n",g); a[g]=0; n--; } } else a[1]=0; } if(a[2]==0&&h==0) { if(b==2&&flag==1) goto AA; Sleep(1000); printf("2号使用复活权\n"); n++; a[2]=2; do m=rand()%5+1; while(a[m]==0||m==2); Sleep(1000); printf("并随机诅咒了%d号\n",m); if(rand()%2==1) { if(m==b&&choos==0&&game<=3) { Sleep(1000); printf("%d号开启了无敌卡,免疫诅咒\n\n",b); h=1;i++;goto AA; } a[m]=0; Sleep(1000); printf("%d号死了\n\n",m); n--; } else { Sleep(1000); printf("但他没死\n\n"); } h=1;goto DD; } if(a[3]==0&&o==0) { if(b==3&&flag==1) goto AA; Sleep(1000); printf("3号使用复活权\n\n"); a[3]=3; o++; n++; } if(i==4&&a[p]==0) { if(n==1) goto GG; else { Sleep(1000); printf("4号使用再次攻击权\n"); flog=1; if(p==b) goto GG; else goto AA; } } if(i==4&&a[p]!=0) flog=0; GG:if(a[b]==0&&e==0) { if(n==1) { num=1; goto CC; } if(shop[1]>=1&&flag==0) { Sleep(1000); printf("%d号使用复活卡继续游戏\n",b); flag=1; a[b]=b; shop[1]--; if(flog==1) { Sleep(1000); printf("4号再次攻击权被抵消\n"); flog=0; } printf("\n"); i++;n++;goto AA; } printf("你死了,是否继续?是按0,否按1\n"); scanf("%d",&x); if(x==1) { num=n; goto BB; } else if(x==0) e=1,num=n; } if(flog==0) i++; else flog=0; } if(num==0) num++; CC:for(j=1;j<=5;j++) if(a[j]!=0) d=j; Sleep(800); printf("%d号赢了",d); if(d==b) { printf("\n恭喜你第1名!赢得30元\n"),money+=30; three++,five++,ten++,paim=1; } else { BB:Sleep(1000); printf("\n结算:你的成绩为第%d名 奖励:",num+1); switch(num) { case 1:printf("20元\n");money+=20;paim=2;break; case 2:printf("10元\n");money+=10;paim=3;break; case 3:printf("5元\n");money+=5;paim=4;break; case 4:printf("无\n");paim=5;break; default:printf("(电脑出现未知现象,发生了什么?这是一个bug,待修复)\n"); } three=0,five=0,ten=0; } printf("游戏结束\n\n是否重新一局?是按0,否按1,退出钱将清零\n"); scanf("%d",&again); if(again==0) { printf("\n\n"); return main(); } if(again==1) return 0; }比较好玩,但后期无趣。推荐程度:💎💎💎
#include<bits/stdc++.h> #include<windows.h> #include<conio.h> using namespace std; const int daytime=0,night=1; int day=0, during_time=daytime, player_number, my_number; HWND hwnd=GetForegroundWindow(); const int blue=0,yellow=1,red=2,green=3,purple=4,white=5;//颜色常量 void color(int c){ switch(c){ case red:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);break; case green:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);break; case yellow:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);break; case blue:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);break; case white:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);break; case purple:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_BLUE);break; } } int idx_police=-1; void gotoxy(int x,int y){ COORD position; position.X=x; position.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position); } void init_Show_Window(){ system("mode con lines=60 cols=188"); ShowWindow(hwnd,SW_MAXIMIZE);//窗口最大化 DeleteMenu(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_BYCOMMAND); DrawMenuBar(GetConsoleWindow());//删除×字符 } /*玩家类*/ const int nvwu=0,cunmin=1,yuyanjia=2,langren=3,lieren=4,shouwei=5,good=6,die=1,life=2; class player{ public: int type; int die_or_life; int how(){ return die_or_life; } int is_light;//是否已经公布 int killer; }; player players[1000]; /*转换白天模式*/ void change_daytime(){ during_time=daytime; day++; } /*转换黑夜模式*/ void change_night(){ during_time=night; } int nnvwu=0,ncunmin=0,nyuyanjia=0,nlangren=0,nlieren=0,nshouwei=0; int idxnvwu,idxshouwei,idxyuyanjia,idxlieren,idxlangren[4]={-1,-1,-1,-1}; /*b是否在Arr中*/ bool is_include(int arr[],int b,int l){ for(int i=0;i<l;i++){ if(arr[i]==b) return true; } return false; } /*初始化人数*/ void init_players(){ my_number=rand()%player_number; if(player_number==12) nlangren=4; else if(player_number>=10) nlangren=3; else nlangren=2; for(int i=0;i<player_number;i++) { players[i].die_or_life=life; players[i].is_light=0; players[i].type=-1; players[i].killer=2147483647; } for(int i=0;i<nlangren;i++) { int p=rand()%player_number; if(!is_include(idxlangren,p,4)) idxlangren[i]=p,players[p].type=langren; else i--; Sleep(rand()%80+100); } if(player_number==12) { do{ idxshouwei=rand()%player_number; }while(players[idxshouwei].type!=-1); players[idxshouwei].type=shouwei; } do{ idxnvwu=rand()%player_number; }while(players[idxnvwu].type!=-1); players[idxnvwu].type=nvwu; if(player_number>=10) { do{ idxlieren=rand()%player_number; }while(players[idxlieren].type!=-1); players[idxlieren].type=lieren; } do{ idxyuyanjia=rand()%player_number; }while(players[idxyuyanjia].type!=-1); players[idxyuyanjia].type=yuyanjia; for(int i=0;i<player_number;i++) if(players[i].type==-1) players[i].type=cunmin, ncunmin++; if(players[my_number].type==langren) { for(int i=0;i<nlangren;i++) { players[idxlangren[i]].is_light=1; } } players[my_number].is_light=1; } /*在屏幕上打印东西*/ void print(){ gotoxy(0,0); cout<<"作者:洛谷393864"; gotoxy(90,0); if(during_time==night) color(red); else color(blue); printf("第%d天 | ",day); if(during_time==night) cout<<"黑夜"; else cout<<"白天"; gotoxy(0,3); color(blue); cout<<" 我的号位:"<<my_number+1; for(int i=0;i<player_number;i++){ gotoxy(i*8+1,4); if(i==idx_police) color(yellow); else color(blue); cout<<i+1<<"号位"; gotoxy(i*8+1,5); if(players[i].how()==die){ color(red); cout<<"死 亡"; }else{ color(green); cout<<"存 活"; } gotoxy(i*8+1,6); color(blue); if(players[i].is_light){ if(players[i].is_light==1){ switch(players[i].type){ case nvwu: cout<<"女 巫";break; case yuyanjia: cout<<"\b预言家";break; case cunmin: cout<<"村 民";break; case langren:cout<<"狼 人"; break; case lieren:cout<<"猎 人"; break; case shouwei:cout<<"守 卫"; break; } }else{ cout<<"好人"; } }else{ cout<<"未知"; } } } /*判断是否结束,没结束返回0 好人胜利返回1 狼人胜利返回2 平局返回3*/ int is_end(){ int die_bad=0; int die_people=0; int die_god=0; for(int i=0;i<player_number;i++){ if((players[i].type == nvwu || players[i].type == yuyanjia || players[i].type == shouwei)&&players[i].die_or_life==die) die_god++; else if(players[i].type == langren && players[i].die_or_life==die) die_bad++; else if(players[i].type == cunmin && players[i].die_or_life==die) die_people++; } if((die_bad==die_people || die_bad==die_god)&&(die_bad>=nlangren)) return 3; if(die_bad>=nlangren) return 1; if(die_people>=ncunmin||die_god>=(player_number>=10 ? 3:2)) return 2; return 0; } /*游戏开始前的骚操作*/ void before_game(){ srand(time(NULL)); init_Show_Window(); color(green); cout<<"欢迎来到狼人杀游戏\t\t\t为了更好的游戏体验,请右键点击上方↑↑,点击\"属性\",点击\"字体\"栏目,将字体修改为宋体或新宋体,将字号改为20\n作者:洛谷393864\n请勿私自转载,违者依法追究法律责任 注:10 11 12人局开设猎人 12人局开设守卫警长\n______________________\n"; cout<<"请输入玩家人数(8-12人):"; cin>>player_number; while(player_number<8||player_number>12) { cout<<"请重新输入!\n"; cin>>player_number; } system("cls"); cout<<"初始化身份中,请稍等."; for(int i=0;i<6;i++){ for(int j=0;j<12;j++){ cout<<"."; Sleep(50); } cout<<"\b\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b\b"; } system("cls"); init_players(); cout<<"我的号位:"<<my_number+1<<endl <<"我的身份:"; switch(players[my_number].type){ case nvwu: cout<<"女巫\n";break; case yuyanjia: cout<<"预言家\n";break; case cunmin: cout<<"村民\n";break; case langren:cout<<"狼人\n";break; case lieren:cout<<"猎人\n"; break; case shouwei:cout<<"守卫\n";break; } change_daytime(); system("pause"); system("cls"); cout<<"游戏加载中.";int ppppp=rand()%3+2; for(int i=0;i<ppppp;i++){ for(int j=0;j<6;j++){ cout<<"."; Sleep(rand()%100+150); } cout<<"\b\b\b\b\b\b \b\b\b\b\b\b"; } print(); } /*每一天开始前的操作*/ void something_before_everyday(){ change_night(); system("cls"); print(); gotoxy(0,7); cout<<"________________________"; gotoxy(0,8); color(white); cout<<"天黑~请闭眼~~~\n"; } /*守卫操作*/ int shouweishou=0; int ShouWei(){ color(blue); cout<<"守卫~请睁眼~~\n"; Sleep(1500); cout<<"你要守护的是?\n"; if(players[my_number].type==shouwei&&players[my_number].die_or_life == life){ cin>>shouweishou; while(!(shouweishou>=1&&shouweishou<=player_number&&players[shouweishou-1].die_or_life == life)){ cout<<"请重新输入!\n"; cin>>shouweishou; } cout<<"你今晚要守护的是"<<shouweishou<<"号\n"; Sleep(1500); shouweishou--; }else{ if(players[idxshouwei].die_or_life == life){ shouweishou=rand()%10; while(!(shouweishou>=1&&shouweishou<=player_number&&players[shouweishou-1].die_or_life == life)){ shouweishou=rand()%10; } } } Sleep(2000); cout<<"守卫请闭眼"<<endl<<endl; return shouweishou; } /*狼人操作*/ int LangRen(){ int langrensha=-1; color(red); cout<<"狼人~请睁眼~~~\n"; Sleep(1500); cout<<"你们今晚要杀~谁~~??\n"; if(players[my_number].type==langren&&players[my_number].die_or_life == life){ cin>>langrensha; while(!(langrensha>=1&&langrensha<=player_number&&players[langrensha-1].die_or_life==life)){ cout<<"请重新输入!\n"; cin>>langrensha; } cout<<"你们今晚要杀的是"<<langrensha--<<"号\n"; Sleep(3500); }else{ while(langrensha==-1 || players[langrensha].die_or_life == die || players[langrensha].type==langren){ langrensha=rand()%player_number; } Sleep(3000); } cout<<"狼人请~闭眼~~\n\n"; return langrensha; } /*女巫操作*/ int nvwujiu=0,nvwudu=0,is_nvwujiu=0,is_nvwudu=0; int NvWu(int langrensha){ color(purple); cout<<"女巫~~请睁眼~~\n"; Sleep(2000); if(players[my_number].type==nvwu&&players[my_number].die_or_life == life){ if(is_nvwujiu) cout<<"你已经用过解药\n",Sleep(1500); else { cout<<"今晚"<<langrensha+1<<"号死了,你想用解药吗?(1想 / 2不想)\n"; int is_nvwujie=0; cin>>is_nvwujie; while(is_nvwujie!=1&&is_nvwujie!=2){ cout<<"请重新输入\n"; cin>>is_nvwujie; } if(is_nvwujie==1) { Sleep(1000); cout<<"已经解救"<<langrensha+1<<"号\n"; nvwujiu=langrensha; } is_nvwujiu=1; } Sleep(1500); if(::is_nvwudu) cout<<"你已经用过解药\n",Sleep(1500); else { cout<<"你想用毒药吗?(1想 / 2不想)\n"; Sleep(1500); int is_nvwudu=0; cin>>is_nvwudu; while(is_nvwudu!=1&&is_nvwudu!=2){ cout<<"请重新输入\n"; cin>>is_nvwudu; } if(is_nvwudu==1){ Sleep(1500); cout<<"你想毒谁?\n"; cin>>nvwudu; while(!(nvwudu>=1&&nvwudu<=player_number&&players[nvwudu].die_or_life==life)){ cout<<"请重新输入\n"; cin>>nvwudu; } nvwudu--; Sleep(1500); cout<<"已经毒死了"<<nvwudu+1<<"号\n"; } ::is_nvwudu=1; } }else{ if(players[idxnvwu].die_or_life == life){ if(!is_nvwujiu) { int is_jiu=rand()%8; if(is_jiu==0){ nvwujiu=langrensha; is_nvwujiu=1; } } if(!is_nvwudu) { int is_du=rand()%4; if(is_du==0){ int num=rand()%player_number; nvwudu=num; is_nvwudu=1; } } } } cout<<"女巫~请闭眼~~\n\n"; return nvwujiu*10000+nvwudu;//传回两个变量,“加密”操作 } int yuyanjiabixutoupiao=-1; /*预言家操作*/ void YuYanJia(){ color(green); cout<<"预言家~请睁眼~~\n"; Sleep(2000); if(players[my_number].type==yuyanjia&&players[my_number].die_or_life == life){ cout<<"请问你想查验谁的身份\n"; int p; cin>>p; while(!(p>=1&&p<=player_number)){ cout<<"请重新输入!\n"; cin>>p; } Sleep(2000); cout<<p<<"号的身份是——"; Sleep(1000); if(players[p-1].type == langren){ cout<<"狼人\n"; players[p-1].is_light = 1; }else{ cout<<"好人\n"; players[p-1].is_light = 2; } }else{ int p=-1; while(p==-1||players[p].die_or_life==die||p==idxlieren) p=rand()%player_number; if(players[p].type==langren)//锁定目标! { yuyanjiabixutoupiao=p; } } cout<<"预言家~~请闭眼~~\n"; } /*黑夜操作*/ int LANGRENSHA=-1,NVWUDU=-1,NVWUJIU=-1,SHOUWEISHOU=-1; void Night(){ LANGRENSHA=-1,NVWUDU=-1,NVWUJIU=-1,SHOUWEISHOU=-1; //如果有12人局,添加守卫 if(player_number==12){ SHOUWEISHOU=ShouWei(); Sleep(2000); } /*狼人部分*/ LANGRENSHA=LangRen(); Sleep(3500); /*女巫部分*/ int nvwu=NvWu(LANGRENSHA); NVWUDU=nvwu%10+nvwu/10%10; NVWUJIU=nvwu/10000%10+nvwu/100000%10; Sleep(3000); /*预言家部分*/ YuYanJia(); Sleep(2000); } /*猎人操作*/ void Lieren(){ int lierendai=-1; cout<<idxlieren+1<<"号是猎人\n"; players[idxlieren].is_light = 1; Sleep(1000); if(idxlieren==my_number){ cout<<"你想带走几号?\n"; cin>>lierendai; while(lierendai<1||lierendai>player_number||players[lierendai].die_or_life==die){ cout<<"请重新输入!\n"; cin>>lierendai; } lierendai--; }else{ lierendai=rand()%player_number; while(players[lierendai].die_or_life == die){ lierendai=rand()%player_number; } } Sleep(2000); cout<<"猎人选择带走"<<lierendai+1<<"号\n"; Sleep(2000); players[lierendai].die_or_life = die; } void police_die(); /*判断谁死了*/ void panduansiwang(){ system("cls"); print(); gotoxy(0,7); cout<<"________________________\n"; Sleep(3000); color(white); cout<<"天亮了\n"; Sleep(2000); gotoxy(0,9); cout<<"昨晚"; bool is_die[15]={false},is_die_lieren=false,flag=false; for(int i=0;i<player_number;i++) { if(players[i].die_or_life==life) { if(i==LANGRENSHA||i==NVWUDU) { if(players[i].type==lieren) is_die_lieren=true; players[i].killer= (i==LANGRENSHA ? langren:nvwu); players[i].die_or_life=die; is_die[i]=true; } if(i==SHOUWEISHOU||i==NVWUJIU) { if(players[i].type==lieren) is_die_lieren=false; players[i].killer=-1; players[i].die_or_life=life; is_die[i]=false; } } } bool is_police_die=false; for(int i=0;i<player_number;i++) { if(is_die[i]) { if(flag) cout<<"和"<<i+1<<"号"; else cout<<i+1<<"号",flag=true; if(i==idx_police) is_police_die=true; } } if(flag) cout<<"死了\n"; else cout<<"是平安夜\n"; if(is_die_lieren) Lieren(); if(is_police_die) police_die(); } /*选警长*/ void choose_police(){ system("cls"); print(); color(blue); gotoxy(0,7); cout<<"________________________\n"; color(yellow); cout<<"下面开始选举警长,各位不能选举自己~\n"; int tong[100]={0},cannot[100],must[100]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; memset(cannot,-1,sizeof(cannot)); CHOOSE: color(yellow); Sleep(1500); for(int i=0;i<player_number;i++) { if(players[i].die_or_life==life&&!is_include(cannot,i,player_number)) { if(i==my_number) { cout<<"你要选举几号?\n"; int n; cin>>n; while(n<1||n>player_number||n==i+1||players[n-1].die_or_life==die||!is_include(must,n-1,player_number)) { cout<<"请重新输入!\n"; cin>>n; } cout<<i+1<<"号选举"<<n--<<"号\n"; tong[n]++; } else { int n=rand()%player_number; while(n==i||players[n].die_or_life==die||!is_include(must,n,player_number)) n=rand()%player_number; cout<<i+1<<"号选举"<<n+1<<"号\n"; tong[n]++; } Sleep(1500); } } int idx_max=-1,maxn=-1,len=0; for(int i=0;i<player_number;i++) if(maxn<tong[i]) { maxn=tong[i]; idx_max=i; } int maxn_arr[15]={0}; for(int i=0;i<player_number;i++) { if(tong[i]==maxn) { maxn_arr[len++]=i; } } color(blue); if(len>1) { for(int i=0;i<len;i++) { if(i==len-1) { cout<<maxn_arr[i]+1<<"号平票\n"; } else { cout<<maxn_arr[i]+1<<"号,"; } } for(int i=0;i<len;i++) cannot[i]=maxn_arr[i]; for(int i=0;i<player_number;i++) { if(is_include(cannot,i,len)) must[i]=i; else must[i]=-1; } color(white); goto CHOOSE; } cout<<"恭喜"<<idx_max+1<<"号当选警长\n"; Sleep(3000); idx_police=idx_max; return; } /*投票*/ int toupiao(){ int tong[100]={0},cannot[100]={},must[100]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; memset(cannot,-1,sizeof(cannot)); gotoxy(0,7); color(blue); cout<<"________________________\n"; color(white); cout<<"下面进入投票环节\n"; memset(tong,0,sizeof(tong)); Sleep(2000); TOUPIAO: for(int i=0;i<player_number;i++){ if(players[i].die_or_life == life&&!is_include(cannot,i,player_number)){ if(i==my_number){ color(white); cout<<"你要投几号?\n"; int n; cin>>n; while(!(n>=1&&n<=player_number&&is_include(must,n-1,player_number))){ cout<<"请重新输入!\n"; cin>>n; } Sleep(2000); cout<<setw(2)<<my_number+1<<"号投了"<<setw(2)<<n<<"号"; if(my_number==n-1) color(red),cout<<"快来看!这有个疯子投自己!"; if(i==idx_police) color(yellow),cout<<"(警长)\n"; else cout<<"\n"; if(i==idx_police) tong[n-1]++; tong[n-1]++; }else{ color(white); int t=-1; while(t==-1 || players[t].die_or_life == die || t==i || !is_include(must,t,player_number)){ if(i==idxyuyanjia&&yuyanjiabixutoupiao!=-1) { t=yuyanjiabixutoupiao; yuyanjiabixutoupiao=-1; continue; } t=rand()%player_number; if(is_include(idxlangren,i,nlangren)) { if(players[t].type == langren) t=-1; } } cout<<setw(2)<<i+1<<"号"<<"投了"<<setw(2)<<t+1<<"号"; if(i==idx_police) cout<<"(警长2票)\n"; else cout<<"\n"; if(i==idx_police) tong[t]++; tong[t]++; } Sleep(rand()%1000+1000); } } int idx_max=-1,maxn=-1,len=0; for(int i=0;i<player_number;i++) if(maxn<tong[i]) { maxn=tong[i]; idx_max=i; } int maxn_arr[15]={0}; for(int i=0;i<player_number;i++) { if(tong[i]==maxn) { maxn_arr[len++]=i; } } color(blue); if(len>1) { for(int i=0;i<len;i++) { if(i==len-1) { cout<<maxn_arr[i]+1<<"号平票\n"; } else { cout<<maxn_arr[i]+1<<"号,"; } } for(int i=0;i<len;i++) cannot[i]=maxn_arr[i]; for(int i=0;i<player_number;i++) { if(is_include(cannot,i,len)) must[i]=i; else must[i]=-1; } color(white); goto TOUPIAO; } cout<<idx_max+1<<"号"<<"出局\n"; Sleep(4000); players[idx_max].die_or_life = die; players[idx_max].killer = good; return idx_max; } /*警长死亡*/ void police_die(){ color(yellow); int type; if(idx_police==my_number) { Sleep(1550); cout<<"你是想撕毁警徽还是移交警徽?(撕毁输入1,移交输入2)"; cin>>type; while(!(type==1||type==2)) { cout<<"请重新输入!\n"; cin>>type; } } else{ type=rand()%3+1; } if(type==1) { cout<<"警长选择撕毁警徽\n"; Sleep(1000); idx_police=-1; } else { int lucky=-1; while(lucky==-1||players[lucky].die_or_life==die) lucky=rand()%player_number; cout<<"警长选择把警徽移交给"<<lucky+1<<"号\n"; Sleep(1500); idx_police=lucky; } } /*故事的最后*/ void the_end(){ system("cls"); switch(is_end()){ case 1:cout<<"好人胜利\n\n"; break; case 2:cout<<"狼人胜利\n\n"; break; case 3:cout<<"本局平局\n\n"; break; } for(int i=0;i<player_number;i++){ cout<<i+1<<"号位:\t"; switch(players[i].type){ case nvwu: cout<<"女巫\t";break; case yuyanjia: cout<<"预言家\t";break; case cunmin: cout<<"村民\t";break; case langren:cout<<"狼人\t";break; case lieren:cout<<"猎人\t"; break; case shouwei:cout<<"守卫\t";break; } cout<<"最终"; switch(players[i].killer){ case nvwu:cout<<"被女巫毒死\n"; break; case langren:cout<<"被狼人杀死\n"; break; case good:cout<<"被投票出局\n"; break; case lieren:cout<<"被猎人带走\n";break; default :cout<<"存活\n"; } cout<<endl; } } /*主函数*/ int main(){ int wheel=0; before_game(); while(!is_end()){ //黑夜准备 something_before_everyday(); Sleep(1500); //黑夜部分 Night(); //进入黑夜! change_daytime(); //换天 //天亮了 panduansiwang();//判断谁死了 Sleep(2000); system("cls"); print(); if(is_end()) break; //选警长 if(!wheel&&player_number==12) { choose_police(); system("cls"); print(); } //投票环节 int idx_max=toupiao();//票数最多的人 if(idx_max==idx_police){ police_die(); } if(players[idx_max].type==lieren){//启动猎人程序 Lieren(); if(is_end()) break; } system("cls"); print(); wheel++; } the_end(); system("pause"); return 0; }有点入机,推荐指数💎💎💎
//愤怒的小鸟 #include <bits/stdc++.h> #include <windows.h> #include <stdio.h> #include <conio.h> #include <time.h> using namespace std; const double pi = 3.1415926536; int toint (float a) { return ((int) (a * 10 + 5)) / 10; } void Color (int a) { if (a == 0 || a == 14 || a == 20) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); else if (a == 1 || a == 12) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE); else if (a == 2) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN); else if (a == 3) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); else if (a == 4 || a == 11) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED); else if (a == 5 || a == 13) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); else if (a == 6) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_BLUE); else if (a == 7) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_GREEN | FOREGROUND_BLUE); else if (a == 8) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); else if (a == 9) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | BACKGROUND_RED | BACKGROUND_GREEN); else if (a == 15) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY); else if (a == 16) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_GREEN); else if (a == 17) SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED); } void SetPos (float x, float y) { int xx = toint (x), yy = toint (y); COORD pos; pos.X = yy * 2; pos.Y = xx; SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), pos); } struct node { int W, W2, S, mS; float X, Y; float vx, vy; float ax, ay; bool go, boom; } blt[100001], pig[100001], boo[100001]; int T, yX, yY, Xy, put, K, K2, Sle, What,Bot, Pit, Blt, Pig, Sco, pigk, scok,m[41][41]; void Cout (int a, int x, int y) { if (a == 1) { SetPos (x, y); Color (5); cout << put << ' '; } if (y == 202) { SetPos (pig[a].X, pig[a].Y); cout << " "; if ((pig[a].W == 2 || pig[a].W == 3) && pig[a].X >= 2) { SetPos (pig[a].X - 2, pig[a].Y); cout << " "; SetPos (pig[a].X - 1, pig[a].Y); cout << " "; } else if (pig[a].W == 4) { SetPos (pig[a].X, pig[a].Y - 1); cout << " "; } else if (pig[a].W == 5) { SetPos (pig[a].X - 1, pig[a].Y); cout << " "; SetPos (pig[a].X - 1, pig[a].Y - 1); cout << " "; } } if (a == 2) { for (int i = 0; i <= 40; i++) { for (int j = 0; j <= 40; j++) { if (i <= 18 && m[i][j] == 1) { SetPos (i, j); Color (7); cout << "■"; } if (m[i][j] >= 2 && m[i][j] <= 19) { SetPos (i, j); Color (5); cout << "█"; m[i][j]++; } if (m[i][j] > 19 && m[i][j] <= 29) { SetPos (i, j); Color (0); cout << "█"; m[i][j]++; if (m[i][j] == 30) { SetPos (i, j); Color (0); cout << " "; m[i][j] = 0; } if (m[i][j] >= 31 && m[i][j] <= 49) { SetPos (i, j); Color (0); cout << "■"; m[i][j]++; } if (m[i][j] == 50) { SetPos (i, j); Color (7); cout << "■"; m[i][j] = 1; } } } } } if (y == 666) { SetPos (blt[a].X, blt[a].Y); Color (10 + blt[a].W); cout << "●"; } Color (0); } void Go (int a) { SetPos (blt[a].X, blt[a].Y); cout << " "; blt[a].X += blt[a].vx / 2; blt[a].Y += blt[a].vy / 2; blt[a].vx += blt[a].ax / 2; blt[a].vy += blt[a].ay / 2; if (blt[a].X >= 20) blt[a].X = 19; if (blt[a].X > 20 || blt[a].Y > 38 || blt[a].X < 0 || blt[a].Y <= 0) blt[a].go = 1; if (blt[a].W2 == 1 && blt[a].Y >= Xy) { blt[a].go = 1; Sle = 0; } if (blt[a].W2 == 0) { for (int i = 0; i <= blt[a].vx / 2 + 1; i++) { if (blt[a].vx > 0 && m[toint (blt[a].X) + i][toint (blt[a].Y)] == 1) { if (blt[a].W != 5) blt[a].boom = 1; blt[a].X = toint (blt[a].X) + i - 1; blt[a].Y += blt[a].vy / 2; blt[a].vx = -blt[a].vx * 0.4; blt[a].vy = blt[a].vy * 0.8; if (blt[a].W == 3) blt[a].ax = 0.5; if (blt[a].W == 7) blt[a].vx *= 2; if (blt[a].W == 10) { blt[a].go = 1; Bot++; boo[Bot].X = blt[a].X; boo[Bot].Y = blt[a].Y; boo[Bot].S = 1; boo[Bot].mS = 4; } } if (blt[a].vx < 0 && m[toint (blt[a].X) - i][toint(blt[a].Y)] == 1) { if (blt[a].W != 5) blt[a].boom = 1; blt[a].X = toint (blt[a].X) + i + 1; blt[a].Y += blt[a].vy / 2; blt[a].vx = -blt[a].vx; blt[a].vy = blt[a].vy * 0.8; if (blt[a].W == 3) blt[a].ax = 0.5; if (blt[a].W == 7) blt[a].vx *= 2; if (blt[a].W == 10) { blt[a].go = 1; Bot++; boo[Bot].X = blt[a].X; boo[Bot].Y = blt[a].Y; boo[Bot].S = 1; boo[Bot].mS = 4; } } } if (abs (blt[a].vx) <= 0.1 && abs (blt[a].vy) <= 0.1 && abs (blt[a].ay) <= 0.1) { blt[a].go = 1; if (blt[a].W == 5) { Bot++; boo[Bot].X = blt[a].X; boo[Bot].Y = blt[a].Y; boo[Bot].S = 1; boo[Bot].mS = 4; blt[a].go = 1; } } } if (blt[a].go == 0) Cout (a, 0, 666); } void Kill (int a) { if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) { Cout (a, 202, 202); pig[a].Y = 16; } if (pig[a].go == 0 && pig[a].W == 4 && pig[a].Y < 20) pig[a].W = 1; int R = rand () % 50; Cout (a, 202, 202); pig[a].X += pig[a].vx / 2; pig[a].Y += pig[a].vy / 2; pig[a].vx += pig[a].ax / 2; pig[a].vy += pig[a].ay / 2; for (int i = -2; i <= pig[a].vx / 2 + 1; i++) if (m[toint (pig[a].X) + i][toint (pig[a].Y)] == 1) { pig[a].X = toint (pig[a].X) + i - 1; pig[a].Y += pig[a].vy / 2; pig[a].vx = -pig[a].vx * 0.5; pig[a].vy = pig[a].vy * 0.8; } for (int i = Blt - 10; i <= Blt; i++) { if (pig[a].W == 5 && blt[i].go == 0 && abs (pig[a].X - blt[i].X) <= 1&& abs (pig[a].Y - blt[i].Y) <= 1) { m[toint (pig[a].X) - 1][toint (pig[a].Y)] = 2; pig[a].W2++; Sco += 2; break; } if (pig[a].W == 5 && m[toint (pig[a].X)][toint (pig[a].Y)] >= 2 &&m[toint (pig[a].X)][toint (pig[a].Y)] < 30) { m[toint (pig[a].X) - 1][toint (pig[a].Y)] = 2; pig[a].W2++; Sco += 2; break; } if (blt[i].go == 0 && abs (pig[a].X - blt[i].X) <= 1 && abs (pig[a].Y - blt[i].Y) <= 1) { if (pig[a].W == 6) { Bot++; boo[Bot].X = pig[a].X; boo[Bot].Y = pig[a].Y; boo[Bot].S = 1; boo[Bot].mS = 4; blt[i].go = 1; } m[toint (pig[a].X)][toint (pig[a].Y)] = 2; pig[a].go = 1; Pig--; Sco += 10; break; } if (m[toint (pig[a].X)][toint (pig[a].Y)] >= 2 && m[toint (pig[a].X)][toint (pig[a].Y)] < 30) { if (pig[a].W == 6) { Bot++; boo[Bot].X = pig[a].X; boo[Bot].Y = pig[a].Y; boo[Bot].S = 1; boo[Bot].mS = 4; } pig[a].go = 1; Pig--; Sco += 10; break; } if ((pig[a].W == 2 || pig[a].W == 3) && blt[i].go == 0 &&abs (pig[a].X - 2 - blt[i].X) <= 1 && abs (pig[a].Y - blt[i].Y) <= 1) { m[toint (pig[a].X)][toint (pig[a].Y)] = 2; pig[a].go = 1; Pig--; Sco += 10; break; } if ((pig[a].W == 2 || pig[a].W == 3) &&m[toint (pig[a].X - 2)][toint (pig[a].Y)] >= 2&& m[toint (pig[a].X - 2)][toint (pig[a].Y)] < 30) { pig[a].go = 1; Pig--; Sco += 10; break; } } if (pig[a].go == 0) { if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) { Cout (a, 202, 202); pig[a].Y = 16; } if (pig[a].go == 0 && pig[a].W == 4 && pig[a].Y < 20) pig[a].W = 1; int Xx = toint (pig[a].X), Xy = toint (pig[a].Y); if (pig[a].W == 6) { SetPos (pig[a].X, pig[a].Y); Color (9); cout << "TN"; Color (0); } else { SetPos (pig[a].X, pig[a].Y); Color (2); cout << "●"; if ((pig[a].W == 2 || pig[a].W == 3) && pig[a].X >= 2) { SetPos (pig[a].X - 2, pig[a].Y); Color (0); cout << "○"; SetPos (pig[a].X - 1, pig[a].Y); cout << "|"; } else if (pig[a].W == 4) { SetPos (pig[a].X, pig[a].Y - 1); Color (2); cout << "﹃"; } else if (pig[a].W == 5) { SetPos (pig[a].X - 1, pig[a].Y); Color (8); SetPos (pig[a].X - 1, pig[a].Y - 1); cout << "▁"; if (pig[a].W2 == 0) cout << "▅"; else if (pig[a].W2 == 1) cout << "▃"; else if (pig[a].W2 == 2) cout << "▂"; else if (pig[a].W2 == 3) { pig[a].W = 1; pig[a].W2 = 0; SetPos (pig[a].X - 1, pig[a].Y - 1); cout << " "; } } } if (pig[a].W == 2 && pig[a].X > pig[a].S) { pig[a].W = 3; pig[a].ax = -0.4; pig[a].vx = 1.5; } else if (pig[a].W == 3 && pig[a].X <= pig[a].S) { pig[a].W = 2; pig[a].ax = 0.4; pig[a].vx = -1.5; } if ((pig[a].W == 2 || pig[a].W == 3) && (pig[a].Y <= 10 || pig[a].Y >= 38)) pig[a].vy *= -1; if (pig[a].W == 4 && R == 0 && pig[a].X == 20) pig[a].vx = -((rand () % 40) / 10); if (pig[a].W == 4) { int r = rand () % 20; for (int i = Blt - 10; i <= Blt; i++) if (r <= 5 && blt[i].go == 0 && pig[a].Y - blt[i].Y <= 5 &&abs (blt[i].X - pig[a].X) <= 1.5 && r < 5) { r = 0; break; } if (r == 0) { m[toint (pig[a].X)][toint (pig[a].Y) - 2] = 10; m[toint (pig[a].X)][toint (pig[a].Y) - 3] = 2; for (int j = toint (pig[a].Y) - 1; j >= toint (pig[a].Y) - 5; j--) { for (int i = Blt - 10; i <= Blt; i++) if (blt[i].go == 0 && !(blt[i].W == 3 && blt[i].boom == 1)&& blt[i].W2 == 0 && toint (blt[i].Y) == j&& abs (blt[i].X - pig[a].X) <= 2) blt[i].vy = -2; for (int i = Pit - 50; i <= Pit; i++) if (pig[i].go == 0 && toint (pig[i].Y) == j && abs (pig[i].X - pig[a].X) <= 2) pig[i].vy = -1; } } } if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) { Cout (a, 202, 202); pig[a].Y = 16; } if (pig[a].go == 0 && pig[a].W == 4 && pig[a].Y < 20) pig[a].W = 1; if (pig[a].X > 20 || pig[a].Y > 38 || pig[a].X < 0 || pig[a].Y <= 0) { pig[a].go = 1; Pig--; Cout (a, 202, 202); } } } void Creat (int a, int p) { if (a == -1 && p == -1) { Blt++; blt[Blt].W = What; blt[Blt].W2 = 1; blt[Blt].vy = 1; blt[Blt].X = 19; blt[Blt].Y = 0; blt[Blt].boom = 1; } else if (a == 0 && p == -1) { int u = rand () % 7 + 1, U = rand() % 30; if (u >= 5) { Pit++; pig[Pit].Y = rand () % 15 + 20; pig[Pit].X = 2; pig[Pit].ax = 0.5; pig[Pit].W = 1; } else if (u == 1) { Pit++; pig[Pit].Y = rand () % 15 + 20; pig[Pit].X = 2; pig[Pit].vy = 0.5; pig[Pit].ax = 0.5; pig[Pit].S = rand () % 5 + 7; pig[Pit].W = 2; } else if (u == 2) { Pit++; pig[Pit].Y = rand () % 15 + 20; pig[Pit].X = 2; pig[Pit].ax = 0.5; pig[Pit].W = 4; } else if (u == 3) { Pit++; pig[Pit].Y = rand () % 15 + 20; pig[Pit].X = 2; pig[Pit].ax = 0.5; pig[Pit].W = 5; } else if (u == 4) { Pit++; pig[Pit].Y = rand () % 15 + 20; pig[Pit].X = 2; pig[Pit].ax = 0.5; pig[Pit].W = 6; } if (U == 1) { Bot++; boo[Bot].Y = rand () % 13 + 15; boo[Bot].X = (rand () % 4) * 3 + 8; boo[Bot].S = 0; boo[Bot].mS = rand () % 2 + 2; boo[Bot].W2 = 1; } } else { Blt++; blt[Blt].W = What; if (a == 1) { blt[Blt].X = yX; blt[Blt].Y = yY; blt[Blt].ax = 0.5; } blt[Blt].vx = -3.5 * sin (p * pi / 180); blt[Blt].vy = 3 * cos (p * pi / 180); if (p <= 45) blt[Blt].vy *= 1 + (0.33 - 0.01 * (45 - p)); if (p >= 45) blt[Blt].vy *= 1 + (0.33 - 0.01 * (p - 45)); if (blt[Blt].W == 6) { blt[Blt].vy *= 1.2; blt[Blt].ax = 0.4; } } } void Boom (int a) { if (boo[a].W2 == 0) { int ms = boo[a].mS, s = boo[a].S, x = boo[a].X, y = boo[a].Y; if (s == ms) return ; for (int i = x - s; i <= x + s; i++) for (int j = y - s; j <= y + s; j++) { float k = (i - x) * (i - x) + (j - y) * (j - y) - s * s; if (k <= s && k >= -s && i <= 20 && j <= 38 && i >= 0 && j > 0 && m[i][j] != 1) m[i][j] = 2; } boo[a].S++; } if (boo[a].W2 == 1) { int ms = boo[a].mS, s = boo[a].S, x = boo[a].X, y = boo[a].Y; if (s == ms) return ; if (y - s > 10) m[x][y - s] = 31 - 31 * (boo[a].W2 - 1); if (y + s < 40) m[x][y + s] = 31 - 31 * (boo[a].W2 - 1); boo[a].S++; } } void Move (int a) { Color (5); if (a == -2) { SetPos (17, Xy); cout << " "; SetPos (18, Xy); cout << " "; SetPos (19, Xy); cout << " "; SetPos (20, Xy); cout << " "; } if (a == -1) { SetPos (17, Xy); cout << " "; SetPos (18, Xy); cout << " ┃ ┃"; SetPos (19, Xy); cout << " ╰┳╯"; SetPos (20, Xy); cout << " ▏"; } if (a == 0) { SetPos (18, Xy); cout << " ┃"; Color (What + 10); cout << "●"; Color (5); cout << "┃"; SetPos (19, Xy); cout << " ╰┳╯"; SetPos (20, Xy); cout << " ▏"; } if (a == 1) { SetPos (18, Xy); cout << " "; Color (What + 10); cout << "●"; Color (5); cout << " ┃"; SetPos (19, Xy); cout << " ╰┳╯"; SetPos (20, Xy); cout << " ▏"; } if (a == 2) { SetPos (18, Xy); Color (What + 10); cout << "●"; Color (5); cout << "┃ ┃"; SetPos (19, Xy); cout << " ╰┳╯"; SetPos (20, Xy); cout << " ▏"; } if (a == 3) { SetPos (18, Xy); cout << " ┃ ┃"; SetPos (19, Xy); Color (What + 10); cout << "●"; Color (5); cout << "╰┳╯"; SetPos (20, Xy); cout << " ▏"; } if (a == 4) { SetPos (18, Xy); cout << " ┃ ┃"; SetPos (19, Xy); cout << " ╰┳╯"; SetPos (20, Xy); Color (What + 10); cout << "●"; Color (5); cout << " ▏"; } if (a == 5) { SetPos (18, Xy); cout << " ┃ ┃"; SetPos (19, Xy); cout << " ╰┳╯"; SetPos (20, Xy); cout << " "; Color (What + 10); cout << "●"; Color (5); cout << " ▏"; } if (a == 6) { SetPos (18, Xy); cout << " ┃ ┃"; SetPos (19, Xy); cout << " ╰┳╯"; SetPos (20, Xy); cout << " "; Color (What + 10); cout << "●"; Color (5); cout << " "; } Color (0); } void Start () { char g; Color (5); system ("cls"); SetPos (1, 1); cout << "------- 愤 怒 的 小 鸟 -------"; Color (0); SetPos (3, 1); cout << "空格瞄准,按X触发小鸟技能,←→移动弹弓"; SetPos (5, 1); cout << "猪猪技能自动触发,空中会有墙出现。"; SetPos (7, 1); cout << "危险值由命中率,猪的存活时间计算!"; SetPos (9, 1); cout << "危险值点满后失败!1500分通关!"; SetPos (1, 20); cout << "-------- 小 鸟 技 能 --------"; SetPos (3, 20); Color (11); cout << "●"; Color (0); cout << ":无技能"; SetPos (5, 20); Color (12); cout << "●"; Color (0); cout << ":分身!不同分身初速度大小相同,"; SetPos(6, 20); cout << " 方向不同。"; SetPos (7, 20); Color (13); cout << "●"; Color (0); cout << ":加速!以当前速度做匀速直线运动,"; SetPos (8, 20); cout << " 且免疫狙击猪的冲击。"; SetPos (9, 20); Color (14); cout << "●"; Color (0); cout << ":投蛋!并获得向上速度做匀速直线"; SetPos (10, 20); cout << " 运动,快达可以穿墙。"; SetPos (11, 20); Color (15); cout << "●"; Color (0); cout << ":爆炸!"; SetPos (13, 20); Color (16); cout << "●"; Color (0); cout << ":回旋!开始做向左加速运动!发射"; SetPos (14, 20); cout << " 时获得双倍水平速度。"; SetPos (15, 20); Color (17); cout << "●"; Color (0); cout << ":[被动] 弹跳力为普通鸟三倍。发射"; SetPos (16, 20); cout << " 时获得1.5倍水平、竖直速度。"; SetPos (11, 1); cout << "-------- 猪 猪 技 能 --------"; SetPos (13, 2); Color (2); cout << "●"; Color (0); cout << ":无技能"; SetPos (14, 1); Color (8); cout << "▁▅"; SetPos (15, 2); Color (2); cout << "●"; Color (0); cout << ":防御力为普通猪三倍"; SetPos (16, 2); cout << "○"; SetPos (17, 2); cout << "│:做空中简谐运动,受死范围"; SetPos (18, 2); Color (2); cout << "●"; Color (0); cout << " 为普通猪两倍。"; SetPos (19, 2); cout << " 有几率跳起或发射冲击波,冲"; SetPos (20, 1); Color (2); cout << "﹃●"; Color (0); cout << ":开小鸟与同类,可以引爆TNT!"; SetPos (18, 20); Color (5); cout << "按 y 开始游戏!"; A: if (kbhit ()) g = _getch (); if (g != 'y') goto A; } int main () { system ("mode con cols=79 lines=22"); CONSOLE_CURSOR_INFO cursor_info = {1, 0}; SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cursor_info); srand ((unsigned)time(NULL)); St: Start (); system ("cls"); memset (blt, 0, sizeof (blt)); memset (pig, 0, sizeof (pig)); memset (boo, 0, sizeof (boo)); memset (m, 0, sizeof (m)); T = put = K = K2 = Sle = What = Pig = Sco = 0; pigk = scok = -1; Xy = 4; yX = 18; yY = 6; Blt = 20; Bot = 20; Pit = 60; Color (7); SetPos (19, 14); cout << "■"; SetPos (20, 13); cout << " █▍"; m[19][14] = m[20][13] = m[20][14] = 1; SetPos (21, 0); for (int i = 0; i < 39; i++) { cout << "■"; m[21][i] = 1; } Color (0); What = rand () % 5 + 1; while (1) { if (Sco >= 1500) break; T++; K = 0; Color (0); if (Sco != scok) { SetPos (1, 1); cout << "分数:" << Sco << ' '; } if (Pig != pigk) { SetPos (3, 1); cout << "危险值:"; int aa = min (Sco / 100, 10); Pig += aa; SetPos (3, 5); if (Pig <= 2) Color (2); else if (Pig <= 4) Color (16); else if (Pig <= 6) Color (7); else if (Pig <= 9) Color (6); else if (Pig <= 12) Color (3); else if (Pig <= 15) Color (17); else Color (11); for (int i = 1; i <= Pig; i++) cout << "■"; Color (0); cout << ' ' << Pig; for (int i = 1; i <= 5; i++) cout << " "; if (Pig > 18) break; Pig -= aa; } scok = Sco; pigk = Pig; if (GetAsyncKeyState (VK_LEFT) & 0x8000 && Xy > 0) { Move (-2); Xy--; K = 1; } if (GetAsyncKeyState (VK_RIGHT) & 0x8000 && Xy < 10) { Move (-2); Xy++; K = 1; } if (K == 1) if (put == 0 && Sle == 0) Move (0); else Move (-1); if (kbhit ()) { char g = _getch (); if (g == 'x' || g == 'X') { for (int i = Blt - 10; i <= Blt; i++) { if (blt[i].go == 0 && blt[i].boom == 0 && blt[i].W != 1 && blt[i].W != 7) { blt[i].boom = 1; if (blt[i].W == 2) { Blt++; blt[Blt].W = 2; blt[Blt].vy = blt[i].vy * 1.2; blt[Blt].vx = blt[i].vx + 1; blt[Blt].ax = blt[i].ax; blt[Blt].X = blt[i].X; blt[Blt].Y = blt[i].Y; blt[Blt].boom = 1; Blt++; blt[Blt].W = 2; blt[Blt].vy = blt[i].vy * 0.7; blt[Blt].vx = blt[i].vx - 1; blt[Blt].ax = blt[i].ax; blt[Blt].X = blt[i].X; blt[Blt].Y = blt[i].Y; blt[Blt].boom = 1; } if (blt[i].W == 3) { blt[i].vy = fmax (blt[i].vy * 1.5, 2.5); blt[Blt].vx++; blt[i].ax = 0; } if (blt[i].W == 4) { blt[i].vx = -3; blt[i].ax = 0.1; Blt++; blt[Blt].boom = 1; blt[Blt].W = 10; blt[Blt].X = blt[i].X; blt[Blt].Y = blt[i].Y; blt[Blt].ax = blt[i].ax; blt[Blt].vx = 1; } if (blt[i].W == 5) { Bot++; boo[Bot].X = blt[i].X; boo[Bot].Y = blt[i].Y; boo[Bot].S = 1; boo[Bot].mS = 5; blt[i].go = 1; } if (blt[i].W == 6) { blt[i].ay = -1; blt[i].ax = 0.3; blt[i].vx = min (blt[i].vx / 2, (float)0); } break; } } } } if (GetAsyncKeyState (' ') & 0x8000 && K == 0 && Sle == 0) { if (put <= 5) { Move (1); yX = 18; yY = Xy + 1; } else if (put <= 20) { Move (2); yX = 18; yY = Xy; } else if (put <= 40) { Move (3); yX = 19; yY = Xy; } else if (put <= 60) { Move (4); yX = 20; yY = Xy; } else if (put <= 80) { Move (5); yX = 20; yY = Xy + 1; } else { Move (6); yX = 20; yY = Xy + 2; } if (put == 0) K2 = 1; if (put == 90) K2 = -1; if (K2 == 1) put += min (rand () % 7 + 1, 90 - put); if (K2 == -1) put -= min(rand() % 7 + 1, put); Cout (1, 17, Xy + 2); } if ((!(GetAsyncKeyState (' ') & 0x8000) && (put != 0)) || (put != 0 && K == 1)) { Move (-1); Creat (1, put); put = 0; yX = 18; yY = 5; Sle = 1; What = rand () % 7 + 1; Creat (-1, -1); Sco = max (Sco - 5, 0); } for (int i = Blt - 10; i <= Blt; i++) if (blt[i].go == 0) Go (i); for (int i = Bot - 10; i <= Bot; i++) if (boo[i].go == 0) { Boom (i); Cout (2, 0, 0); } for (int i = Pit - 50; i <= Pit; i++) if (pig[i].go == 0) Kill (i); if (Sle != 0) Move (-1); else if (put == 0) Move (0); if (T % 300 == 0) { system ("cls"); pigk = scok = -1; } if (T % 100 == 0) { Color (7); for (int i = 0; i <= 18; i++) for (int j = 0; j <= 40; j++) if (m[i][j] == 1 && T % 100 == 0) { SetPos (i, j); cout << "■"; } SetPos (19, 14); cout << "■"; SetPos (20, 13); cout << " █▍"; SetPos (21, 0); for (int i = 0; i < 39; i++) { cout << "■"; Color (0); } } if (T % min (50, (2000 - Sco) / 30) == 0) { Pig++; Creat (0, -1); } Sleep (30); } if (Sco < 100) if (MessageBox (NULL, "很遗憾,您输了,您还想再来一次吗?", "温馨提示", MB_YESNO) == IDYES) goto St; else return 0; else if (MessageBox (NULL, "恭喜您赢了!您还想再来一次吗?", "温馨提示", MB_YESNO) == IDYES) goto St; else return 0; return 0; }强烈推荐!!!非常好玩!推荐指数:💎💎💎💎💎
#include <iostream> #include <list> #include <cstdio> #include <string> #include <vector> #include <ctime> #include <algorithm> #include <conio.h> #include <windows.h> using namespace std; class Node { public: int x, y; Node(int x1, int y1); }; class UserData { public: string name; long long score; int gt; int gr; UserData(string s, long long sc,int gametime,int grade); friend bool operator < (UserData a, UserData b); }; #define RIGHT 0x4d #define LEFT 0x4b #define UP 0x48 #define DOWN 0x50 #define YELLOW FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY #define CYAN FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY #define ORANGE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY #define PURPLE FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY #define RED FOREGROUND_RED | FOREGROUND_INTENSITY const int STARTX = 8; const int STARTY = 4; const int RANGEX = 60; const int RANGEY = 20; int point=10; const int ENDX = STARTX + RANGEX; const int ENDY = STARTY + RANGEY; bool isSnake[RANGEY + 10 ][RANGEX + 10]; int speed; int sysj; int gametime; list<Node> snake; int curDiraction; //蛇的当前前进方向, 1上, 2下, 3左, 4右 int score; //当前分数 int grade; int snakeLen; //蛇的长度 int foodx, foody; //食物坐标 int gox, goy; //蛇头坐标 int mj; void GoTo(short x, short y); //定位光标 void DrawBoard(); //绘制边框 void ShowInformation(); //展示游戏信息 void Init(); //初始化游戏 void RunSnake(int x, int y); //绘制蛇身 void Try(int& x, int& y); //试走 bool IsGoodCoord(int x, int y); //前进坐标是否合法 void AddFood(); void EartFood(); void InitSnake(); bool EndGame(); bool StartGame(); bool GameMenu(); //游戏菜单 void ShowRanking(); //排行榜 void ShowAbout(); //相关信息 void InputData(); //输入玩家名字 int main() { while (true) { if (!GameMenu()) return 0; } return 0; } Node::Node(int x1, int y1) { //构造Node对象 x = x1; y = y1; } int SuiJi() { srand((unsigned)time(NULL)); return (rand()*rand()+rand()*rand())%14; } bool operator < (UserData a, UserData b) { //重载运算符,按分数由大到小排列 if(a.score != b.score) return a.score > b.score; if(a.gt !=b.gt) return a.gt > b.gt; else return a.gr > b.gr; } UserData::UserData(string s, long long sc,int gametime_,int _grade) { //构造UserData对象 name = s; score = sc; gt=gametime_; gr=_grade; } void color(WORD A) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), A); } void Color(int a) { switch (a%4) { case 0:color(RED);break; case 1:color(CYAN);break; case 2:color(YELLOW);break; case 3:color(PURPLE);break; } } void GoTo(short x, short y) { //定位光标 COORD coord = { x, y }; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } void ShowInformation() { //输出游戏信息 color(YELLOW); GoTo(78, 5); printf("贪吃蛇游戏"); GoTo(78,18); gametime=(clock()-mj)/1000; grade=snakeLen-3; printf("生存时间:%3d 秒",(clock()-mj)/1000); GoTo(78, 8); printf("游戏规则:"); GoTo(78, 10); printf("请按 ↑ ↓ ← → 来控制您的蛇吃东西"); GoTo(78, 12); printf("吃的越多,蛇就越长,您的等级也将越高"); GoTo(78, 14); printf("当蛇吃到自己或撞上墙时,游戏结束。"); GoTo(78,16); printf("自动前进时间:%3dms",speed); GoTo(78, 20); printf("当前等级: %8d", snakeLen-3); GoTo(78, 23); printf("您的分数: %d", score); color(CYAN); printf("+%d=%d",score/3,score*3/2); color(YELLOW); GoTo(78,25); printf("剩余时间:%d秒",20+(snakeLen-3)*5-gametime); sysj=20+(snakeLen-3)*5-gametime; } void DrawBoard() { //绘制墙体 HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); //获得输出句柄 CONSOLE_CURSOR_INFO cursor_info = { 1, 0 }; //光标信息 SetConsoleCursorInfo(hOut, &cursor_info); //隐藏光标 COORD size = { 120, 30 }; SetConsoleScreenBufferSize(hOut, size); //重设缓冲区大小 SMALL_RECT rc = { 0 , 0, 120, 30 }; SetConsoleWindowInfo(hOut, true, &rc); //重设窗口大小 SetConsoleTextAttribute(hOut, CYAN); for (int i = STARTX - 2; i <= ENDX + 2; i += 2) { //横向墙体 GoTo(i, STARTY - 1); printf("■"); GoTo(i, ENDY + 1); printf("■"); } for (int i = STARTY - 1; i <= ENDY + 1; ++i) { //竖向墙体 GoTo(STARTX - 2, i); printf("■"); GoTo(ENDX + 2, i); printf("■"); } } void draw() { char m=snakeLen+62; Color(score); cout<<m; } void Init() { //初始化游戏 system("cls"); memset(isSnake, 0, sizeof(isSnake)); speed = 200; curDiraction = 4; score = 0; DrawBoard(); InitSnake(); ShowInformation(); AddFood(); mj=clock(); point=20; sysj=20; } void RunSnake(int x, int y) { //绘制蛇身 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW); score += snakeLen + 1; if (x == foodx && y == foody) { EartFood(); AddFood(); return; } DrawBoard(); snake.push_front(Node(x, y)); isSnake[y][x] = true; GoTo(x, y); draw(); Node back = snake.back(); snake.pop_back(); isSnake[back.y][back.x] = false; GoTo(back.x, back.y); printf(" "); } void Try(int& x, int& y) { //试走 int key, cnt = 100; while (cnt--) { //多次检测键盘状态 if (_kbhit()) { key = getch(); switch (key) { case UP: // if (curDiraction == 1 || curDiraction == 2) break; --y; curDiraction = 1; return; case DOWN: // if (curDiraction == 1 || curDiraction == 2) break; ++y; curDiraction = 2; return; case LEFT: // if (curDiraction == 3 || curDiraction == 4) break; x -= 2; curDiraction = 3; return; case RIGHT: // if (curDiraction == 3 || curDiraction == 4) break; x += 2; curDiraction = 4; return; } } } if (curDiraction == 1) --y; //用户没有输入时 else if (curDiraction == 2) ++y; else if (curDiraction == 3) x -= 2; else x += 2; } bool IsGoodCoord(int x, int y) { //判断光标是否合法 if (x <= ENDX && y <= ENDY && x >= STARTX && y >= STARTY) return true; else return false; } void AddFood() { //增加食物 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), PURPLE); srand((unsigned)time(NULL)); while (true) { foodx = (rand()%ENDX) + 1; foody = (rand()%ENDY) + 1; if (foodx&1) foodx++; if (!isSnake[foody][foodx] && IsGoodCoord(foodx, foody)) break; } GoTo(foodx, foody); int a=rand()%5; if(a>=4) printf("@"); else if(a<=1) printf("#"); else printf("&"); } void EartFood() { //吃东西 point+=4; int sb=gametime=(clock()-mj)/1000; sysj=point-sb; score+=score/2; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW); snake.push_front(Node(foodx, foody)); isSnake[foody][foodx] = true; ++snakeLen; if (speed >= 55) speed -= 5; GoTo(foodx, foody); draw(); AddFood(); } void InitSnake() { //初始化蛇身 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW); snakeLen = 3, gox = 18, goy = 14; snake.clear(); snake.push_front(Node(12, 14)); snake.push_front(Node(14, 14)); snake.push_front(Node(16, 14)); for (int i = 12; i <= 16; i += 2) { GoTo(i, 14); draw(); isSnake[14][i] = true; } } bool EndGame() { //结束游戏 system("cls"); DrawBoard(); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW); GoTo(28, 10); printf("您的本局游戏得分: %d分", score); GoTo(32, 18); printf("....你挂了...."); GoTo(27, 20); printf("是否继续游戏: 是(1), 否(0)"); GoTo(27, 22); char key = getch(); while (true) { if (key == '1') return false; else if (key == '0') {GoTo(ENDX+1,ENDY+2); exit(0);return true; } else key = getch(); } } bool StartGame() { //启动游戏 Init(); while (sysj>0) { //开挂 RunSnake(gox, goy); ShowInformation(); Try(gox, goy); Sleep(speed); } InputData(); return true; } bool GameMenu() { //游戏菜单 system("cls"); DrawBoard(); GoTo(STARTX + 22, STARTY + 4); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW); printf("欢迎进入贪吃蛇游戏!"); GoTo(STARTX + 24, STARTY + 10); printf("1: 新游戏"); GoTo(STARTX + 24, STARTY + 12); printf("2: 排行榜"); GoTo(STARTX + 24, STARTY + 14); printf("3: 关于游戏"); GoTo(STARTX + 24, STARTY + 16); printf("4: 退出游戏"); while (true) { if (_kbhit()) { char key = getch(); switch (key) { case '1': if (!StartGame()) return false; else return true; case '2': ShowRanking(); return true; case '3': ShowAbout(); return true; case '4': GoTo(1,ENDY+2); return false; default: return true; } } } } void ShowRanking() { //展示排行榜 vector<UserData> vu; FILE *fp = fopen("Gamedata2.txt", "r"); if (fp == NULL) fp = fopen("Gamedata2.txt", "w+"); char name[20]; int len = 0; while (fscanf(fp, "%s", name) != EOF) { ++len; int score,g=grade; fscanf(fp, "%d%d%d%*c", &score,&gametime,&g); vu.push_back(UserData(string(name), score,gametime,g)); } fclose(fp); sort(vu.begin(), vu.end()); //对得分进行排名 system("cls"); DrawBoard(); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), CYAN); GoTo(STARTX + 8, STARTY + 2); printf("用户"); GoTo(STARTX + 20, STARTY + 2); printf("分数"); GoTo(STARTX + 32, STARTY + 2); printf("生存时间"); GoTo(STARTX + 44, STARTY + 2); printf("排行"); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW); for (int i = 0; i < len && i < 10; ++i) { //打印前十名用户数据 char const *p = vu[i].name.c_str(); Color(score); GoTo(STARTX + 8, STARTY + 4 + i); printf("%s", p); GoTo(STARTX + 20, STARTY + 4 + i); printf("%d分", vu[i].score); GoTo(STARTX + 32, STARTY + 4 + i); printf("%d秒", vu[i].gt); GoTo(STARTX + 44, STARTY + 4 + i); printf(" %d", i + 1); } GoTo(STARTX + 4, ENDY - 2); printf("----------------- 按'1'返回游戏菜单 ---------------"); while (true) { if (_kbhit()) { char key = getch(); if (key == '1') break; } } } void ShowAbout() { //展示游戏相关 system("cls"); DrawBoard(); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW); GoTo(STARTX + 4, STARTY + 2); printf("------------------- 贪吃蛇游戏 -------------------"); GoTo(STARTX + 10,STARTY + 8); printf("贪吃蛇游戏"); GoTo(STARTX + 10,STARTY + 10); printf("游戏规则:"); GoTo(STARTX + 10,STARTY + 12); printf("请按 ↑ ↓ ← → 来控制您的蛇吃东西"); GoTo(STARTX + 10,STARTY + 14); printf("吃的越多,蛇就越长,您的等级也将越高"); GoTo(STARTX + 10,STARTY + 16); printf("当蛇吃到自己或撞上墙时,游戏结束。"); GoTo(STARTX + 4, ENDY - 2); printf("----------------- 按'1'返回游戏菜单 ---------------"); while (true) { if (_kbhit()) { char key = getch(); if (key == '1') break; } } } void InputData() { //用户输入名字 char name[20]; if(score>=1000) { GoTo(STARTX + 10, STARTY + 10); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), RED); printf("请输入你的名字: "); COORD coord = { STARTX + 10, STARTY + 12 }; SetConsoleCursorPosition(GetStdHandle(STD_INPUT_HANDLE), coord); while (true) { //忽略非法字符 scanf("%s", name); if (name[0] != 0 && name[0] != ' ') break; }FILE *fp = fopen("Gamedata2.txt", "a"); if (fp == NULL) fp = fopen("Gamedata2.txt", "w+"); fprintf(fp, "%s %d %d \n", name, score,gametime); fclose(fp); } else { GoTo(STARTX + 20, STARTY + 10); cout<<"哟!这分数也能上榜??"<<endl; Sleep(1000); } EndGame(); }好玩,但边际判断有亿点问题,推荐指数:💎💎💎💎
只能挂这么多,想要更多私信我~
挂的都是比较好玩的,绝对没有私货!
-
通过的题目
-
最近活动
- JHCSP复赛模拟赛二 OI
- JHCSP复赛考前模拟一 OI
- JH二分和背包模板练习赛 ACM/ICPC
- 2025.10.23 背包二分练习和模板赛 作业
- 2025.10.17 模板赛和二分,背包最短路 作业
- JH 搜索模板练习赛 ACM/ICPC
- 2025.10.16 提高组真题和模板练习 作业
- 2025.10.10 复赛真题练习 作业
- 2025.10.09 复赛真题练习 作业
- JH国庆CSP复赛集训模拟赛4 OI
- 2025.10.05 国庆集训Day4:图论和dp(JT4 /ST3) 作业
- JH国庆CSP复赛集训模拟赛3 OI
- 2025.10.05 国庆集训Day3:模拟和搜索(JT3 /ST2) 作业
- JH国庆CSP复赛集训模拟赛2 OI
- 2025.10.05 国庆集训Day2:贪心和优化(JT2 /ST1) 作业
- JH国庆CSP复赛集训模拟赛1 OI
- 2025.10.04 国庆集训Day1:数学和模拟 (JT1 /ST1) 作业
- 贪心进阶 作业
- 2025.09.25 高精度运算 作业
- 2025.09.12 建华提高班 高精度加法 作业
- 2025.09.05 建华提高班 快速幂 作业
- 2025.09.04 建华提高班 质数筛 作业
题目标签
- 搜索
- 4
- CSP-J
- 4
- 高精度
- 3
- 贪心
- 3
- 其他
- 3
- CSPJ模拟赛
- 3
- R16
- 3
- 模拟
- 2
- dfs
- 2
- 一本通编程启蒙
- 2
- 数论
- 2
- 数学
- 2
- CSP-S
- 2
- 2014
- 1
- 2019
- 1
- 2020
- 1
- 2023
- 1
- 1
- 回溯法
- 1
- NOIP 提高组
- 1