簡易音游底力練習(xí)器 C++ 自帶樓梯板(Version 5)
/*
第一次修改優(yōu)化了隨機(jī)數(shù),代碼見 https://www.bilibili.com/read/cv11974105
第二次修改修復(fù)了輸出錯(cuò)誤,代碼已刪除。
第三次修改做到了下落式,代碼已刪除。
第四次修改修復(fù)了刷新屏幕時(shí)閃爍以及時(shí)間和規(guī)定時(shí)間內(nèi)擊中數(shù)量顯示不正確的Bug。
Version4.1修復(fù)了位置四為空的問題。
Version5 自帶樓梯,從樓梯和隨機(jī)打勾內(nèi)隨機(jī)查找。
類似于別踩白塊禪模式,20秒電腦版。
推薦編譯器(編輯器):Dev-C++(下載頁面:https://lanzoux.com/imXG3gpfjej)
Dev-C++備用下載頁面: https://lanzoui.com/imXG3gpfjej
Dev-C++適用于Windows7-64Bit以上。若您是XP系統(tǒng)請使用VC6.0以上。
僅限Bilibili,轉(zhuǎn)載請?zhí)崆八叫盼?二次開發(fā)不算)
*/
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <windows.h>
using namespace std;
void gotoxy(short x, short y) {
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int main() {
system("color 7a");
cout << "請按照屏幕上的字符\"√\"按下鍵盤按鍵(1:D,2:f,3:J,4:K)\n按任意鍵開始游戲\n";
int t = 0;
getch();
system("cls");
int d = 0;
time_t start = time(0);
srand(time(0));
int Miss = 0, Tap = 0, b[2][8], ran, t1 = 0;
for (int i = 0; i <= 7; i++) {
for (int j = 0; j <= 1; j++) {
b[j][i] = 4;
}
}
b[0][0] = 0;
b[0][1] = 1;
b[0][2] = 2;
b[0][3] = 3;
b[0][4] = 1;
b[0][5] = 3;
b[0][6] = 1;
b[0][7] = 2;
for (int i = 0; i <= 7; i++) {
b[1][i] = rand() % 4;
}
char a[4] = {'d', 'f', 'j', 'k'}, c;
while (time(0) - start <= 20) {
if (t1 % 8 == 0) {
ran = rand() % 2;
t1 = 0;
}
for (int i = 0; i <= 7; i++) {
switch (b[ran][i]) {
case 0:
cout << "√ × × ×\n";
break;
case 1:
cout << "× √ × ×\n";
break;
case 2:
cout << "× × √ ×\n";
break;
case 3:
cout << "× × × √\n";
break;
}
}
c = getch();
Tap++;
if (ran == 1 && c == a[b[1][7]]) {
Tap++;
b[1][7] = b[1][6];
b[1][6] = b[1][5];
b[1][5] = b[1][4];
b[1][4] = b[1][3];
b[1][3] = b[1][2];
b[1][2] = b[1][1];
b[1][1] = b[1][0];
b[1][0] = rand() % 4;
gotoxy(0, 0);
} else if (ran == 0 && c == a[b[0][7]]) {
Tap++;
t = b[0][7];
b[0][7] = b[0][6];
b[0][6] = b[0][5];
b[0][5] = b[0][4];
b[0][4] = b[0][3];
b[0][3] = b[0][2];
b[0][2] = b[0][1];
b[0][1] = b[0][0];
b[0][0] = t;
gotoxy(0, 0);
} else {
d = time(0) - start;
system("cls");
break;
}
gotoxy(0, 0);
t1++;
}
system("cls");
if (d == 0) {
cout << "擊中:" << Tap - 1 << " 耗時(shí)約20\"";
} else {
cout << "您擊錯(cuò)了。\n擊中:" << Tap << " 耗時(shí)約" << d << '\"';
}
getch();
getch();
}