写个小小小游戏,大家有兴趣帮改改。
程序代码:
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int i = 1, t; int man, computer; int zg , sm ; printf("司马老儿大战诸葛村夫!\n"); printf("你想大战几回合?:"); scanf("%d", &t); srand((unsigned)time(NULL)); while (t--) { zg = 1000, sm = 1000; printf("第%d局开始!\n", i); printf("诸葛初始血量%d ", zg); printf("司马初始血量%d \n", sm); while (zg > 0 && sm > 0) { printf("出招吧!:"); do { scanf("%d", &man); }while (man < 1 || man > 3); if (man == 1) printf("诸葛痛下杀手-->剑指洛阳!\n"); if (man == 2) printf("诸葛痛下杀手-->赤壁烈焰!\n"); if (man == 3) printf("诸葛痛下杀手-->木牛暴踏!\n"); computer = rand() % 3 + 1; if (computer == 1) printf("司马反戈一击-->水淹蜀道!\n"); if (computer == 2) printf("司马反戈一击-->森严壁垒!\n"); if (computer == 3) printf("司马反戈一击-->魏斧狂啸!\n"); if (man == 1 && computer == 1) { zg -= 100; sm -= 20; printf("诸葛还剩%d血 ", zg); printf("司马还剩%d血 \n", sm); } if (man == 1 && computer == 2) { zg += 20; sm -= 100; printf("诸葛还剩%d血 ", zg); printf("司马还剩%d血 \n", sm); } if (man == 1 && computer == 3) { zg -= 100; sm -= 100; printf("诸葛还剩%d血 ", zg); printf("司马还剩%d血 \n", sm); } if (man == 2 && computer == 1) { zg -= 120; sm += 20; printf("诸葛还剩%d血 ", zg); printf("司马还剩%d血 \n", sm); } if (man == 2 && computer == 2) { zg += 10; sm -= 130; printf("诸葛还剩%d血 ", zg); printf("司马还剩%d血 \n", sm); } if (man == 2 && computer == 3) { zg -= 50; sm -= 50; printf("诸葛还剩%d血 ", zg); printf("司马还剩%d血 \n", sm); } if (man == 3 && computer == 1) { zg -= 10; sm -= 70; printf("诸葛还剩%d血 ", zg); printf("司马还剩%d血 \n", sm); } if (man == 3 && computer == 2) { zg -= 100; sm -= 100; printf("诸葛还剩%d血 ", zg); printf("司马还剩%d血 \n", sm); } if (man == 3 && computer == 3) { zg -= 30; sm += 30; printf("诸葛还剩%d血 ", zg); printf("司马还剩%d血 \n", sm); } } if (zg <= 0) printf("诸葛死亡,司马狂笑道:村夫何足道!\n"); if (sm <= 0) printf("司马死亡,诸葛冷笑道:无能鼠辈!\n"); i++; } return 0; }
[ 本帖最后由 有容就大 于 2012-1-30 13:28 编辑 ]