闲的无聊写了个很(wu)有(liao)意(dao)思(bao)的程序
Posted 自为
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了闲的无聊写了个很(wu)有(liao)意(dao)思(bao)的程序相关的知识,希望对你有一定的参考价值。
下午机房断网了
闲的无聊,写了个小游戏
忘了sleep在哪个库里了。。
自带变色效果哦
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<stdlib.h> 6 #include<ctime> 7 using namespace std; 8 const int MAXN=0x7fffff; 9 const int INF=50; 10 inline int read() 11 { 12 char c=getchar();int f=1,x=0; 13 while(c<\'0\'||c>\'9\') {if(c==\'-\') f=-1;c=getchar();} 14 while(c>=\'0\'&&c<=\'9\') x=x*10+c-48,c=getchar();return x*f; 15 } 16 struct god 17 { 18 int blood; 19 int attack; 20 }lgj; 21 struct lgj_de_son 22 { 23 int blood; 24 int attack; 25 }lyq; 26 inline void sleep() 27 { 28 int tot=0; 29 for(int i=1;i<=2*1e8;i++) tot++; 30 } 31 string myname; 32 string enemyname; 33 int main() 34 { 35 srand((unsigned)time(NULL)); 36 system("color b"); 37 printf("please input your name\\n"); 38 cin>>myname; 39 printf("please input your blood\\n"); 40 cin>>lgj.blood; 41 printf("please input your attack\\n"); 42 cin>>lgj.attack; 43 printf("please input your enemy\'s name\\n"); 44 cin>>enemyname; 45 printf("please input your enemy\'s blood\\n"); 46 cin>>lyq.blood; 47 printf("please input your enemy\'s attack\\n"); 48 cin>>lyq.attack; 49 int now=0; 50 while(lgj.blood>0&&lyq.blood>0) 51 { 52 if(now==0) 53 { 54 sleep(); 55 system("color a"); 56 now^=1; 57 cout<<myname; 58 printf(" will attack "); 59 sleep(); 60 int k=rand()%5*lgj.attack; 61 cout<<enemyname; 62 printf(" \'s blood -%d\\n",k); 63 lyq.blood-=k; 64 cout<<enemyname; 65 printf(" \'s blood remain %d\\n",lyq.blood); 66 sleep(); 67 } 68 else 69 { 70 system("color e"); 71 sleep(); 72 now^=1; 73 cout<<enemyname; 74 printf(" will attack "); 75 sleep(); 76 int k=rand()%5*lyq.attack; 77 cout<<myname; 78 printf("\'s blood -%d\\n",k); 79 lgj.blood-=k; 80 sleep(); 81 cout<<myname; 82 printf("\'s blood remain %d\\n",lgj.blood); 83 } 84 } 85 system("color b"); 86 if(lgj.blood<0) printf("*********lyq win************"); 87 else printf("*********lgj win************"); 88 return 0; 89 }
以上是关于闲的无聊写了个很(wu)有(liao)意(dao)思(bao)的程序的主要内容,如果未能解决你的问题,请参考以下文章
2016.3.19作业 分析一个很有(wu)趣(liao)的小程序
虽然我不是做游戏的,闲的没事,emm,写了个扫雷小游戏(Android)
虽然我不是做游戏的,闲的没事,emm,写了个扫雷小游戏(Android)