五一假期到了,该放松一下了,我自己做了个五一小游戏
代码我用c++写的
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
// 函数声明
void startGame();
void travelAdventure();
void movieNight();
void picnicAdventure();
int main() {
srand(time(nullptr)); // 初始化随机数生成器
startGame();
return 0;
}
void startGame() {
string activity;
cout << "五一假期到了!你想做什么活动呢?" << endl;
cout << "1. 去旅行" << endl;
cout << "2. 宅在家里看电影" << endl;
cout << "3. 外出野餐" << endl;
cout << "请输入你的选择(1/2/3):";
cin >> activity;
if (activity == "1") {
travelAdventure();
} else if (activity == "2") {
movieNight();
} else if (activity == "3") {
picnicAdventure();
} else {
cout << "无效的选择,请重新输入。" << endl;
startGame(); // 重新开始游戏
}
}
void travelAdventure() {
cout << "你选择了去旅行!你来到了一个神秘的岛屿..." << endl;
string choice;
cout << "1. 探索洞穴" << endl;
cout << "2. 在海滩上放松" << endl;
cout << "请输入你的选择(1/2):";
cin >> choice;
if (choice == "1") {
// 假设有50%的几率发现宝藏
int findTreasure = rand() % 2;
if (findTreasure) {
cout << "恭喜你!你在洞穴里发现了一箱宝藏!" << endl;
} else {
cout << "很遗憾,洞穴里什么都没有。" << endl;
}
} else if (choice == "2") {
cout << "你在海滩上享受了阳光和海浪,度过了一个轻松的假期。" << endl;
} else {
cout << "无效的选择,请重新输入。" << endl;
travelAdventure(); // 重新开始旅行冒险
}
}
void movieNight() {
cout << "你选择了宅在家里看电影!你选了一部恐怖电影..." << endl;
// 这里可以添加更多的电影选择或互动,比如选择电影类型、评分等
cout << "电影很精彩,你度过了一个刺激的夜晚!" << endl;
}
void picnicAdventure() {
cout << "你选择了外出野餐!你和朋友们来到了一个美丽的公园..." << endl;
// 这里可以添加野餐准备、游戏等互动
cout << "野餐你想吃啥?" << endl;
string drink;
cout << "饮品:" << endl;
cout << "1. 牛奶" << endl;
cout << "2. 橙汁" << endl;
cout << "3. 豆浆" << endl;
cout << "4. 果粒橙" << endl;
cout << "5. 咖啡" << endl;
cout << "请输入你的选择(1/2/3/4/5):";
cin >> drink;
int milk = 0;
int orange = 0;
int soybeanmilk = 0;
int fruitorange = 0;
int coffee = 0;
if (drink == "1") {
milk++;
} else if (drink == "2") {
orange++;
} else if (drink == "3") {
soybeanmilk++;
} else if (drink == "4") {
fruitorange++;
} else if (drink == "5") {
coffee++;
} else {
cout << "无效的选择,请重新输入。" << endl;
picnicAdventure(); // 重新开始旅行冒险
}
cout << "野餐你想吃啥?" << endl;
string food;
cout << "食物:" << endl;
cout << "1. 盒饭(青椒肉丝味)" << endl;
cout << "2. 盒饭(红烧牛肉味)" << endl;
cout << "3. 盒饭(土豆牛腩味)" << endl;
cout << "4. 盒饭(宫爆鸡丁味)" << endl;
cout << "5. 面条(红烧牛肉面)" << endl;
cout << "6. 面条(日式骨汤面)" << endl;
cout << "7. 面条(番茄鸡蛋面)" << endl;
cout << "8. 面条(兰州拉面)" << endl;
cout << "请输入你的选择(1/2/3/4/5/6/7/8):";
cin >> food;
int ShreddedporkandgreenpepperwithGreenPeppers = 0;
int BraisedBeefFlavor = 0;
int Potatoandbeefbrisketflavor = 0;
int KungPaoChickenFlavor = 0;
int BraisedBeefNoodlesinBrownSauce = 0;
int JapaneseboneNoodlesinsoup = 0;
int Tomatoandeggnoodles = 0;
int LanzhouLamianNoodles = 0;
if (food == "1") {
ShreddedporkandgreenpepperwithGreenPeppers++;
} else if (food == "2") {
BraisedBeefFlavor++;
} else if (food == "3") {
Potatoandbeefbrisketflavor++;
} else if (food == "4") {
KungPaoChickenFlavor++;
} else if (food == "5") {
BraisedBeefNoodlesinBrownSauce++;
} else if (food == "6") {
JapaneseboneNoodlesinsoup++;
} else if (food == "7") {
Tomatoandeggnoodles++;
} else if (food == "8") {
LanzhouLamianNoodles++;
} else {
cout << "无效的选择,请重新全部选择。" << endl;
picnicAdventure(); // 重新开始旅行冒险
}
cout << "你要吃的是:" << endl;
cout << "牛奶:" << milk << endl;
cout << "橙汁:" << orange << endl;
cout << "豆浆:" << soybeanmilk << endl;
cout << "果粒橙:" << fruitorange << endl;
cout << "咖啡:" << coffee << endl << endl;;
cout << "盒饭(青椒肉丝味):" << ShreddedporkandgreenpepperwithGreenPeppers << endl;
cout << "盒饭(红烧牛肉味):" << BraisedBeefFlavor << endl;
cout << "盒饭(土豆牛腩味):" << Potatoandbeefbrisketflavor << endl;
cout << "盒饭(宫爆鸡丁味):" << KungPaoChickenFlavor << endl;
cout << "面条(红烧牛肉面):" << BraisedBeefNoodlesinBrownSauce << endl;
cout << "面条(日式骨汤面):" << JapaneseboneNoodlesinsoup << endl;
cout << "面条(番茄鸡蛋面):" << Tomatoandeggnoodles << endl;
cout << "面条(兰州拉面):" << LanzhouLamianNoodles << endl << endl;
cout << "吧唧吧唧你吃完了!" << endl;
cout << "你们玩得很开心,度过了一个愉快的假期!" << endl;
}
做的不是非常好,玩几次就玩腻了,毕竟这个游戏我才用了10几分钟写出了的,不用追求太好。