Created
November 8, 2018 16:48
-
-
Save Sotalbireo/95031bee9b27bea86282a0c7e744faeb to your computer and use it in GitHub Desktop.
This file contains 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> | |
#include <string.h> | |
#include <time.h> | |
#define TRUE 1 | |
#define FALSE 0 | |
#ifdef _WIN32 | |
#include <windows.h> | |
void _sleep(unsigned milliseconds) | |
{ | |
Sleep(milliseconds); | |
} | |
void clear(){system("cls");} | |
#else | |
#include <unistd.h> | |
void _sleep(unsigned milliseconds) | |
{ | |
usleep(milliseconds * 1000); | |
} | |
void clear(){system("clear");} | |
#endif | |
int help(void) | |
{ | |
puts("========= HELP =========\n"); | |
puts("このソフトウェアは「フラッシュ暗算」の体験ソフトウェアです。\n"); | |
puts("「フラッシュ暗算」とは、\n画面に順次表示されては消える複数の数字を暗算で足し続ける、\n計算能力育成カリキュラムのことです。"); | |
puts("ここでは、実際のフラッシュ暗算用ソフトウェアを参考に、\nフラッシュ暗算を体験することができます。\n"); | |
puts("====== Difficulty ======\n"); | |
puts("Easy -> 3 integers: from 1 to 10. Displayed speed is 500ms."); | |
puts("Normal -> 3 integers: from 1 to 100. Displayed speed is 1000ms."); | |
puts("Hard -> 5 integers: from 1 to 100. Displayed speed is 400ms."); | |
return 2; | |
} | |
void clearStdin(void) | |
{ | |
int c; | |
while(c=getchar() != '\n' && c != EOF){} | |
} | |
void countDown(int t) | |
{ | |
if(t>0) | |
{ | |
clear(); | |
printf("\n\n\t\t-%d-\n", t); | |
_sleep(1000); | |
countDown(--t); | |
} | |
} | |
void flashNum(int arr[], int int_N, int margin) | |
{ | |
int i; | |
for(i=0; i<int_N; ++i) | |
{ | |
printf("\n\n\t\t%3d\n", arr[i]); | |
_sleep(margin); | |
clear(); | |
puts("\n\n\t\t\t"); | |
_sleep(margin/3); | |
clear(); | |
} | |
} | |
int flashSumApp(int int_N, int max_val, int margin) | |
{ | |
int question[5]={0,0,0,0,0}; | |
int i; | |
int ans=0; | |
int input; | |
for(i=0;i<int_N;++i) | |
{ | |
question[i]= (rand()%max_val) +1; | |
ans += question[i]; | |
} | |
clear(); | |
puts("※ 下の「xxx」の辺りに数字が出ます ※"); | |
puts("\n\t\txxx"); | |
_sleep(4000); | |
countDown(3); | |
clear(); | |
flashNum(question, int_N, margin); | |
puts("\n\n\t\t"); | |
_sleep(1000); | |
clear(); | |
puts("the sum ?"); | |
printf("-> "); | |
scanf("%d", &input); | |
clearStdin(); | |
if(input == ans) | |
{ puts("Rights!");} | |
else | |
{ puts("Wrong!");}; | |
puts("\nAnswer:"); | |
for(i=0;i<int_N;++i) | |
{ | |
printf("%d", question[i]); | |
if(i!=int_N-1){ printf(" + ");}; | |
} | |
printf(" = %d\n", ans); | |
return 0; | |
} | |
int flashSumMain(void) | |
{ | |
int mode; | |
clear(); | |
printf("Difficulty?\n- Easy : type '1'.\n- Normal : type '2'.\n- Hard : type '3'.\n\n- HELP : type '0'.\n-> "); | |
mode = getchar(); | |
clearStdin(); | |
switch(mode) | |
{ | |
case 49: // '1' | |
return flashSumApp(3, 10, 500); | |
case 50: // '2' | |
return flashSumApp(3, 100, 1000); | |
case 51: // '3' | |
return flashSumApp(5, 100, 400); | |
case 48: // '0' | |
return help(); | |
default: | |
puts("Invalid Input."); | |
puts("Please Relaunch this and Retype valid Input.\n\nThanks."); | |
return 2; | |
} | |
} | |
int main(void) | |
{ | |
int flag; | |
srand((unsigned)time(NULL)); | |
do | |
{ | |
flag= flashSumMain(); | |
if(flag == 0) | |
{ | |
puts("\nAre you continue? (y/n)"); | |
printf("-> "); | |
flag = getchar(); | |
clearStdin(); | |
switch(flag) | |
{ | |
case 89: // 'Y' | |
case 121: // 'y' | |
flag = TRUE; | |
break; | |
case 78: // 'N' | |
case 110: // 'n' | |
flag = FALSE; | |
puts("Thank you for playing!"); | |
break; | |
default : | |
flag = FALSE; | |
break; | |
} | |
} | |
}while(flag == TRUE); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment