用C语言编写一个程序

1)模拟一个街霸游戏,
就是那种
随机出拳打中人随机掉血的那种,
其中生成的随机数用rand函数。
用0-10表示时间数,用while循环
语句,掉没血了或者时间结束了结
束循环。

#include<stdio.h>
typedef struct {
int   blood;
char* type;
int   sleep;
}Fist;
Fist f[] = {
{1, "直拳", 1},
{3, "勾拳", 2},
{5, "摆拳", 2},
{8,"重拳",  5},
};
#define BLOOD (100)
#define TIME  (80)
int main()
{
   int t = TIME;
   int b = BLOOD;
   srand(time(NULL));
   while (t > 0) {
   int c = rand() % (sizeof(f)/sizeof(Fist));
   int r = rand() % 3;
   printf("一记%s过后", f[c].type);
   if (r == 2) {
   printf("闪开了\n");
   }
   else {
   printf("损失血精%d点\n", f[c].blood);
   b -= f[c].blood;
   if (b <= 0) break;
   }
   //sleep(f[c].sleep*10);
   t -= f[c].sleep;
   }
   if (b > 0) {
   printf("英雄气概仍有精力%d点\n", b);
   }
   else {
   printf("继续操练,你坚持了%d秒\n", TIME - t);
   }
   return 0;
}
温馨提示:答案为网友推荐,仅供参考
相似回答