彩票中奖游戏
2025-07-25 12:36:22
发布于:广东
求关注、点赞!!!
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#include <cstdlib>
#include <ctime>
using namespace std;
double money = 0.0;
void color(int color) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
void welcome() {
system("color 0A");
for (int i = 0; i < 3; i++) {
system("cls");
cout << "\n\n\n";
cout << " ★★☆★★☆★★☆★★☆★★\n";
cout << " ☆ ★\n";
cout << " ★ 彩票开奖系统 ☆\n";
cout << " ☆ ★\n";
cout << " ★★☆★★☆★★☆★★☆★★\n";
Sleep(500);
system("color 0B");
Sleep(500);
}
system("color 0F");
}
int menu() {
system("cls");
color(11);
cout << "══════════════════════════════\n";
cout << " 彩票游戏 v2.0 \n";
cout << " 你的钱数:" << money << "美元" << endl;
cout << "══════════════════════════════\n";
color(7);
cout << "1. 开始游戏\n";
cout << "2. 游戏规则\n";
cout << "3. 退出游戏\n";
cout << "══════════════════════════════\n";
cout << "请选择: ";
int a;
cin >> a;
return a;
}
void rules() {
system("cls");
color(14);
cout << "════════════════ 游戏规则 ════════════════\n";
color(7);
cout << "1. 系统随机生成6个1-49的数字作为中奖号码\n";
cout << "2. 您需要选择6个不同的数字(1-49)\n";
cout << "3. 匹配的数字越多,奖金越高\n";
cout << "4. 匹配6个数字可获得头奖!\n";
color(14);
cout << "══════════════════════════════════════════\n";
color(7);
system("pause");
}
vector<int> check(int count, int max) {
vector<int> v;
srand(time(NULL));
while (v.size() < count) {
int num = rand() % max + 1;
if (find(v.begin(), v.end(), num) == v.end())
v.push_back(num);
}
sort(v.begin(), v.end());
return v;
}
void dfs(const vector<int> &v) {
system("cls");
cout << "\n\n";
color(12);
cout << " 正在开奖...\n\n";
color(7);
vector<int> v2;
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < 3; j++) {
cout << "\r ";
for (int k = 0; k <= i; k++) {
color(10);
cout << v[k] << " ";
color(7);
}
for (int k = 0; k < 3; k++)
cout << (rand() % 49 + 1) << " ";
Sleep(100);
}
v2.push_back(v[i]);
cout << "\r ";
for (int num : v2) {
color(10);
cout << num << " ";
color(7);
}
cout << " \n";
Sleep(800);
}
}
void game() {
system("cls");
SetConsoleTitle(TEXT("买彩票中..."));
color(11);
cout << "════════════════ 选择号码 ════════════════\n";
color(7);
cout << "请输入6个不同的数字(1-49),用空格分隔:\n";
vector<int> v;
for (int i = 0; i < 6; ) {
int num;
cin >> num;
if (num < 1 || num > 49) {
cout << "请输入1-49之间的数字!\n";
continue;
}
if (find(v.begin(), v.end(), num) != v.end()) {
cout << "不能重复选择相同数字!\n";
continue;
}
v.push_back(num);
i++;
}
sort(v.begin(), v.end());
system("cls");
color(14);
cout << "您选择的号码是: ";
color(10);
for (int num : v)
cout << num << " ";
cout << "\n\n";
color(7);
system("pause");
vector<int> winnum = check(6, 49);
SetConsoleTitle(TEXT("第250期开奖节目"));
dfs(winnum);
int cnt = 0;
for (int num : v)
if (find(winnum.begin(), winnum.end(), num) != winnum.end())
cnt++;
system("cls");
color(14);
cout << "════════════════ 开奖结果 ════════════════\n";
color(7);
cout << "中奖号码: ";
color(12);
for (int num : winnum)
cout << num << " ";
cout << "\n\n";
color(7);
cout << "您的号码: ";
color(11);
for (int num : v) {
if (find(winnum.begin(), winnum.end(), num) != winnum.end())
color(10);
cout << num << " ";
color(11);
}
cout << "\n\n";
color(14);
if (cnt)
cout << "您匹配了 " << cnt << " 个号码!\n";
else
cout << "您没有匹配到号码。\n";
color(12);
switch (cnt) {
case 6:
cout << "恭喜!您中了头奖!奖金1亿美元!\n";
money += 100000000;
break;
case 5:
cout << "二等奖!奖金100万美元!\n";
money += 1000000;
break;
case 4:
cout << "三等奖!奖金1万美元!\n";
money += 10000;
break;
case 3:
cout << "四等奖!奖金1000美元!\n";
money += 1000;
break;
default:
cout << "很遗憾,您没有中奖\n";
}
color(7);
system("pause");
}
int main() {
ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
MessageBoxA(NULL, "彩票游戏", "游戏名称", MB_ICONASTERISK);
SetConsoleTitle(TEXT("彩票游戏 v1.0"));
welcome();
while (true) {
int x = menu();
switch (x) {
case 1:
game();
break;
case 2:
rules();
break;
case 3:
system("cls");
color(11);
cout << "感谢游玩,再见!\n";
color(7);
return 0;
default:
cout << "无效选择,请重新输入!\n";
Sleep(1000);
}
}
return 0;
}
这里空空如也
有帮助,赞一个