1. 程式人生 > >閑的無聊寫了個很(wu)有(liao)意(dao)思(bao)的程序

閑的無聊寫了個很(wu)有(liao)意(dao)思(bao)的程序

ges bsp sig () %d string srand lin space

下午機房斷網了

閑的無聊,寫了個小遊戲

忘了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)的程序