問題に正解した時に表示する画像が2回に一回だけしか設定したとおり表示されません。
画像を1秒表示するよう設定しているのですが、2回に一回は一瞬だけ表示して処理が次へ進んでしまいます。
#include "DxLib.h"
#include "キーボードモジュール.h"
#include <math.h>
#include "問題用乱数生成.h"
#include "問題の表示.h"
int ketteion;//キー操作音格納変数
int sentakuon[1];//キー操作音格納変数
int count;//カウンター
int i;
int Ready;//レベルごとの開始待機用
int G_Lv[6];//レベル表示の画像
int anntenn;//暗転用画像
int taitoru;//タイトル画面の画像
int a[5] = {250,300,350,400,450};//矢印の座標格納
int houkouKey;//矢印の画像
int gameover;//ゲームオーバーの画像格納変数
int HP;//ライフゲージの画像格納変数(未使用)
int d;//選択番号
int mode;/*現在のゲームモード*/
int LvQ;//乱数格納
int time;//画像の表示時間
int keta;
int keta2;
int furagu[2];//判定用変数
int LvA;//キーボードからの数値を格納し、成否を判定する
int stage;//ステージの判定変数
int LIFE=3;//残りのHP
int TRUE_A;//正解の画像格納変数
int NO_A;//不正解の画像格納変数
int KeyIn;//キー入力ハンドル
void taitoru_syokika()
{
Ready=LoadGraph("画像/レディ?.png");
taitoru = LoadGraph("画像/無題.png");
houkouKey = LoadGraph("画像/方向キー右.png");
sentakuon[0]=LoadSoundMem("効果音/キー移動音.ogg");
ketteion=LoadSoundMem("効果音/決定音.ogg");
anntenn=LoadGraph("画像/暗転.png");
G_Lv[0]=LoadGraph("画像/レベル0.png");
G_Lv[1]=LoadGraph("画像/レベル1.png");
G_Lv[2]=LoadGraph("画像/レベル2.png");
G_Lv[3]=LoadGraph("画像/レベル3.png");
G_Lv[4]=LoadGraph("画像/レベル4.png");
G_Lv[5]=LoadGraph("画像/レベル5.png");
TRUE_A=LoadGraph("画像/正解.png");
NO_A=LoadGraph("画像/失敗.png");
gameover=LoadGraph("画像/ゲームオーバー.png");
HP=LoadGraph("画像/ライフ.png");
furagu[2]=1;//最初のレベルを1に設定
}
void taitoru_enzan()
{
if(Keyboard_Get(KEY_INPUT_DOWN) == 1)
{
d = (d + 1 ) % 5 ;/*下が押されたら選択番号を下げる*/
PlaySoundMem(sentakuon[0],DX_PLAYTYPE_BACK,TRUE);
}
if(Keyboard_Get(KEY_INPUT_UP)== 1 )
{
d = (d + 4 ) % 5;//上が押されたら選択番号を上げる
PlaySoundMem(sentakuon[0],DX_PLAYTYPE_BACK,TRUE);
}
if(Keyboard_Get(KEY_INPUT_RETURN)==1 && d==0)
{
PlaySoundMem(ketteion,DX_PLAYTYPE_BACK,TRUE);
mode=1;
}
if(Keyboard_Get(KEY_INPUT_RETURN)==1 && d==1)
{
mode=26;
}
if(Keyboard_Get(KEY_INPUT_RETURN)==1 && d==3)
{
mode=27;
}
}
void taitoru_byouga()
{
DrawGraph( 0, 0, taitoru,TRUE);
DrawFormatString( 400,250,GetColor(255,255,255),"ゲームスタート");
DrawFormatString( 400,300,GetColor(255,255,255),"記録回覧");//未実装
DrawFormatString( 400,350,GetColor(255,255,255),"ヘルプ");//未実装
DrawFormatString( 400,400,GetColor(255,255,255),"設定");//未実装
DrawFormatString( 400,450,GetColor(255,255,255), "ゲーム終了");
DrawGraph(383,a[d],houkouKey,TRUE);//方向キーを選択番号に対応
} //画像の描画
void GameMain_answer1()
{
if(count==0)
{
KeyIn=MakeKeyInput(keta2,FALSE,TRUE,TRUE);//キー入力ハンドル作成
SetActiveKeyInput(KeyIn);//キー入力をアクティブにする。
}
count++;
//キーの入力が終了している場合は成否の判定に移る
if( CheckKeyInput( KeyIn ) != 0 )
{
mode=4;
}
// 画面の初期化
ClearDrawScreen() ;
DrawFormatString( 230,200,GetColor(255,255,255),"4桁の数字を入力してください");
// 入力モードを描画
DrawKeyInputModeString( 300, 230 ) ;
// 入力途中の文字列を描画
DrawKeyInputString( 300 , 240 , KeyIn ) ;
}
void GameMain_A1()
{
LvA = GetKeyInputNumber( KeyIn );//キー入力内容を判定用変数
if( LvA == LvQ )/*正解*/
{
count++;
DrawGraph( 0 , 0 , TRUE_A , TRUE );
//正解の画像を一秒表示加算するまで繰り返し
if( count > 60 )
{
stage=stage+1;//正解数加算
if( stage == 3 )//三回正解したら
{
DeleteKeyInput(KeyIn);//キーデータ内容を初期化
count=0;//カウンターを初期化
mode=1;//レベル振り分けクラスに戻る
}
else
{
DeleteKeyInput(KeyIn);//キーデータ内容を初期化
count=0;//カウンターの初期化
mode=2;//もう一度出題
}
}
}
else/*不正解*/
{
count++;
DrawGraph( 0 , 0 , NO_A , TRUE );
//不正解の画像を一秒表示加算するまで繰り返し
if( count >= 60 )
{
LIFE= LIFE-1;//ライフゲージを1減らす。
if( LIFE == 0 )//ライフが0の場合
{
count=0;
mode=25;
}
else
{
count=0;
mode=2;
}
}
}
}
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定
taitoru_syokika();//画像処理
// while( 裏画面を表画面に反映, メッセージ処理, 画面クリア )
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 )
{
Keyboard_Update();//キーボードモジュールの読み込み
switch( mode )
{
case 0://タイトル画面
taitoru_enzan();
//タイトル画面の演算
if( Keyboard_Get ( KEY_INPUT_RETURN ) == 1 && d == 4 )
{
PlaySoundMem( ketteion , DX_PLAYTYPE_BACK , TRUE );
goto End;
}//ゲーム終了処理
taitoru_byouga();
//タイトル画面の表示
ScreenFlip();
//表画面と裏画面の反転
break;
case 1://各レベルへの振り分け。
count++;
//カウンター
DrawGraph( 0 , 0 , G_Lv[furagu[2]] , TRUE );
//レベルに対応した画像を表示
if(count==60)
{
count=0;//一秒表示したらカウンターを初期化
if(furagu[2]>=1){furagu[2]++;}
//レベルアップ
stage=0;//正解数初期化
if(furagu[2]==2)
{
time=60;/*問題の表示時間*/
keta=8999;/*出題の最大数の指定*/
keta2=4;/*出題の数の桁*/
mode=2;
}//レベル1
if(furagu[2]==3)
{
time=45;
keta=8999;
keta2=4;
mode=2;
}//レベル2
if(furagu[2]==4)
{
time=60;
keta=89999;
keta2=5;
mode=2;
}//レベル3
if(furagu[2]==5)
{
time=60;
keta=899999;
keta2=6;
mode=2;
}//レベル4
if(furagu[2]==6)
{
time=45;
keta=899999;
keta2=6;
mode=2;
furagu[2]=0;
}//レベル5
if(furagu[2]==0)
{
time=30;
keta=899999;
keta2=6;
mode=2;
}//最大レベル
}
ScreenFlip();
break;
case 2://出題処理
count++;
//カウンター
if(count==1)
{
LvQ = GameMain_GetRand(keta , keta2);
}//取得した乱数を変数に格納
if(count <= time)
{
GameMain_DisPlay(time,LvQ);
}//指定した時間まで問題を表示
if(count>=time)
{
count=0;//カウンターリセット
mode=3;//回答処理へ
}
ScreenFlip();
break;
case 3://回答入力
GameMain_answer1();
//入力変数
ScreenFlip();
break;
case 4://正否判定
GameMain_A1();
//回答の正否判定
ScreenFlip();
break;
case 25://ゲームオーバーの画面表示
DrawGraph(0,0,gameover,TRUE);
//ゲームオーバと表示
if(Keyboard_Get(KEY_INPUT_SPACE)==1)
{//スペースキーが押されたら
furagu[2]=1;//レベルを初期化
mode=0;//タイトル画面へ
}
ScreenFlip();
break;
}
}
End:
DxLib_End(); // DXライブラリ終了処理
return 0;
}
#include "DxLib.h"
static int count;
void GameMain_DisPlay(int time , int nunber)
{
count++;
//一秒たつまで問題を表示
if(count<=time)
{
DrawFormatString( 300 , 230 , GetColor ( 255 , 255 , 255 ) , "%d" , nunber );
}
//問題を表示し終わったらカウンターを初期化し、回答処理へ
if( count >= time )
{
count=0;
}
}
#include <math.h>
#include "DxLib.h"
static int Q_Rand;//レベルごとの問題の乱数を格納
static int Q_Rand_Or;
static int count;
int GameMain_GetRand(int keta,/*桁数*/ double keta2/*乱数の上限*/)
{
keta2 = keta2-1;
Q_Rand_Or = pow( 10 , keta2 );
Q_Rand = GetRand(keta);//最大数を指定した数字を取得
Q_Rand = Q_Rand_Or + Q_Rand ;
return Q_Rand;
}