C++抽卡模擬器的實(shí)現(xiàn)示例
近日在學(xué)校無聊,寫了個(gè)抽卡模擬器供大家娛樂。
代碼實(shí)現(xiàn)以下功能:抽卡界面,抽卡判定、動(dòng)畫播放、存檔。
1.抽卡界面及判定
技術(shù)有限,不可能做的和原神一樣精致。代碼如下(注:這不是完整代碼,別復(fù)制錯(cuò)了)
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++; //gold Play(1); chu = 1; if ((rand() % 2 ) && !big) { //wai big = 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) { //purple if (!chu) Play(0); chu = 1; printf("%d times a purple\n", pp); system("pause"); pp = 0; pple++; if (pple % 10 == 0) total++; } } }
2.存檔
包括時(shí)間獲取以及存儲(chǔ)結(jié)果
獲取時(shí)間:
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; }
存儲(chǔ):
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()); else printf("%s\n", DATA[i].c_str()); } fclose(stdin); fclose(stdout); }
對(duì)了,由于不是很信任rand(),自己造了一個(gè)隨機(jī)函數(shù)
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.動(dòng)畫播放
十分簡(jiǎn)陋。
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); }
就是這樣,完整代碼如下。使用教程
#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}; //注:有些是詞生造出來的,可能與實(shí)際不符,僅供參數(shù)使用,切勿實(shí)際使用,否則后果自負(fù) 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()); else printf("%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++; //gold Play(1); chu = 1; if ((rand() % 2 ) && !big) { //wai big = 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) { //purple if (!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; }
到此這篇關(guān)于C++抽卡模擬器的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)C++抽卡模擬器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解析C++中臨時(shí)對(duì)象的產(chǎn)生情況
臨時(shí)對(duì)象的產(chǎn)生和銷毀都是有成本的,都會(huì)影響程序的執(zhí)行性能和效率,所以如果能了解臨時(shí)對(duì)象產(chǎn)生的原因,就可以提升程序的性能和效率,下面小編就來和大家聊聊臨時(shí)對(duì)象產(chǎn)生的幾種情況吧2023-06-06C++利用鏈表模板類實(shí)現(xiàn)簡(jiǎn)易隊(duì)列
這篇文章主要為大家詳細(xì)介紹了C++利用鏈表模板類實(shí)現(xiàn)一個(gè)簡(jiǎn)易隊(duì)列,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12C語言實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能(1)
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能的第一部分,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02C語言popen函數(shù)調(diào)用其他進(jìn)程返回值示例詳解
這篇文章主要為大家介紹了C語言popen函數(shù)調(diào)用其他進(jìn)程返回值示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09GCC 編譯使用動(dòng)態(tài)鏈接庫和靜態(tài)鏈接庫的方法
根據(jù)鏈接時(shí)期的不同,庫又有靜態(tài)庫和動(dòng)態(tài)庫之分,有別于靜態(tài)庫,動(dòng)態(tài)庫的鏈接是在程序執(zhí)行的時(shí)候被鏈接的2013-03-03C語言中初始、增加和刪除進(jìn)程信號(hào)的操作方法簡(jiǎn)介
這篇文章主要介紹了C語言中初始、增加和刪除進(jìn)程信號(hào)的操作方法簡(jiǎn)介,分別是sigemptyset函數(shù)、sigaddset函數(shù)和sigdelset函數(shù)的用法,需要的朋友可以參考下2015-09-09C語言基于EasyX庫實(shí)現(xiàn)有圖形界面時(shí)鐘
這篇文章主要為大家詳細(xì)介紹了C語言基于EasyX庫實(shí)現(xiàn)有圖形界面時(shí)鐘,獲得本地時(shí)間,輸出文字,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03C/C++標(biāo)準(zhǔn)庫之轉(zhuǎn)換UTC時(shí)間到local本地時(shí)間詳解
最近遇到一個(gè)問題:數(shù)據(jù)庫中存放的時(shí)間為UTC時(shí)間,但是現(xiàn)在要求都出來顯示的時(shí)間為本地時(shí)間,所以就用C++實(shí)現(xiàn)了,下面這篇文章主要給大家介紹了關(guān)于C/C++標(biāo)準(zhǔn)庫之轉(zhuǎn)換UTC時(shí)間到local本地時(shí)間的方法,還有C++中獲取UTC時(shí)間精確到微秒的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2017-11-11