#2
by みけCAT » 5年前
入力を読み込む前にClearInputCharBuf()を呼んでいるため、キー入力のデータが消されてしまい、
入力を検出できなくなっているようです。
従って、この関数の呼び出しを削除するといいと思います。
動作確認したコード (DXライブラリ Ver3.17a)
コード:
#include <DxLib.h>
#define STR_MAX 1024
#define QUIZ_MAX 1024
#define STR_MAX 1024
#define WINDOW_X 640
#define WINDOW_Y 480
int MainFont;
int White;
void ShapeRotation() {
static unsigned int t = 0;
DrawFormatString(10, 10, GetColor(0, 255, 0), "%u", t++);
}
char in;
char typ[STR_MAX] = "";
char ans[QUIZ_MAX][STR_MAX] ={
"kouennniikimasita",
"anatahasuzukisandesuka",
"kyouhamokuyoubinanodarouka"
};
int pos = 0;
int NowQuiz=0;
void GetKey(){
//ClearInputCharBuf();
//in = GetInputCharWait(TRUE);
in = GetInputChar(TRUE);
//入力があれば
if( in >= CTRL_CODE_CMP ){
//同じであれば
if(in == ans[NowQuiz][pos]){
typ[pos] = in;
pos++;
}
}
if(ans[NowQuiz][pos] == '\0'){
NowQuiz++;
pos=0;
for(int i=0; i < STR_MAX; i++)
typ[i]=0;
if(NowQuiz >= QUIZ_MAX) NowQuiz=0;
}
}
void Draw(){
ShapeRotation();
DrawFormatStringToHandle(
WINDOW_X/2 - GetDrawFormatStringWidthToHandle(MainFont,"%s",ans[NowQuiz])/2,
WINDOW_Y/2,White,MainFont,"%s",ans[NowQuiz]);
DrawFormatStringToHandle(
WINDOW_X/2 - GetDrawFormatStringWidthToHandle(MainFont,"%s",typ)/2,
WINDOW_Y/2+80,White,MainFont,"%s",typ);
}
void Typing(){
GetKey();
Draw();
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
if (ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() != 0) return -1;
MainFont = CreateFontToHandle(NULL, -1, -1, -1);
White = GetColor(255, 255, 255);
SetDrawScreen(DX_SCREEN_BACK);
while (ProcessMessage() == 0 && ClearDrawScreen() == 0) {
Typing();
ScreenFlip();
}
DxLib_End();
return 0;
}
入力を読み込む前にClearInputCharBuf()を呼んでいるため、キー入力のデータが消されてしまい、
入力を検出できなくなっているようです。
従って、この関数の呼び出しを削除するといいと思います。
動作確認したコード (DXライブラリ Ver3.17a)
[code]
#include <DxLib.h>
#define STR_MAX 1024
#define QUIZ_MAX 1024
#define STR_MAX 1024
#define WINDOW_X 640
#define WINDOW_Y 480
int MainFont;
int White;
void ShapeRotation() {
static unsigned int t = 0;
DrawFormatString(10, 10, GetColor(0, 255, 0), "%u", t++);
}
char in;
char typ[STR_MAX] = "";
char ans[QUIZ_MAX][STR_MAX] ={
"kouennniikimasita",
"anatahasuzukisandesuka",
"kyouhamokuyoubinanodarouka"
};
int pos = 0;
int NowQuiz=0;
void GetKey(){
//ClearInputCharBuf();
//in = GetInputCharWait(TRUE);
in = GetInputChar(TRUE);
//入力があれば
if( in >= CTRL_CODE_CMP ){
//同じであれば
if(in == ans[NowQuiz][pos]){
typ[pos] = in;
pos++;
}
}
if(ans[NowQuiz][pos] == '\0'){
NowQuiz++;
pos=0;
for(int i=0; i < STR_MAX; i++)
typ[i]=0;
if(NowQuiz >= QUIZ_MAX) NowQuiz=0;
}
}
void Draw(){
ShapeRotation();
DrawFormatStringToHandle(
WINDOW_X/2 - GetDrawFormatStringWidthToHandle(MainFont,"%s",ans[NowQuiz])/2,
WINDOW_Y/2,White,MainFont,"%s",ans[NowQuiz]);
DrawFormatStringToHandle(
WINDOW_X/2 - GetDrawFormatStringWidthToHandle(MainFont,"%s",typ)/2,
WINDOW_Y/2+80,White,MainFont,"%s",typ);
}
void Typing(){
GetKey();
Draw();
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
if (ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() != 0) return -1;
MainFont = CreateFontToHandle(NULL, -1, -1, -1);
White = GetColor(255, 255, 255);
SetDrawScreen(DX_SCREEN_BACK);
while (ProcessMessage() == 0 && ClearDrawScreen() == 0) {
Typing();
ScreenFlip();
}
DxLib_End();
return 0;
}
[/code]