どういう事かというと、AとBの道があり、キー1を押すと変数aが1になり、Aの道に進むのですが、その後キー2を押したら変数aが2になってしまい、Bの道に変わってしまいます。
これを防ぐために、変数が一度変わったら固定できるようにしたいんですが、可能でしょうか。
不可能 または難しいなら、可能でなるべく簡単な方法を教えて下さい。
#include "DxLib.h"
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定
ProcessMessage();
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 )
{
DrawFormatString( 0, 0, GetColor(255,255,255), "気付いたらあなたは白い部屋の中にいた。");
DrawFormatString( 0, 20, GetColor(255,255,255), "目の前には扉があるが開かない。窓もない。扉には北と書いてある。");
DrawFormatString( 0, 40, GetColor(255,255,255), "地面にはリンゴが一つ落ちている。食べますか?");
DrawFormatString( 0, 60, GetColor(255,255,255), "1で食べる 2で食べない");
if( CheckHitKey(KEY_INPUT_2 ))
{
a = 2;
}
if( a == 2 )
{
//食べない
DrawFormatString( 0, 80, GetColor(255,255,255),"リンゴを拾ってみると地面には「生まれる太陽に死を」と書かれていた。");
DrawFormatString( 0, 100, GetColor(255,255,255),"後ろには何もない。");
DrawFormatString( 0, 120, GetColor(255,255,255),"左右どちらに行って調べる?");
DrawFormatString( 0, 140, GetColor(255,255,255),"3で左 4で右");
if( CheckHitKey(KEY_INPUT_3 ))
{
b = 1;
}
if( b == 1 )
{
//左
DrawFormatString( 0, 160, GetColor(255,255,255),"左に進むと宝箱を見つけた。");
DrawFormatString( 0, 180, GetColor(255,255,255),"宝箱に「扉は0=360 僕は?」と書かれている。");
DrawFormatString( 0, 200, GetColor(255,255,255),"宝箱には鍵がかかっている。");
DrawFormatString( 0, 220, GetColor(255,255,255),"宝箱のパスワードは?");
if( d == 3 && e == 6 && f == 0 )
{
c = 1;
}
if( c == 1 )
{
//正解
DrawFormatString( 0, 240, GetColor(255,255,255),"宝箱が開き、中には鍵が入っていた。");
DrawFormatString( 0, 260, GetColor(255,255,255),"鍵を使って扉を開け、あなたは脱出した。~END~");
DrawFormatString( 0, 280, GetColor(255,255,255),"0キーで終了します。");
if( CheckHitKey(KEY_INPUT_0 ))
{
break;
}
}
else
{
c = 2;
}
if( c == 2 )
{
//ハズレ
DrawFormatString( 0, 240, GetColor(255,255,255),"パスワードが間違っていたようだ。");
DrawFormatString( 0, 260, GetColor(255,255,255),"天井から何かが降って来てあなたは死んだ。~GAME OVER~");
DrawFormatString( 0, 280, GetColor(255,255,255),"0キーで終了します。");
if( CheckHitKey(KEY_INPUT_0 ))
{
break;
}
}
}
else if( CheckHitKey(KEY_INPUT_4 ))
{
b = 2;
}
if ( b == 2 )
{
//右
DrawFormatString( 0, 160, GetColor(255,255,255),"右に進むとあなたは落とし穴に落ちてしまった。~GAME OVER~");
DrawFormatString( 0, 180, GetColor(255,255,255),"0キーで終了します。");
if( CheckHitKey(KEY_INPUT_0 ))
{
break;
}
}
}
else if( CheckHitKey(KEY_INPUT_1 ))
{
a = 1;
}
if( a == 1 )
{
//食べる
DrawFormatString( 0, 80, GetColor(255,255,255), "リンゴには毒が入っていてあなたは死んでしまった。~GAME OVER~");
DrawFormatString( 0, 100, GetColor(255,255,255), "0キーで終了します。");
if( CheckHitKey(KEY_INPUT_0 ))
{
break;
}
}
}
DxLib_End();
return 0;
}