写了一个短一点的钓鱼小游戏,献上代码^_^:
#include<bits/stdc++.h> #include<windows.h> using namespace std; int main() { ?? ?system("color 4b");? ? ? srand(time(NULL)); ? ? system("cls"); ?? ?char name; ?? ?int fish = 2,luck,mp = 5,i; ?? ?cout << "请输入姓名" ?<< endl; ?? ?cin >> name; ?? ?system("cls"); ? ? cout << name << "的钓鱼游戏" << endl; ? ? cout << "目前鱼数:" << fish << endl; ? ? cout << "生命值:" << mp << endl; ?? ?cout << ?"1.钓鱼 ?2.吃鱼" << endl;? ?? ?cin >> i; ? ? while(mp > 0) ? ? { ?? ??? ?if(i == 1) ?? ??? ?{ ?? ??? ??? ?mp--; ?? ??? ??? ?luck = rand() % 10; ?? ??? ??? ?if(luck == 0||luck == 1||luck == 2||luck == 3) ?? ??? ??? ?{ ?? ??? ??? ??? ?fish++; ?? ??? ??? ??? ?cout << "钓上来了一条鲅鱼" << endl;? ?? ??? ??? ??? ?cout << "目前鱼数:" << fish << endl; ?? ??? ??? ??? ?cout << "生命值:" << mp << endl;?? ? ?? ??? ??? ??? ?Sleep(1000); ?? ??? ??? ?}else if(luck == 6) ?? ??? ??? ?{ ?? ??? ??? ??? ?fish = fish + 2; ?? ??? ??? ??? ?cout << "钓上来了两条三文鱼" << endl;? ?? ??? ??? ??? ?cout << "目前鱼数:" << fish << endl; ?? ??? ??? ??? ?cout << "生命值:" << mp << endl; ?? ??? ??? ??? ?Sleep(1000); ?? ??? ??? ?}else{ ?? ??? ??? ??? ?fish = fish - 3; ?? ??? ??? ??? ?mp = mp - 1; ?? ??? ??? ??? ?cout << "钓上来了一堆垃圾" << endl;? ?? ??? ??? ??? ?cout << "目前鱼数:" << fish << endl; ?? ??? ??? ??? ?cout << "生命值:" << mp << endl; ?? ??? ??? ??? ?Sleep(2000); ?? ??? ??? ?}? ?? ??? ??? ? ?? ??? ?} ?? ??? ?else if(i == 2) ?? ??? ?{ ?? ??? ??? ?if(fish == 0) ?? ??? ??? ?{ ?? ??? ??? ??? ?cout << "没有鱼了" << endl; ?? ??? ??? ?}else{ ?? ??? ??? ??? ?mp++; ?? ??? ??? ? ? ?fish--; ?? ??? ??? ? ? ?cout << "真香" << endl; ?? ??? ? ? ??? ?cout << "目前鱼数:" << fish << endl; ?? ??? ??? ? ? ?cout << "生命值:" << mp << endl; ?? ??? ??? ? ? ?Sleep(2000); ?? ??? ??? ?} ?? ??? ?} ?? ?? ??? ?system("cls"); ?? ??? ?if(fish<0) ?? ??? ?{ ?? ??? ??? ?fish = 0; ?? ??? ?} ?? ??? ?else{ ?? ??? ??? ?fish = fish; ?? ??? ?} ?? ??? ?cin >> i;? ?? ?} ?? ?cout << "GAME OVER"; ?? ?return 0; }?
|