模拟扭蛋器( 不完整,仅通过课设要求)
模拟一个扭蛋器。具体要求如下:
- 设计扭蛋器出蛋控制策略,实现参数可调节出蛋;
- 模拟一个扭蛋器游戏的过程;
- 扭蛋器营收分析,按周统计扭蛋器成本和收益,通过数据分析给出下一周的出蛋控制参数。 #include<iostream> #include<stdlib.h>//引用,能够使用ssytem("cls")达到清屏目的 #include<string> #include<ctime>//引用时间类库对象,可以使用时间延时函数Delay using namespace std; const int N = 5; const int M = 100; void Delay(int time)//程序运行时间延迟。 { clock_t now = clock(); while (clock() - now < time); } void circle_open(int e)//开蛋结果 { cout << " **" << endl; cout << " ***" << endl; cout << "****" <<"奖品"<<e<< endl; cout << " ***" << endl; cout << " ********" << endl; cout << " *** " << endl; cout << " * " << endl; } void Mean()//文本菜单 { cout << "********************" << endl; cout << "每次五块,不准白嫖!" << endl; cout << "*按 1 开始投币*" << endl; cout << "*按 2 单次扭蛋*" << endl; cout << "*按 3 十连抽*" << endl; cout << "*按 4 查看奖励列表*" << endl; cout << "*按 5 查看所获奖励*" << endl; cout << "*按 6 提前结束程序*" << endl; cout << "若提前结束程序,投入的币不退还" << endl; cout << "********************" << endl; } int Srand()//用于产生1~10之间的随机数 { int e; srand((unsigned int)time(NULL)); e = 1 + rand() % 10; return e; } class Gashapon { private: int a = 0; static int arr[M]; static int count; int m = 0;//表示单次投入的硬币数量 public: int n = 0;//表示总硬币数 void Coins()//投币函数 { cout << "请输入你所需要投币的数量,必须为5的倍数:"; cin >> m; if (n % 5 == 0) n = n+m; else { n = 0; cout << "投入的币不符!" << endl; } } void Start()//扭蛋开始函数(单次开始) { n = n - N; if (n >=0) { a = Srand(); arr[count] = a; count++; cout << "出蛋!" << endl; Delay(1*1000);//延迟1秒 system("cls"); Mean(); circle_open(a); cout << "游戏币剩余:" << n << endl; } else cout << "想要继续请投币!!!" << endl; } void reward_list()//奖品列表 { 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 << "奖品9:" << endl; cout << "奖品10:" << endl; } static void reward_look()//查看奖励序号 { cout << "你的" << count << "奖励序号为:"<<endl; for (int j = 0; j <count; j++) { cout << arr[j]<<" "; } cout << "请按照序号领取奖励" << endl; } }; int Gashapon::count = 0; int Gashapon::arr[M]; int main() { int op; Gashapon A; Mean(); label:cout << "请执行操作!" << endl; cin >> op; switch (op) { case 1: A.Coins();//投币 goto label; case 2: A.Start();//开始一次 goto label; case 3://十连抽 if (A.n >= (10 * N)) { for (int i = 0; i < 10; i++) { A.Start(); } cout << "十连抽结果如下:"; A.reward_look(); } else cout << "硬币不足,无法启动十连抽"; goto label; case 4: A.reward_list();//查看将励列表 goto label; case 5: A.reward_look();//查看所取得的奖励序号 goto label; case 6: break;//提前结束程序 default: cout << "无效操作" << endl; goto label; } system("pause"); return 0; }
