Created
November 5, 2020 05:56
-
-
Save Colk-tech/5db9c1d905e0973861abebca490fb221 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
int main(void) { | |
int is_cpu_turn; | |
int default_fingers; | |
int game_end_flag = 0; | |
int user_left_fingers; | |
int user_raise_fingers; | |
int user_declared_number; | |
int cpu_left_fingers; | |
int cpu_raise_fingers; | |
int cpu_declared_number; | |
srand((unsigned) time(NULL)); | |
printf(" ■ \n" | |
"■■ ■■ ■ ■ \n" | |
" ■ ■ ■ \n" | |
" ■ ■ ■ ■■ ■■■■■ ■ ■■■■ ■ ■■ ■■■■ ■■ ■■■ \n" | |
" ■■■■ ■ ■■ ■■ ■■ ■ ■ ■ ■■ ■■ ■■ ■ ■ ■\n" | |
" ■■ ■ ■■ ■ ■ ■ ■ ■ ■■ ■ ■ ■ ■\n" | |
" ■■ ■ ■■ ■ ■ ■ ■■ ■ ■■ ■ ■ ■ ■■■■■\n" | |
" ■■ ■ ■■ ■ ■ ■ ■ ■ ■■ ■ ■ ■ ■ ■\n" | |
" ■■ ■■ ■■ ■■ ■■ ■ ■ ■ ■■ ■■ ■ ■ ■ ■ ■■\n" | |
" ■■ ■■■■■ ■ ■■■ ■ ■■■■ ■■■■■ ■ ■ ■ ■■■■■\n"); | |
BLANK; | |
printf("指スマへようこそ!\n"); | |
printf("まず、指を何本立てるかを決めてね!\n"); | |
while (1) { | |
scanf("%d", &default_fingers); | |
if (1 <= default_fingers && default_fingers <= 5) { | |
break; | |
} | |
printf("指は1〜5本の間で指定してね!\n"); | |
} | |
user_left_fingers = default_fingers; | |
cpu_left_fingers = default_fingers; | |
printf("%d本が選択されました!\n", default_fingers); | |
BLANK; | |
is_cpu_turn = rand() % 2; | |
if (is_cpu_turn) { | |
printf("CPUが先行です!\n"); | |
} else { | |
printf("あなたが先行です!\n"); | |
} | |
BLANK; | |
while (1) { | |
if (is_cpu_turn) { | |
SEPARATION; | |
printf("CPUが数を言うターンです\n"); | |
printf("あなたの残り本数: %d本, CPUの残り本数: %d本\n", user_left_fingers, cpu_left_fingers); | |
user_raise_fingers = ask_how_many_fingers_to_raise(user_left_fingers); | |
cpu_raise_fingers = decide_how_many_fingers_to_raise(cpu_left_fingers); | |
cpu_declared_number = decide_how_many_fingers_to_declare(user_left_fingers, cpu_raise_fingers); | |
printf("あなたが立てた指: %d本, CPUが立てた指: %d本, CPUが言った数: %d\n", user_raise_fingers, cpu_raise_fingers, cpu_declared_number); | |
if (user_raise_fingers + cpu_raise_fingers == cpu_declared_number) { | |
printf("CPUが的中させました!\n"); | |
cpu_left_fingers = cpu_left_fingers - 1; | |
} | |
printf("あなたの残り本数: %d本, CPUの残り本数: %d本\n", user_left_fingers, cpu_left_fingers); | |
is_cpu_turn = 0; | |
SEPARATION; | |
BLANK; | |
} else { | |
SEPARATION; | |
printf("あなたが数を言うターンです\n"); | |
printf("あなたの残り本数: %d本, CPUの残り本数: %d本\n", user_left_fingers, cpu_left_fingers); | |
user_raise_fingers = ask_how_many_fingers_to_raise(user_left_fingers); | |
cpu_raise_fingers = decide_how_many_fingers_to_raise(cpu_left_fingers); | |
user_declared_number = ask_how_many_fingers_to_declare(); | |
printf("あなたが立てた指: %d本, CPUが立てた指: %d本, あなたが言った数: %d\n", user_raise_fingers, cpu_raise_fingers, user_declared_number); | |
if (user_raise_fingers + cpu_raise_fingers == user_declared_number) { | |
printf("的中!\n"); | |
user_left_fingers = user_left_fingers - 1; | |
} | |
printf("あなたの残り本数: %d本, CPUの残り本数: %d本\n", user_left_fingers, cpu_left_fingers); | |
is_cpu_turn = 1; | |
SEPARATION; | |
BLANK; | |
} | |
if (user_left_fingers <= 0 || cpu_left_fingers <= 0) { | |
break; | |
} | |
} | |
return 0; | |
} | |
int ask_how_many_fingers_to_raise(int user_left_fingers) { | |
int user_raise_fingers; | |
printf("指を何本立てる?\n"); | |
while (1) { | |
scanf("%d", &user_raise_fingers); | |
if (0 <= user_raise_fingers && user_raise_fingers <= user_left_fingers) { | |
break; | |
} | |
printf("指は0〜%d本の間で指定してね!\n", user_left_fingers); | |
} | |
return user_raise_fingers; | |
} | |
int decide_how_many_fingers_to_raise(int cpu_left_fingers) { | |
int cpu_raise_fingers; | |
cpu_raise_fingers = rand() % cpu_left_fingers; | |
return cpu_raise_fingers; | |
} | |
int ask_how_many_fingers_to_declare() { | |
printf("いっせーので!\n"); | |
int user_declared_number; | |
scanf("%d", &user_declared_number); | |
return user_declared_number; | |
} | |
int decide_how_many_fingers_to_declare(int user_left_fingers, int cpu_raise_fingers) { | |
int sum_of_left_fingers = user_left_fingers + cpu_raise_fingers; | |
int cpu_declared_number; | |
cpu_declared_number = (rand() % (sum_of_left_fingers + 1)); | |
printf("いっせーので!\n"); | |
printf("%d\n", cpu_declared_number); | |
return cpu_declared_number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment