Created
May 19, 2022 06:38
-
-
Save seya128/fe928d04631f311eeacfbad465c06dc9 to your computer and use it in GitHub Desktop.
C言語サンプル 出席番号ルーレット
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
/* | |
チーム名: | |
メンバー: 瀬谷 | |
タイトル: 出席番号ルーレット | |
内容: | |
画面上にランダムで1~17までの変化する数値を表示。 | |
[a]キーでストップ。 | |
[s]キーでスタート。 | |
*/ | |
#include <stdio.h> | |
#include <conio.h> | |
#include <Windows.h> | |
#include <stdlib.h> | |
void cursor(int x, int y); | |
int keyin(void); | |
int random(int max); | |
int main(void) | |
{ | |
int ch; | |
int stop_flag = 0; /* 0:回転中 1:停止中 */ | |
/* | |
* Visual Studio 2019の「F5」で動かすと動くけど、 | |
* 作成されたexeを起動するとエスケープシーケンスが動かない対策 | |
*/ | |
HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE); | |
DWORD consoleMode = 0; | |
GetConsoleMode(stdOut, &consoleMode); | |
consoleMode = consoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING; | |
SetConsoleMode(stdOut, consoleMode); | |
while (1) { | |
ch = keyin(); | |
if (ch == 'a') { | |
stop_flag = 1; | |
} | |
if (ch == 's') { | |
stop_flag = 0; | |
} | |
if (stop_flag == 0) { | |
cursor(10, 10); | |
printf("%2d\n", random(17) + 1); | |
} | |
Sleep(10); | |
} | |
return 0; | |
} | |
void cursor(int x, int y) | |
{ | |
printf("\033[%d;%dH", y, x); | |
} | |
int keyin(void) | |
{ | |
int ch; | |
if (_kbhit() != 0) { | |
ch = _getch(); | |
} | |
else { | |
ch = 0; | |
} | |
return ch; | |
} | |
int random(int max) | |
{ | |
int r; | |
r = rand() % max; | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment