C++抽卡模擬器

近日在學校無聊,寫了個抽卡模擬器供大家娛樂。

代碼實現以下功能:抽卡界面,抽卡判定、動畫播放、存檔。

1.抽卡界面及判定

技術有限,不可能做的和原神一樣精致。代碼如下(注:這不是完整代碼,別復制錯了)

printf("enter your name:");cin >> username;HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO CursorInfo;GetConsoleCursorInfo(handle, &CursorInfo);CursorInfo.bVisible = false;SetConsoleCursorInfo(handle, &CursorInfo);printf("For each time : 0.6%% for gold and 6%% for purple\n");printf("P(gold) will increase After 73 times until 90 to 100%\n");printf("10 purples , as well as 1 gold, provides another chance\n");system("pause");char kk = _getch();if (kk == 'c')change();int r, waidegold = 0, ggold = 0, pple = 0;READ();srand(time(0));int n, m, i, j, gold = 0, pp = 0, big = 0, cnt = 0, total = 30;while (cnt < total) {system("cls");printf("Press 1.10\n");printf("You've rolled %d times rest:%d\n", cnt * 10, (total - cnt) * 10);printf("WAI:%d GOLD:%d PP:%d\n", waidegold, ggold, pple);++cnt;char k;bool chu = 0;k = _getch();Sleep(5);for (i = 1; i <= 10; ++i) {int r = random();++gold, ++pp;if (r <= p[gold] *MAXX ) {total++;//goldPlay(1);chu = 1;if ((rand() % 2  ) && !big) {//waibig = 1;string tmp = changzhu[rand() % 8];printf("%d times 恭喜你歪%s了\n", gold, tmp.c_str());DATA[++cnttt] = username;DATA[cnttt]  += ( gold / 10 + '0');DATA[cnttt] += (gold % 10 + '0' );DATA[cnttt] += "times : ";DATA[cnttt] += tmp;//printf("DATA[%d]= %s\n", cnttt, DATA[cnttt].c_str());Sleep(2000);system("pause");waidegold++;} else {big = 0;printf("%d times %s\n", gold, UP.c_str());DATA[++cnttt] = username;DATA[cnttt]  += ( gold / 10 + '0');DATA[cnttt] += (gold % 10 + '0' );DATA[cnttt] += "times : ";DATA[cnttt] += UP;//printf("DATA[%d]= %s\n", cnttt, DATA[cnttt].c_str());Sleep(2000);system("pause");ggold++;}gold = 0;}if (r >= MAXX * 0.94 || pp == 10) {//purpleif (!chu)Play(0);chu = 1;printf("%d times a purple\n", pp);system("pause");pp = 0;pple++;if (pple % 10 == 0)total++;}}}

2.存檔

包括時間獲取以及存儲結果

獲取時間:

struct Time {int year, month, day, hour, minute, second;
};Time gottime() {Time TIME;time_t now = time(0);tm *ltm = localtime(&now);TIME.year = 1900 + ltm->tm_year;TIME.month = 1 + ltm->tm_mon;TIME.day = ltm->tm_mday;TIME.hour = ltm->tm_hour;TIME.minute = ltm->tm_min;TIME.second = ltm->tm_sec;return TIME;
}

存儲:

void read() {freopen("ouhuang.txt", "r", stdin);scanf("%d %d %d", &mxxwdgd, &mxxggd, &mxxple);fclose(stdin);
}
void putt(int waidegold, int ggold, int pple) {freopen("ouhuang.txt", "w", stdout);printf("%d %d %d", waidegold, ggold, pple);fclose(stdout);
}
void save(int waidegold, int ggold, int pple) {read();printf("RECORD: waide:%d not:%d ple:%d\n", mxxwdgd, mxxggd, mxxple);if (ggold > mxxggd) {printf("NEW RECORD!!!\n");putt(waidegold, ggold, pple);Sleep(3000);}}
string changzhu[8] ;
string UP;
void READ() {freopen("text.txt", "r", stdin);cin >> UP;for (int i = 0; i <= 7; i++)cin >> changzhu[i];fclose(stdin);
}
void change() {freopen("text.txt", "w", stdout);string st;cin >> st;cout << st << endl;for (int i = 1; i <= 8; i++) {cin >> st;cout << st << endl;}fclose(stdout);
}
void read1() {freopen("data.txt", "r", stdin);char tmp[500];while (~scanf("%s", &tmp)) {DATA[++cnttt] = tmp;}fclose(stdin);
}
void data1(string stt) {freopen("data.txt", "w", stdout);Time s = gottime();printf("\n%d/%d/%d,%d:%d:%d\n", s.year, s.month, s.day, s.hour, s.minute, s.second);printf("%s\n", username.c_str());for (int i = 1; i <= cnttt; i++) {if (DATA[i] == ":" || DATA[i + 1] == ":")printf("%s", DATA[i].c_str());elseprintf("%s\n", DATA[i].c_str());}fclose(stdin);fclose(stdout);
}

對了,由于不是很信任rand(),自己造了一個隨機函數

int random() {int a[6], k = 0;for (int i = 0; i < 6; ++i)a[i] = rand() % 10;for (int i = 0; i < 6; ++i)k = k * 10 + a[i];return k;
}

3.動畫播放

十分簡陋。

void Play(bool ggg) {system("cls");if (ggg == 0) {setcolor(purple, white);} else {setcolor(black, yellow);}int i, j, k;for (i = 1; i <= 20; i++) {GoToxy(i, i + 20) ;printf("\\");Sleep(40);if (ggg == 1)Sleep(15);}i = 20, j = 50, k = 1;int r = 1;if (ggg == 1)for (; r <= 10; r += k, ++k) {GoToxy(i - r, i + 20 - r);for (int i1 = i - r; i1 <= i + r; ++i1)printf("_");for (int i1 = i - r + 1; i1 <= i + r - 1; ++i1) {GoToxy(i1, i + 20 - r);printf("|");GoToxy(i1, i + 20 + r);printf("|");}GoToxy(i + r, i + 20 - r);for (int i1 = i - r; i1 <= i + r; ++i1)printf("_");Sleep(55);}system("cls");setcolor(white, black);
}

就是這樣,完整代碼如下。使用教程

抽卡模擬器~_嗶哩嗶哩_bilibili

#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
const int MAXX = 1e6;
string username;
string DATA[500000];
int cnttt = 0;struct Time {int year, month, day, hour, minute, second;
};Time gottime() {Time TIME;time_t now = time(0);tm *ltm = localtime(&now);TIME.year = 1900 + ltm->tm_year;TIME.month = 1 + ltm->tm_mon;TIME.day = ltm->tm_mday;TIME.hour = ltm->tm_hour;TIME.minute = ltm->tm_min;TIME.second = ltm->tm_sec;return TIME;
}enum Colour {black, blue, green, palegreen, red, purple, yellow, white, gray, light_blue, light_palegreen, light_red, light_purple, light_yellow, light_white}; //注:有些是詞生造出來的,可能與實際不符,僅供參數使用,切勿實際使用,否則后果自負
const Colour Const[16] = {black, blue, green, palegreen, red, purple, yellow, white, gray, light_blue, light_palegreen, light_red, light_purple, light_yellow, light_white};
double p[90] = {};
void GoToxy(int y, int x) {COORD  coord;coord.X = x;coord.Y = y;HANDLE a = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(a, coord);
}void color(int x) {int typeface = x / 16, background = x % 16;char command_typeface[2], command_background[2];string command = "color ";string change = "0123456789abcdef";command = command + change[typeface] + change[background];char cmd[9];for (int i = 0; i < 9; i++)cmd[i] = command[i];system(cmd);
}
void setcolor(Colour x, Colour y) {int i, j;for (i = 0; i < 16; i++)if (x == Const[i])break;for (j = 0; j < 16; j++)if (y == Const[j])break;color(i + y * 16);
}
int random() {int a[6], k = 0;for (int i = 0; i < 6; ++i)a[i] = rand() % 10;for (int i = 0; i < 6; ++i)k = k * 10 + a[i];return k;
}
int mxxwdgd, mxxggd, mxxple;
void Play(bool ggg) {system("cls");if (ggg == 0) {setcolor(purple, white);} else {setcolor(black, yellow);}int i, j, k;for (i = 1; i <= 20; i++) {GoToxy(i, i + 20) ;printf("\\");Sleep(40);if (ggg == 1)Sleep(15);}i = 20, j = 50, k = 1;int r = 1;if (ggg == 1)for (; r <= 10; r += k, ++k) {GoToxy(i - r, i + 20 - r);for (int i1 = i - r; i1 <= i + r; ++i1)printf("_");for (int i1 = i - r + 1; i1 <= i + r - 1; ++i1) {GoToxy(i1, i + 20 - r);printf("|");GoToxy(i1, i + 20 + r);printf("|");}GoToxy(i + r, i + 20 - r);for (int i1 = i - r; i1 <= i + r; ++i1)printf("_");Sleep(55);}system("cls");setcolor(white, black);
}
void read() {freopen("ouhuang.txt", "r", stdin);scanf("%d %d %d", &mxxwdgd, &mxxggd, &mxxple);fclose(stdin);
}
void putt(int waidegold, int ggold, int pple) {freopen("ouhuang.txt", "w", stdout);printf("%d %d %d", waidegold, ggold, pple);fclose(stdout);
}
void save(int waidegold, int ggold, int pple) {read();printf("RECORD: waide:%d not:%d ple:%d\n", mxxwdgd, mxxggd, mxxple);if (ggold > mxxggd) {printf("NEW RECORD!!!\n");putt(waidegold, ggold, pple);Sleep(3000);}}
string changzhu[8] ;
string UP;
void READ() {freopen("text.txt", "r", stdin);cin >> UP;for (int i = 0; i <= 7; i++)cin >> changzhu[i];fclose(stdin);
}
void change() {freopen("text.txt", "w", stdout);string st;cin >> st;cout << st << endl;for (int i = 1; i <= 8; i++) {cin >> st;cout << st << endl;}fclose(stdout);
}
void read1() {freopen("data.txt", "r", stdin);char tmp[500];while (~scanf("%s", &tmp)) {DATA[++cnttt] = tmp;}fclose(stdin);
}
void data1(string stt) {freopen("data.txt", "w", stdout);Time s = gottime();printf("\n%d/%d/%d,%d:%d:%d\n", s.year, s.month, s.day, s.hour, s.minute, s.second);printf("%s\n", username.c_str());for (int i = 1; i <= cnttt; i++) {if (DATA[i] == ":" || DATA[i + 1] == ":")printf("%s", DATA[i].c_str());elseprintf("%s\n", DATA[i].c_str());}fclose(stdin);fclose(stdout);
}
int main() {for (int i = 1; i <= 72; ++i)p[i] = 0.006;p[73] = 0.01;p[74] = 0.05;p[75] = 0.21;p[76] = 0.3;p[77] = 0.33;p[78] = 0.36;p[79] = 0.40;p[80] = 0.5;p[81] = 0.6;p[82] = 0.7;p[83] = 0.8;p[84] = 0.82;p[85] = 0.9;p[86] = 0.95;p[87] = 0.989;p[88] = 0.999;p[89] = 0.999;p[90] = 1;printf("enter your name:");cin >> username;HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO CursorInfo;GetConsoleCursorInfo(handle, &CursorInfo);CursorInfo.bVisible = false;SetConsoleCursorInfo(handle, &CursorInfo);printf("For each time : 0.6%% for gold and 6%% for purple\n");printf("P(gold) will increase After 73 times until 90 to 100%\n");printf("10 purples , as well as 1 gold, provides another chance\n");system("pause");char kk = _getch();if (kk == 'c')change();int r, waidegold = 0, ggold = 0, pple = 0;READ();srand(time(0));int n, m, i, j, gold = 0, pp = 0, big = 0, cnt = 0, total = 30;while (cnt < total) {system("cls");printf("Press 1.10\n");printf("You've rolled %d times rest:%d\n", cnt * 10, (total - cnt) * 10);printf("WAI:%d GOLD:%d PP:%d\n", waidegold, ggold, pple);++cnt;char k;bool chu = 0;k = _getch();Sleep(5);for (i = 1; i <= 10; ++i) {int r = random();++gold, ++pp;if (r <= p[gold] *MAXX ) {total++;//goldPlay(1);chu = 1;if ((rand() % 2  ) && !big) {//waibig = 1;string tmp = changzhu[rand() % 8];printf("%d times 恭喜你歪%s了\n", gold, tmp.c_str());DATA[++cnttt] = username;DATA[cnttt]  += ( gold / 10 + '0');DATA[cnttt] += (gold % 10 + '0' );DATA[cnttt] += "times : ";DATA[cnttt] += tmp;//printf("DATA[%d]= %s\n", cnttt, DATA[cnttt].c_str());Sleep(2000);system("pause");waidegold++;} else {big = 0;printf("%d times %s\n", gold, UP.c_str());DATA[++cnttt] = username;DATA[cnttt]  += ( gold / 10 + '0');DATA[cnttt] += (gold % 10 + '0' );DATA[cnttt] += "times : ";DATA[cnttt] += UP;//printf("DATA[%d]= %s\n", cnttt, DATA[cnttt].c_str());Sleep(2000);system("pause");ggold++;}gold = 0;}if (r >= MAXX * 0.94 || pp == 10) {//purpleif (!chu)Play(0);chu = 1;printf("%d times a purple\n", pp);system("pause");pp = 0;pple++;if (pple % 10 == 0)total++;}}}read1();save(waidegold, ggold, pple);data1("\n");return 0;
}

點個贊再走吧~

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/75813.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/75813.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/75813.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

詳解相機的內參和外參,以及內外參的標定方法

1 四個坐標系 要想深入搞清楚相機的內參和外參含義&#xff0c; 首先得清楚以下4個坐標系的定義&#xff1a; 世界坐標系&#xff1a; 名字看著很唬人&#xff0c; 其實沒什么大不了的&#xff0c; 這個就是你自己定義的某一個坐標系。 比如&#xff0c; 你把房間的某一個點定…

學透Spring Boot — 011. 一篇文章學會Spring Test

系列文章目錄 這是學透Spring Boot的第11篇文章。更多系列文章請關注 CSDN postnull 用戶的專欄 文章目錄 系列文章目錄Spring Test的依賴Spring Test的核心功能SpringBootTest 加載Spring上下文依賴注入有問題時Spring配置有問題時 WebMvcTest 測試Web層&#xff08;Controll…

Mysql 數據庫編程技術01

一、數據庫基礎 1.1 認識數據庫 為什么學習數據庫 瞬時數據&#xff1a;比如內存中的數據&#xff0c;是不能永久保存的。持久化數據&#xff1a;比如持久化至數據庫中或者文檔中&#xff0c;能夠長久保存。 數據庫是“按照數據結構來組織、存儲和管理數據的倉庫”。是一個長…

新一代AI架構實踐:數字大腦AI+智能調度MCP+領域執行APP的黃金金字塔體系

新一代AI架構實踐&#xff1a;數字大腦智能調度領域執行的黃金金字塔體系 一、架構本質的三層穿透性認知 1.1 核心范式轉變&#xff08;CPS理論升級&#xff09; 傳統算法架構&#xff1a;數據驅動 → 特征工程 → 模型訓練 → 業務應用 新一代AI架構&#xff1a;物理規律建…

macOS可視化桌面配置docker加速器

macOS可視化桌面配置docker加速器 在鏡像settings->docker Engine改為國內鏡像修改為國內鏡像重啟docker(可視化界面啟動或者使用命令行)使用命令重啟可視化界面重啟 在鏡像settings->docker Engine改為國內鏡像 修改為國內鏡像 {"registry-mirrors": ["…

Nginx 基礎使用(2025)

一、Nginx目錄結構 [rootlocalhost ~]# tree /usr/local/nginx /usr/local/nginx ├── client_body_temp # POST 大文件暫存目錄 ├── conf # Nginx所有配置文件的目錄 │ ├── fastcgi.conf # fastcgi相…

用spring-webmvc包實現AI(Deepseek)事件流(SSE)推送

前后端&#xff1a; Spring Boot Angular spring-webmvc-5.2.2包 代碼片段如下&#xff1a; 控制層&#xff1a; GetMapping(value "/realtime/page/ai/sse", produces MediaType.TEXT_EVENT_STREAM_VALUE)ApiOperation(value "獲取告警記錄進行AI分析…

基于Python的招聘推薦數據可視化分析系統

【Python】基于Python的招聘推薦數據可視化分析系統&#xff08;完整系統源碼開發筆記詳細部署教程&#xff09;? 目錄 一、項目簡介二、項目界面展示三、項目視頻展示 一、項目簡介 &#x1f680;&#x1f31f; 基于Python的招聘推薦數據可視化分析系統&#xff01;&#x1…

使用注解開發springMVC

引言 在學習過第一個springMVC項目建造過后&#xff0c;讓我們直接進入真實開發中所必需的注解開發&#xff0c; 是何等的簡潔高效&#xff01;&#xff01; 注&#xff1a;由于Maven可能存在資源過濾的問題&#xff0c;在maven依賴中加入 <build><resources>&l…

linux專題3-----禁止SSH的密碼登錄

要在linux系統中禁止密碼登錄&#xff0c;您可以通過修改 SSH 配置來實現。請按照以下步驟操作(此處以 Ubuntu為例)&#xff1a; 1、SSH 登錄到您的服務器&#xff08;或直接在命令行模式下&#xff09;。 2、備份 SSH 配置文件&#xff1a; 在終端中運行以下命令以備份現有的…

基于LangChain和通義(Tongyi)實現NL2SQL的智能檢索(無需訓練)

在數據驅動的時代,如何高效地從數據庫中獲取信息成為了一個重要的挑戰。自然語言到SQL(NL2SQL)技術提供了一種便捷的解決方案,使用戶能夠用自然語言查詢數據庫,而無需深入了解SQL語法。本文將探討如何利用LangChain和通義(Tongyi)實現NL2SQL的智能檢索,具體步驟如下: …

深度學習處理文本(10)

保存自定義層 在編寫自定義層時&#xff0c;一定要實現get_config()方法&#xff1a;這樣我們可以利用config字典將該層重新實例化&#xff0c;這對保存和加載模型很有用。該方法返回一個Python字典&#xff0c;其中包含用于創建該層的構造函數的參數值。所有Keras層都可以被序…

機器視覺3D中激光偏鏡的優點

機器視覺的3D應用中,激光偏鏡(如偏振片、波片、偏振分束器等)通過其獨特的偏振控制能力,顯著提升了系統的測量精度、抗干擾能力和適應性。以下是其核心優點: 1. 提升3D成像精度 抑制環境光干擾:偏振片可濾除非偏振的環境雜光(如日光、室內照明),僅保留激光偏振信號,大…

線程同步的學習與應用

1.多線程并發 1).多線程并發引例 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <assert.h> #include <pthread.h>int wg0; void *fun(void *arg) {for(int i0;i<1000;i){wg;printf("wg%d\n",wg);} } i…

寫.NET可以指定運行SUB MAIN嗎?調用任意一個里面的類時,如何先執行某段初始化代碼?

VB.NET 寫.NET可以指定運行SUB MAIN嗎?調用任意一個里面的類時,如何先執行某段初始化代碼? 分享 1. 在 VB.NET 中指定運行 Sub Main 在 VB.NET 里&#xff0c;你能夠指定 Sub Main 作為程序的入口點。下面為你介紹兩種實現方式&#xff1a; 方式一&#xff1a;在項目屬性…

【AI插件開發】Notepad++ AI插件開發實踐(代碼篇):從Dock窗口集成到功能菜單實現

一、引言 上篇文章已經在Notepad的插件開發中集成了選中即問AI的功能&#xff0c;這一篇文章將在此基礎上進一步集成&#xff0c;支持AI對話窗口以及常見的代碼功能菜單&#xff1a; 顯示AI的Dock窗口&#xff0c;可以用自然語言向 AI 提問或要求執行任務選中代碼后使用&…

關聯容器-模板類pair數對

關聯容器 關聯容器和順序容器有著根本的不同:關聯容器中的元素是按關鍵字來保存和訪問的,而順序容器中的元素是按它們在容器中的位置來順序保存和訪問的。 關聯容器支持高效的關鍵字查找和訪問。 兩個主要的關聯容器(associative-container),set和map。 set 中每個元素只包…

京東運維面試題及參考答案

目錄 OSPF 實現原理是什么? 請描述 TCP 三次握手的過程。 LVS 的原理是什么? 闡述 Nginx 七層負載均衡的原理。 Nginx 與 Apache 有什么區別? 如何查看監聽在 8080 端口的是哪個進程(可舉例:netstat -tnlp | grep 8080)? OSI 七層模型是什么,請寫出各層的協議。 …

輸入框輸入數字且保持精度

在項目中如果涉及到金額等需要數字輸入且保持精度的情況下&#xff0c;由于輸入框是可以隨意輸入文本的&#xff0c;所以一般情況下可能需要監聽輸入框的change事件&#xff0c;然后通過正則表達式去替換掉不匹配的文本部分。 由于每次文本改變都會被監聽&#xff0c;包括替換…

使用 requests 和 BeautifulSoup 解析淘寶商品

以下將詳細解釋如何通過這兩個庫來實現按關鍵字搜索并解析淘寶商品信息。 一、準備工作 1. 安裝必要的庫 在開始之前&#xff0c;確保已經安裝了 requests 和 BeautifulSoup 庫。如果尚未安裝&#xff0c;可以通過以下命令進行安裝&#xff1a; bash pip install requests…