Created
June 11, 2015 09:50
-
-
Save HaruhiroTakahashi/5937ceaa03ea37d20e6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*========================================== | |
タイピングゲーム | |
==========================================*/ | |
#include"stdio.h" | |
#include"stdlib.h" //画面クリア「system("cls")」・乱数発生「rand()」で使用 | |
#include"conio.h" //キー入力の「_getch()」などで使用 | |
#include"time.h" //時間を調べる「time()」を乱数の命令と一緒に使用 | |
void timer(void); | |
int main(){ | |
int key = 0; //入力されたキーを保存 | |
int ran = 0; //乱数を保存 | |
int i = 0; | |
int count = 0; | |
int score = 0; | |
int mistake = 0; | |
//<<<<<<<<<<<<<<<アルファベット26文字分の乱数発生処理>>>>>>>>>>>>>>>> | |
for (count = 10; count > 0; count--){ | |
srand((unsigned)time(NULL)); | |
ran = (rand() % 26); | |
system("cls"); | |
printf("得点%d点 ミス%d回 残り%d回", score, mistake, count); | |
printf("\n"); | |
/* | |
* a~z の文字コードは 97~122番 | |
* 97 + ran(0~25)でアルファベットを判断 | |
* 例:97 + 3 = 100 → [ d ] | |
*/ | |
for (i = 0; i < 80; i++){//画面端まで80文字分のアルファベットを表示 | |
printf("%c", (97 + ran)); | |
timer(); | |
if (_kbhit()){//途中でキー入力があれば上の表示をやめる | |
key = _getch(); | |
if (key == 0 || key == 224)key = getch(); | |
break; | |
} | |
} | |
if (key == (ran + 97)){ | |
score++; | |
} | |
else{ | |
mistake++; | |
} | |
} | |
system("cls"); | |
printf("結果\n"); | |
printf("得点%d点 ミス%d点 残り回数%d回\n", score, mistake, count); | |
printf("おしまい\n"); | |
return 0; | |
} | |
void timer(){ | |
int i, j; | |
for (i = 0; i < 3000; i++){ | |
for (j = 0; j < 3000; j++){ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment