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