c++タイピングゲーム

11026 ワード

#include 
#include 
#include 
#include 
#include 
using namespace std;
//       、    、    
char RandomChar()
{
    int type = rand() % 3;
    if (type == 0)
    {
        return rand() % 10 + '0';
    }
    if (type == 1)
    {
        return rand() % 26 + 'A';
    }
    return rand() % 26 + 'a';
}
//         (x,y) 。
void gotoxy(int x, int y)
{
    CONSOLE_SCREEN_BUFFER_INFO cs;
    HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsoleOut, &cs);
    cs.dwCursorPosition.X = y;
    cs.dwCursorPosition.Y = x;
    SetConsoleCursorPosition(hConsoleOut,
        cs.dwCursorPosition);
}

int main()
{

    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);//        ,          

    cout << "    :
"
; cout << " , , ,

"
; cout << "

"
; getch(); cout << "
"
; getch(); system("cls");// bool again = 1;// while (again) { srand((unsigned int)time(NULL));// int x[100];// x int y[100];// y char target[100];// int score = 0;// cout << " :
"
; cout << "1:" << " " << endl; cout << "2:" << " " << endl; cout << "3:" << " " << endl; cout << "4:" << " " << endl; cout << "5:" << " " << endl; cout << endl; int n; cin >> n; system("cls");// gotoxy(0, 55);// cout << " :" << score; SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_INTENSITY); // gotoxy(20 - 2 * n, 0);// cout << "------- --------------- ------------------ -------" << endl; SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY); // for (int i = 1; i <= 2 * n; i++) { x[i] = 0; y[i] = rand() % 50; } for (int i = 1; i <= 2 * n; i++) { target[i] = RandomChar(); } bool gameOver = 0;// while (gameOver == 0) { while (!kbhit()) // { for (int i = 1; i <= 2 * n; i++) { gotoxy(x[i], y[i]); cout << target[i]; x[i]++; if (x[i] == 20 - 2 * n) // { gameOver = 1; } } Sleep(1000 - n * 100);// for (int i = 1; i <= 2 * n; i++) { gotoxy(x[i] - 1, y[i]); cout << ' ';// } if (gameOver) { break; } } if (gameOver)// , , , { break; } char userHit = getch(); for (int i = 1; i <= 2 * n; i++) { if (target[i] == userHit)// { score++; gotoxy(0, 65); cout << score; gotoxy(x[i], y[i]); cout << ' ';// // x[i] = 0; y[i] = rand() % 50; target[i] = RandomChar(); } } } SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); // gotoxy(20 - 2 * n + 2, 0); cout << " , !
:"
; SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY); // cout << score; SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); // cout << "

? Y/N
"
; string str; cin >> str; if (str == "N" || str == "n") { cout << " ,
"
; break; } else { system("cls");// } } return 0; }