じゃんけんゲームを作っているのですが・・

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
アバター
エルフ
記事: 79
登録日時: 9年前
住所: 埼玉

じゃんけんゲームを作っているのですが・・

#1

投稿記事 by エルフ » 9年前

どうしても直らない事が2つあります
1.Voice2の音が再生されない
2.2キーと3キーを押しても反応がない

どうしたら改善されますか?
以下ソース

コード:

#include "DxLib.h"

int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int )
{
	ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定

	int PC = 0; //PCの初期化
	int b = 0; //bの初期化
	int Handle0,Handle1,Handle2,Handle3,Handle4;
	int Voice0,Voice1,Voice2,Voice3,Voice4,Voice5,Voice6,Voice7,Voice8;
	Handle0 = LoadGraph( "画像/ゆっくり霊夢.png" );
	Handle1 = LoadGraph("画像/しょぼん.png");
	Handle2 = LoadGraph( "画像/グー.png" );
	Handle3 = LoadGraph( "画像/チョキ.png" );
	Handle4 = LoadGraph( "画像/パー.png" );
	Voice0 = LoadSoundMem("サウンド/勝ち1.wav"); // サウンドをロードし、識別番号をVoice0に格納
	Voice3 = LoadSoundMem("サウンド/勝ち2.wav");
	Voice6 = LoadSoundMem("サウンド/勝ち3.wav");
	Voice1 = LoadSoundMem("サウンド/あいこ1.wav");
	Voice4 = LoadSoundMem("サウンド/あいこ2.wav");
	Voice7 = LoadSoundMem("サウンド/あいこ3.wav");
	Voice2 = LoadSoundMem("サウンド/負け1,wav");
	Voice5 = LoadSoundMem("サウンド/負け2.wav");
	Voice8 = LoadSoundMem("サウンド/負け3.wav");
	SRand(GetNowCount());  // 乱数初期化

	while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 )
	{
		int a = GetRand( 2 ); //乱数0,1,2
		int Col = GetColor( 255,255,255 );

		if( b == 0 )
		{

			b = 1;
		}

		if( b == 1 )
		{
			DrawFormatString( 0, 0, GetColor(255,255,255), "「ジャンケン!」");
			DrawFormatString( 0,20, GetColor(255,255,255), "あなたの手を入力して下さい(グー:1 チョキ:2 パー:3)");
			DrawGraph( 395, 250, Handle0, TRUE ); // データハンドルを使って画像を描画
			DrawGraph( 1, 335, Handle1, TRUE ); 
			DrawFormatString( 445,460, GetColor(255,255,255), "[ゆっくり霊夢]");
			DrawFormatString( 110,460, GetColor(255,255,255), "[あなた]");
			if( CheckHitKey(KEY_INPUT_1) == 1 )
			{
				b = 2;
				if( b == 2 )
				{
					if( a == 0 )
					{
						PC=1;
						b=1;
					}
					else if( a == 1 )
					{
						PC=2;
						b=1;
					}
					else if( a == 2 )
					{
						PC=3;
						b=1;
					}
				}
			}
		}

		else if( CheckHitKey(KEY_INPUT_2) == 1 )
		{
			b = 3;
			if( b == 3 )
			{
				if( a == 0 )
				{
					PC=4;
					b=1;
				}
				else if( a == 1 )
				{
					PC=5;
					b=1;
				}
				else if( a == 2 )
				{
					PC=6;
					b=1;
				}
			}
		}
		else if( CheckHitKey(KEY_INPUT_3) == 1 )
		{
			b = 4;
			if( b == 4 )
			{
				if( a == 0 )
				{
					PC=7;
					b=1;
				}
				else if( a == 1 )
				{
					PC=8;
					b=1;
				}
				else if( a == 2 )
				{
					PC=9;
					b=1;
				}
			}
		}


		if( PC == 1 )
		{

			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle2, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_1) == 0)
			{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
				PlaySoundMem( Voice1, DX_PLAYTYPE_NORMAL ); // 効果音を再生する
				PC = 10;
			}
		}
		else if( PC == 10)
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");

			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{

				break;
			}
		}
		else if( PC == 2 )
		{
			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle3, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_1) == 0)
			{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
				PlaySoundMem( Voice0, DX_PLAYTYPE_NORMAL );
				PC = 11;
			}
		}
		else if( PC == 11 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{

				break;
			}
		}
		else if( PC == 3 )
		{

			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle4, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_1) == 0)
			{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
				PlaySoundMem( Voice2, DX_PLAYTYPE_NORMAL );
				PC = 12;
			}
		}
		else if( PC == 12 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
			DrawFormatString( 0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 4 )
		{

			DrawGraph( 155, 88, Handle3, TRUE );
			DrawGraph( 330, 88, Handle2, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_1) == 0)
			{

				PlaySoundMem( Voice5, DX_PLAYTYPE_NORMAL );
				PC = 13;
			}
		}
		else if(PC == 13)
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;

			}
		}

		else  if( PC == 5 )
		{

			DrawGraph( 155, 88, Handle3, TRUE );
			DrawGraph( 330, 88, Handle3, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_1) == 0)
			{
				PlaySoundMem( Voice4, DX_PLAYTYPE_NORMAL );
				PC = 14;
			}
			else if( PC == 14)
			{
				DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
				DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
				DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
				DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
				DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");

				if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
				{
					break;
				}
			}

			else if( PC == 6 )
			{

				DrawGraph( 155, 88, Handle3, TRUE );
				DrawGraph( 330, 88, Handle4, TRUE );

				if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_1) == 0)
				{
					PlaySoundMem( Voice3, DX_PLAYTYPE_NORMAL );
					PC = 15;
				}
			}
			else if( PC == 15 )
			{
				DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
				DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
				DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
				DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
				DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
				if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
				{
					break;
				}
			}

			else if( PC == 7 )
			{
				DrawGraph( 155, 88, Handle4, TRUE );
				DrawGraph( 330, 88, Handle2, TRUE );
				if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_1) == 0)
				{
					PlaySoundMem( Voice6, DX_PLAYTYPE_NORMAL );
					PC = 16;
				}
				else if( PC == 16 )
					DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
				DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
				DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
				DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
				DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
				if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
				{
					break;
				}
			}

			else if( PC == 8 )
			{

				DrawGraph( 155, 88, Handle4, TRUE );
				DrawGraph( 330, 88, Handle3, TRUE );
				if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_1) == 0)
				{
					PlaySoundMem( Voice8, DX_PLAYTYPE_NORMAL );
					PC = 17;
				}
				else if( PC == 17 )
					DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
				DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
				DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
				DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
				DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
				if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
				{
					break;
				}
			}

			else if( PC == 9 )
			{
				DrawGraph( 155, 88, Handle4, TRUE );
				DrawGraph( 330, 88, Handle4, TRUE );
				if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_1) == 0)
				{
					PlaySoundMem( Voice7, DX_PLAYTYPE_NORMAL );
					PC = 18;
				}
				else if( PC == 18 )
				{
					DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
					DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
					DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
					DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
					DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");	
					if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
					{
						break;
					}
				}
			}



		}
	}

	DxLib_End(); // DXライブラリ終了処理
	return 0;
}

アバター
エルフ
記事: 79
登録日時: 9年前
住所: 埼玉

Re: じゃんけんゲームを作っているのですが・・

#2

投稿記事 by エルフ » 9年前

少しソース変えました
もう一つ質問があります
ポン!を表示する条件は、一度1,2,3のどれかのキーを押し、離した瞬間に表示し、再びキーを押すと消える仕組みにしようとしたら、最初からでてしまいます・・・
なんででしょうか

コード:

#include "DxLib.h"

int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int )
{
	ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定

	int PC = 0; //PCの初期化
	int b = 0; //bの初期化
	int Handle0,Handle1,Handle2,Handle3,Handle4;
	int Voice0,Voice1,Voice2,Voice3,Voice4,Voice5,Voice6,Voice7,Voice8;
	int pon = 0;
	Handle0 = LoadGraph( "画像/ゆっくり霊夢.png" );
	Handle1 = LoadGraph("画像/しょぼん.png");
	Handle2 = LoadGraph( "画像/グー.png" );
	Handle3 = LoadGraph( "画像/チョキ.png" );
	Handle4 = LoadGraph( "画像/パー.png" );
	Voice0 = LoadSoundMem("サウンド/勝ち1.wav"); // サウンドをロードし、識別番号をVoice0に格納
	Voice3 = LoadSoundMem("サウンド/勝ち2.wav");
	Voice6 = LoadSoundMem("サウンド/勝ち3.wav");
	Voice1 = LoadSoundMem("サウンド/あいこ1.wav");
	Voice4 = LoadSoundMem("サウンド/あいこ2.wav");
	Voice7 = LoadSoundMem("サウンド/あいこ3.wav");
	Voice2 = LoadSoundMem("サウンド/負け1,wav");
	Voice5 = LoadSoundMem("サウンド/負け2.wav");
	Voice8 = LoadSoundMem("サウンド/負け3.wav");
	SRand(GetNowCount());  // 乱数初期化

	while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 )
	{
		int a = GetRand( 2 ); //乱数0,1,2
		int Col = GetColor( 255,255,255 );

		if( b == 0 )
		{

			b = 1;
		}

		if( b == 1 )
		{
			DrawFormatString( 0, 0, GetColor(255,255,255), "「ジャンケン!」");
			DrawFormatString( 0,20, GetColor(255,255,255), "あなたの手を入力して下さい(グー:1 チョキ:2 パー:3)");
			DrawGraph( 395, 250, Handle0, TRUE ); // データハンドルを使って画像を描画
			DrawGraph( 1, 335, Handle1, TRUE ); 
			DrawFormatString( 445,460, GetColor(255,255,255), "[ゆっくり霊夢]");
			DrawFormatString( 110,460, GetColor(255,255,255), "[あなた]");
			if( CheckHitKey(KEY_INPUT_1) == 1 )
			{
				b = 2;
				if( b == 2 )
				{
					if( a == 0 )
					{
						PC=1;
						b=1;
					}
					else if( a == 1 )
					{
						PC=2;
						b=1;
					}
					else if( a == 2 )
					{
						PC=3;
						b=1;
					}
				}
			}
		}

		else if( CheckHitKey(KEY_INPUT_2) == 1 )
		{
			b = 3;
			if( b == 3 )
			{
				if( a == 0 )
				{
					PC=4;
					b=1;
				}
				else if( a == 1 )
				{
					PC=5;
					b=1;
				}
				else if( a == 2 )
				{
					PC=6;
					b=1;
				}
			}
		}
		else if( CheckHitKey(KEY_INPUT_3) == 1 )
		{
			b = 4;
			if( b == 4 )
			{
				if( a == 0 )
				{
					PC=7;
					b=1;
				}
				else if( a == 1 )
				{
					PC=8;
					b=1;
				}
				else if( a == 2 )
				{
					PC=9;
					b=1;
				}
			}
		}
		if( CheckHitKey(KEY_INPUT_1) == 1 || CheckHitKey(KEY_INPUT_2) == 1 || CheckHitKey(KEY_INPUT_3) == 1)
		{
			pon = 1;
			if( pon == 1 )
			{
				if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
				{
					pon = 2;
				}
			}
		}
		if( pon = 2 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			if( CheckHitKey(KEY_INPUT_1) == 1 || CheckHitKey(KEY_INPUT_2) == 1 || CheckHitKey(KEY_INPUT_3) == 1)
			{
				pon = 0;
			}
		}
		if( PC == 1 )
		{

			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle2, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice1, DX_PLAYTYPE_NORMAL ); // 効果音を再生する
				PC = 10;
			}
		}
		else if( PC == 10)
		{
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");

			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{

				break;
			}
		}
		else if( PC == 2 )
		{
			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle3, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice0, DX_PLAYTYPE_NORMAL );
				PC = 11;
			}
		}
		else if( PC == 11 )
		{
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{

				break;
			}
		}
		else if( PC == 3 )
		{

			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle4, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice2, DX_PLAYTYPE_NORMAL );
				PC = 12;
			}
		}
		else if( PC == 12 )
		{
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
			DrawFormatString( 0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 4 )
		{

			DrawGraph( 155, 88, Handle3, TRUE );
			DrawGraph( 330, 88, Handle2, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{

				PlaySoundMem( Voice5, DX_PLAYTYPE_NORMAL );
				PC = 13;
			}
		}
		else if(PC == 13)
		{
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;

			}
		}

		else  if( PC == 5 )
		{

			DrawGraph( 155, 88, Handle3, TRUE );
			DrawGraph( 330, 88, Handle3, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice4, DX_PLAYTYPE_NORMAL );
				PC = 14;
			}
			else if( PC == 14)
			{
				DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
				DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
				DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
				DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");

				if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
				{
					break;
				}
			}

			else if( PC == 6 )
			{

				DrawGraph( 155, 88, Handle3, TRUE );
				DrawGraph( 330, 88, Handle4, TRUE );

				if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
				{
					PlaySoundMem( Voice3, DX_PLAYTYPE_NORMAL );
					PC = 15;
				}
			}
			else if( PC == 15 )
			{
				DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
				DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
				DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
				DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
				if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
				{
					break;
				}
			}

			else if( PC == 7 )
			{
				DrawGraph( 155, 88, Handle4, TRUE );
				DrawGraph( 330, 88, Handle2, TRUE );
				if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
				{
					PlaySoundMem( Voice6, DX_PLAYTYPE_NORMAL );
					PC = 16;
				}
				else if( PC == 16 )
					DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
				DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
				DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
				DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
				if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
				{
					break;
				}
			}

			else if( PC == 8 )
			{

				DrawGraph( 155, 88, Handle4, TRUE );
				DrawGraph( 330, 88, Handle3, TRUE );
				if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
				{
					PlaySoundMem( Voice8, DX_PLAYTYPE_NORMAL );
					PC = 17;
				}
				else if( PC == 17 )
					DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
				DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
				DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
				DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
				if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
				{
					break;
				}
			}

			else if( PC == 9 )
			{
				DrawGraph( 155, 88, Handle4, TRUE );
				DrawGraph( 330, 88, Handle4, TRUE );
				if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
				{
					PlaySoundMem( Voice7, DX_PLAYTYPE_NORMAL );
					PC = 18;
				}
				else if( PC == 18 )
				{
					DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
					DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
					DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
					DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");	
					if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
					{
						break;
					}
				}
			}



		}
	}

	DxLib_End(); // DXライブラリ終了処理
	return 0;
}

box
記事: 2002
登録日時: 13年前

Re: じゃんけんゲームを作っているのですが・・

#3

投稿記事 by box » 9年前

エルフ さんが書きました: 1.Voice2の音が再生されない

コード:

	Voice2 = LoadSoundMem("サウンド/負け1,wav");
wavの前がカンマになっているのは正しいですか?
バグのないプログラムはない。
プログラムは思ったとおりには動かない。書いたとおりに動く。

box
記事: 2002
登録日時: 13年前

Re: じゃんけんゲームを作っているのですが・・

#4

投稿記事 by box » 9年前

エルフ さんが書きました:少しソース変えました
もう一つ質問があります
後の方のソースにおいて、
71行目から始まるelse if

93行目から始まるelse if
は、どの
if
に対応していますか?その対応は正しいですか?
バグのないプログラムはない。
プログラムは思ったとおりには動かない。書いたとおりに動く。

アバター
エルフ
記事: 79
登録日時: 9年前
住所: 埼玉

Re: じゃんけんゲームを作っているのですが・・

#5

投稿記事 by エルフ » 9年前

boxさん
ありがとうございます
できました!

ですが、ポン!の処理がうまくいかないです・・・

box
記事: 2002
登録日時: 13年前

Re: じゃんけんゲームを作っているのですが・・

#6

投稿記事 by box » 9年前

後の方のコードの47行目から始まっているif文は、結局

コード:

            if (CheckHitKey(KEY_INPUT_1) == 1)
            {
                b = 2;
                if (a == 0)
                {
                    PC = 1;
                    b = 1;
                }
                else if (a == 1)
                {
                    PC = 2;
                    b = 1;
                }
                else if (a == 2)
                {
                    PC = 3;
                    b = 1;
                }
            }
こんな風に書いたのと同じ効果をもたらすはずです(未検証)。
これは想定どおりですか?aが0~2以外の値になることは絶対にありませんか?
バグのないプログラムはない。
プログラムは思ったとおりには動かない。書いたとおりに動く。

アバター
エルフ
記事: 79
登録日時: 9年前
住所: 埼玉

Re: じゃんけんゲームを作っているのですが・・

#7

投稿記事 by エルフ » 9年前

int a = GetRand( 2 );
の場合ってaには0または1または2以外の数字が入ることってないんじゃないんですか?
a = ○○とかのコードを書かない限り

zxc
記事: 79
登録日時: 11年前
住所: 日本の背骨(?)あたり

Re: じゃんけんゲームを作っているのですが・・

#8

投稿記事 by zxc » 9年前

コード:

        if( pon = 2 )
        {~
代入じゃなく比較してください・・・

アバター
エルフ
記事: 79
登録日時: 9年前
住所: 埼玉

Re: じゃんけんゲームを作っているのですが・・

#9

投稿記事 by エルフ » 9年前

zxcさん
ミスしてました・・・
ありがとうございました

box
記事: 2002
登録日時: 13年前

Re: じゃんけんゲームを作っているのですが・・

#10

投稿記事 by box » 9年前

aが0~2の範囲に絶対収まるならば、
先ほどの私の回答で書き換えたif文は
もっと簡単になるはずです(未検証)。

コード:

            if (CheckHitKey(KEY_INPUT_1) == 1)
            {
                b = 2;
                PC = a + 1;
                b = 1;
            }
これは想定どおりでしょうか。
バグのないプログラムはない。
プログラムは思ったとおりには動かない。書いたとおりに動く。

アバター
エルフ
記事: 79
登録日時: 9年前
住所: 埼玉

Re: じゃんけんゲームを作っているのですが・・

#11

投稿記事 by エルフ » 9年前

boxさん
何行目でしょうか
最後に編集したユーザー エルフ on 2014年8月25日(月) 17:24 [ 編集 1 回目 ]

box
記事: 2002
登録日時: 13年前

Re: じゃんけんゲームを作っているのですが・・

#12

投稿記事 by box » 9年前

先ほどの回答でif文について言及した理由は、
エルフ さんが書きました:

コード:

				b = 2;
				if( b == 2 )
				{
ここがとても不自然に見えるからです。というのは、
bに2を代入した直後で2と比較したら、真に決まってますよね。
だったら、このif文は不要では?ということです。
バグのないプログラムはない。
プログラムは思ったとおりには動かない。書いたとおりに動く。

アバター
エルフ
記事: 79
登録日時: 9年前
住所: 埼玉

Re: じゃんけんゲームを作っているのですが・・

#13

投稿記事 by エルフ » 9年前

boxさん
確かにそうですね・・
なおします

アバター
エルフ
記事: 79
登録日時: 9年前
住所: 埼玉

Re: じゃんけんゲームを作っているのですが・・

#14

投稿記事 by エルフ » 9年前

少し変えていたら
error C2086: 'int Handle0' : 再定義されました。
'Handle0' の宣言を確認してください。
とでました

エラーの意味がわからないです

コード:

#include "DxLib.h"

int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int )
{
	ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定

	int PC = 0; //PCの初期化
	int b = 0; //bの初期化
	int Handle0,Handle1,Handle2,Handle3,Handle4;
	int Voice0,Voice1,Voice2,Voice3,Voice4,Voice5,Voice6,Voice7,Voice8;
	int score0,score1,score2,
    
    Handle0 = LoadGraph( "画像/ゆっくり霊夢.png" );
	Handle1 = LoadGraph("画像/しょぼん.png");
	Handle2 = LoadGraph( "画像/グー.png" );
	Handle3 = LoadGraph( "画像/チョキ.png" );
	Handle4 = LoadGraph( "画像/パー.png" );
	Voice0 = LoadSoundMem("サウンド/勝ち1.wav"); // サウンドをロードし、識別番号をVoice0に格納
	Voice3 = LoadSoundMem("サウンド/勝ち2.wav");
	Voice6 = LoadSoundMem("サウンド/勝ち3.wav");
	Voice1 = LoadSoundMem("サウンド/あいこ1.wav");
	Voice4 = LoadSoundMem("サウンド/あいこ2.wav");
	Voice7 = LoadSoundMem("サウンド/あいこ3.wav");
	Voice2 = LoadSoundMem("サウンド/負け1.wav");
	Voice5 = LoadSoundMem("サウンド/負け2.wav");
	Voice8 = LoadSoundMem("サウンド/負け3.wav");
	SRand(GetNowCount());  // 乱数初期化

	while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 )
	{
		int a = GetRand( 2 ); //乱数0,1,2
		int Col = GetColor( 255,255,255 );

		if( b == 0 )
		{

			b = 1;
		}
		DrawFormatString( 0, 0, GetColor(255,255,255), "「ジャンケン!」");
		DrawFormatString( 0,20, GetColor(255,255,255), "あなたの手を入力して下さい(グー:1 チョキ:2 パー:3)");
		DrawGraph( 395, 250, Handle0, TRUE ); // データハンドルを使って画像を描画
		DrawGraph( 1, 335, Handle1, TRUE ); 
		DrawFormatString( 445,460, GetColor(255,255,255), "[ゆっくり霊夢]");
		DrawFormatString( 110,460, GetColor(255,255,255), "[あなた]");
		DrawFormatString( 445,250, GetColor(255,255,255), "[勝ち[%d]あいこ[%d]負け[%d]]score0,score2,score3");
		if( CheckHitKey(KEY_INPUT_1) == 1 )
		{
			b = 2;

			if( a == 0 )
			{
				PC=1;
				b=1;
			}
			else if( a == 1 )
			{
				PC=2;
				b=1;
			}
			else if( a == 2 )
			{
				PC=3;
				b=1;
			}
		}

		else if( CheckHitKey(KEY_INPUT_2) == 1 )
		{
			b = 3;
			if( a == 0 )
			{
				PC=4;
				b=1;
			}
			else if( a == 1 )
			{
				PC=5;
				b=1;
			}
			else if( a == 2 )
			{
				PC=6;
				b=1;
			}
		}
		else if( CheckHitKey(KEY_INPUT_3) == 1 )
		{
			b = 4;
			if( b == 4 )
			{
				if( a == 0 )
				{
					PC=7;
					b=1;
				}
				else if( a == 1 )
				{
					PC=8;
					b=1;
				}
				else if( a == 2 )
				{
					PC=9;
					b=1;
				}
			}
		}
		if( PC == 1 )
		{

			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle2, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice1, DX_PLAYTYPE_NORMAL ); // 効果音を再生する
				score1 ++;
				PC = 10;
			}
		}
		else if( PC == 10)
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");

			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{

				break;
			}
		}
		else if( PC == 2 )
		{
			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle3, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice0, DX_PLAYTYPE_NORMAL );
				score0 ++;
				PC = 11;
			}
		}
		else if( PC == 11 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{

				break;
			}
		}
		else if( PC == 3 )
		{

			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle4, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice2, DX_PLAYTYPE_NORMAL );
				score2 ++;
				PC = 12;
			}
		}
		else if( PC == 12 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
			DrawFormatString( 0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 4 )
		{

			DrawGraph( 155, 88, Handle3, TRUE );
			DrawGraph( 330, 88, Handle2, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{

				PlaySoundMem( Voice5, DX_PLAYTYPE_NORMAL );
				score2 ++;
				PC = 13;
			}
		}
		else if(PC == 13)
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;

			}
		}

		else  if( PC == 5 )
		{

			DrawGraph( 155, 88, Handle3, TRUE );
			DrawGraph( 330, 88, Handle3, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice4, DX_PLAYTYPE_NORMAL );
				score1 ++;
				PC = 14;
			}
		}
		else if( PC == 14)
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");

			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 6 )
		{

			DrawGraph( 155, 88, Handle3, TRUE );
			DrawGraph( 330, 88, Handle4, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice3, DX_PLAYTYPE_NORMAL );
				score0 ++;
				PC = 15;
			}
		}
		else if( PC == 15 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 7 )
		{
			DrawGraph( 155, 88, Handle4, TRUE );
			DrawGraph( 330, 88, Handle2, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice6, DX_PLAYTYPE_NORMAL );
				score0 ++;
				PC = 16;
			}
		}
		else if( PC == 16 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 8 )
		{

			DrawGraph( 155, 88, Handle4, TRUE );
			DrawGraph( 330, 88, Handle3, TRUE );
			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice8, DX_PLAYTYPE_NORMAL );
				score2 ++;
				PC = 17;
			}
		}
		else if( PC == 17 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 9 )
		{
			DrawGraph( 155, 88, Handle4, TRUE );
			DrawGraph( 330, 88, Handle4, TRUE );
			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice7, DX_PLAYTYPE_NORMAL );
				score1 ++;
				PC = 18;
			}
		}
		else if( PC == 18 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");	
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}
	}

	DxLib_End(); // DXライブラリ終了処理
	return 0;
}

アバター
Hiragi(GKUTH)
記事: 167
登録日時: 13年前
住所: 大阪府
連絡を取る:

Re: じゃんけんゲームを作っているのですが・・

#15

投稿記事 by Hiragi(GKUTH) » 9年前

コード:

int score0, score1, score2,
となっていてセミコロンが抜けています。
オフトピック
追記:
それに加えて前回のトピックにて解決後には解決したソースコードを貼ることになっているので、よろしくお願いします。
だいがくせい!

アバター
エルフ
記事: 79
登録日時: 9年前
住所: 埼玉

Re: じゃんけんゲームを作っているのですが・・

#16

投稿記事 by エルフ » 9年前

セミコロンが抜けていたのにきづきませんでした・・・
ご指摘ありがとうございました
前回の件ですが、そのようなルールがあったとは知りませんでした・・ 今から気をつけたいと思います。

みなさまありがとうございました

コード:

#include "DxLib.h"

int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int )
{
	ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定

	int PC = 0; //PCの初期化
	int b = 0; //bの初期化
	int Handle0,Handle1,Handle2,Handle3,Handle4;
	int Voice0,Voice1,Voice2,Voice3,Voice4,Voice5,Voice6,Voice7,Voice8;
	int score0 = 0;
	int	score1 = 0;
	int	score2 = 0;

	Handle0 = LoadGraph( "画像/ゆっくり霊夢.png" );
	Handle1 = LoadGraph("画像/しょぼん.png");
	Handle2 = LoadGraph( "画像/グー.png" );
	Handle3 = LoadGraph( "画像/チョキ.png" );
	Handle4 = LoadGraph( "画像/パー.png" );
	Voice0 = LoadSoundMem("サウンド/勝ち1.wav"); // サウンドをロードし、識別番号をVoice0に格納
	Voice3 = LoadSoundMem("サウンド/勝ち2.wav");
	Voice6 = LoadSoundMem("サウンド/勝ち3.wav");
	Voice1 = LoadSoundMem("サウンド/あいこ1.wav");
	Voice4 = LoadSoundMem("サウンド/あいこ2.wav");
	Voice7 = LoadSoundMem("サウンド/あいこ3.wav");
	Voice2 = LoadSoundMem("サウンド/負け1.wav");
	Voice5 = LoadSoundMem("サウンド/負け2.wav");
	Voice8 = LoadSoundMem("サウンド/負け3.wav");
	SRand(GetNowCount());  // 乱数初期化

	while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 )
	{
		int a = GetRand( 2 ); //乱数0,1,2
		int Col = GetColor( 255,255,255 );

		if( b == 0 )
		{

			b = 1;
		}
		DrawFormatString( 0, 0, GetColor(255,255,255), "「ジャンケン!」");
		DrawFormatString( 0,20, GetColor(255,255,255), "あなたの手を入力して下さい(グー:1 チョキ:2 パー:3)");
		DrawGraph( 395, 250, Handle0, TRUE ); // データハンドルを使って画像を描画
		DrawGraph( 1, 335, Handle1, TRUE ); 
		DrawFormatString( 445,460, GetColor(255,255,255), "[ゆっくり霊夢]");
		DrawFormatString( 110,460, GetColor(255,255,255), "[あなた]");
		DrawFormatString( 280,50, GetColor(255,255,255), "スコア:勝ち[%d]",score0);
		DrawFormatString( 410,50, GetColor(255,255,255), "あいこ[%d]",score1);
		DrawFormatString( 500,50, GetColor(255,255,255), "負け[%d]",score2);
		if( CheckHitKey(KEY_INPUT_1) == 1 )
		{
			b = 2;

			if( a == 0 )
			{
				PC=1;
				b=1;
			}
			else if( a == 1 )
			{
				PC=2;
				b=1;
			}
			else if( a == 2 )
			{
				PC=3;
				b=1;
			}
		}

		else if( CheckHitKey(KEY_INPUT_2) == 1 )
		{
			b = 3;
			if( a == 0 )
			{
				PC=4;
				b=1;
			}
			else if( a == 1 )
			{
				PC=5;
				b=1;
			}
			else if( a == 2 )
			{
				PC=6;
				b=1;
			}
		}
		else if( CheckHitKey(KEY_INPUT_3) == 1 )
		{
			b = 4;
			if( b == 4 )
			{
				if( a == 0 )
				{
					PC=7;
					b=1;
				}
				else if( a == 1 )
				{
					PC=8;
					b=1;
				}
				else if( a == 2 )
				{
					PC=9;
					b=1;
				}
			}
		}
		if( PC == 1 )
		{

			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle2, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice1, DX_PLAYTYPE_NORMAL ); // 効果音を再生する
				score1 ++;
				PC = 10;
			}
		}
		else if( PC == 10)
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");

			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{

				break;
			}
		}
		else if( PC == 2 )
		{
			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle3, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice0, DX_PLAYTYPE_NORMAL );
				score0 ++;
				PC = 11;
			}
		}
		else if( PC == 11 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{

				break;
			}
		}
		else if( PC == 3 )
		{

			DrawGraph( 155, 88, Handle2, TRUE );
			DrawGraph( 330, 88, Handle4, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice2, DX_PLAYTYPE_NORMAL );
				score2 ++;
				PC = 12;
			}
		}
		else if( PC == 12 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:グー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
			DrawFormatString( 0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 4 )
		{

			DrawGraph( 155, 88, Handle3, TRUE );
			DrawGraph( 330, 88, Handle2, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{

				PlaySoundMem( Voice5, DX_PLAYTYPE_NORMAL );
				score2 ++;
				PC = 13;
			}
		}
		else if(PC == 13)
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;

			}
		}

		else  if( PC == 5 )
		{

			DrawGraph( 155, 88, Handle3, TRUE );
			DrawGraph( 330, 88, Handle3, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice4, DX_PLAYTYPE_NORMAL );
				score1 ++;
				PC = 14;
			}
		}
		else if( PC == 14)
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");

			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 6 )
		{

			DrawGraph( 155, 88, Handle3, TRUE );
			DrawGraph( 330, 88, Handle4, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice3, DX_PLAYTYPE_NORMAL );
				score0 ++;
				PC = 15;
			}
		}
		else if( PC == 15 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:チョキ");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 7 )
		{
			DrawGraph( 155, 88, Handle4, TRUE );
			DrawGraph( 330, 88, Handle2, TRUE );

			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice6, DX_PLAYTYPE_NORMAL );
				score0 ++;
				PC = 16;
			}
		}
		else if( PC == 16 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:グー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの勝ちです!");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 8 )
		{

			DrawGraph( 155, 88, Handle4, TRUE );
			DrawGraph( 330, 88, Handle3, TRUE );
			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice8, DX_PLAYTYPE_NORMAL );
				score2 ++;
				PC = 17;
			}
		}
		else if( PC == 17 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:チョキ");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あなたの負けです・・・");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}

		else if( PC == 9 )
		{
			DrawGraph( 155, 88, Handle4, TRUE );
			DrawGraph( 330, 88, Handle4, TRUE );
			if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
			{
				PlaySoundMem( Voice7, DX_PLAYTYPE_NORMAL );
				score1 ++;
				PC = 18;
			}
		}
		else if( PC == 18 )
		{
			DrawFormatString( 0, 40, GetColor(255,255,255), "「ポン!」");
			DrawFormatString( 0, 60, GetColor(255,255,255),"あなた:パー");
			DrawFormatString( 0, 80, GetColor(255,255,255),"あいて:パー");
			DrawFormatString( 0, 100, GetColor(255, 255,255),"結果:あいこです。");
			DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。");	
			if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
			{
				break;
			}
		}
	}

	DxLib_End(); // DXライブラリ終了処理
	return 0;
}

アバター
エルフ
記事: 79
登録日時: 9年前
住所: 埼玉

Re: じゃんけんゲームを作っているのですが・・

#17

投稿記事 by エルフ » 9年前

解決にチェックを入れるのを忘れてました

アバター
Hiragi(GKUTH)
記事: 167
登録日時: 13年前
住所: 大阪府
連絡を取る:

Re: じゃんけんゲームを作っているのですが・・

#18

投稿記事 by Hiragi(GKUTH) » 9年前

すいません。
解決したのにかかわらず少しだけ突っ込みたい所があるので、書き込ませてもらいます。

まず

コード:

if( b == 0 )
{
 
    b = 1;
}
にはなんの意味があるのですか?1フレーム目だけココを通過させる理由がありますか?
加えて折角

コード:

int Col = GetColor(255,255,255);
と色を作っているのに

コード:

        DrawFormatString( 0, 0, GetColor(255,255,255), "「ジャンケン!」");
        DrawFormatString( 0,20, GetColor(255,255,255), "あなたの手を入力して下さい(グー:1 チョキ:2 パー:3)");
        DrawGraph( 395, 250, Handle0, TRUE ); // データハンドルを使って画像を描画
        DrawGraph( 1, 335, Handle1, TRUE ); 
        DrawFormatString( 445,460, GetColor(255,255,255), "[ゆっくり霊夢]");
        DrawFormatString( 110,460, GetColor(255,255,255), "[あなた]");
        DrawFormatString( 280,50, GetColor(255,255,255), "スコア:勝ち[%d]",score0);
        DrawFormatString( 410,50, GetColor(255,255,255), "あいこ[%d]",score1);
        DrawFormatString( 500,50, GetColor(255,255,255), "負け[%d]",score2);
と殆ど全ての描画に直接GetColorを使ってしまっていて意味がありません。

コード:

DrawFormatString( 0, 0, Col, "「ジャンケン!」");
とするほうがいいのではないでしょうか、更にGetColor関数を使うのはメインループ内である必要が無いはずです。
それと乱数も毎フレーム生成する必要はありません。(もちろんそのままでも動きますが)

ほかにも色々と突っ込みどころは満載(ESCAPEキーを至る所で判定してるとか)ですが頑張ってください。

改善点は他にも沢山あるはずです。もちろん現状で満足するならそれまでですが。(私だったらそうしてしまうだろうが...)
オフトピック
面倒ならこの書き込みに対して返してもらわなくても結構です。
だいがくせい!

much

Re: じゃんけんゲームを作っているのですが・・

#19

投稿記事 by much » 9年前

Hiragi(GKUTH) さんが書きました:すいません。
解決したのにかかわらず少しだけ突っ込みたい所があるので、書き込ませてもらいます。
私もちょっと追記を

改良点の目安(もちろん全部じゃない)

コード:

        if( CheckHitKey(KEY_INPUT_1) == 1 )
        {
            b = 2;
 
            if( a == 0 )
            {
                PC=1;
                b=1;
            }
            else if( a == 1 )
            {
                PC=2;
                b=1;
            }
            else if( a == 2 )
            {
                PC=3;
                b=1;
            }
        }
aは0,1,2のいずれかなのでいずれかのif文を通るかと思います
なので b=2;は不要ではないでしょうか?

コード:

        else if( CheckHitKey(KEY_INPUT_3) == 1 )
        {
            b = 4;
            if( b == 4 )
            {
                if( a == 0 )
                {
                    PC=7;
                    b=1;
                }
                else if( a == 1 )
                {
                    PC=8;
                    b=1;
                }
                else if( a == 2 )
                {
                    PC=9;
                    b=1;
                }
            }
        }
b=4;
と書かれているので
if(b==4)
を常に通ります
よって
if(b==4)
は不要です
(多分わかっているとは思いますが)

というより
bは何にも使ってないのでb自体すべて不要ですね


せっかくスコアをつけているので
もう一回戦えてもいいと思います
(もう一回戦わせるためには結果が出たあと(PCが10~18のとき)にどううればいいでしょう?)

コード:

    Voice0 = LoadSoundMem("サウンド/勝ち1.wav"); // サウンドをロードし、識別番号をVoice0に格納
    Voice3 = LoadSoundMem("サウンド/勝ち2.wav");
    Voice6 = LoadSoundMem("サウンド/勝ち3.wav");
    Voice1 = LoadSoundMem("サウンド/あいこ1.wav");
    Voice4 = LoadSoundMem("サウンド/あいこ2.wav");
    Voice7 = LoadSoundMem("サウンド/あいこ3.wav");
    Voice2 = LoadSoundMem("サウンド/負け1.wav");
    Voice5 = LoadSoundMem("サウンド/負け2.wav");
    Voice8 = LoadSoundMem("サウンド/負け3.wav");
この部分のVoice0,Voice3,Voice6って別ファイルの同じ音じゃないでしょうか?(違う音なら無視してOKです)
同じ音であればVoice0,Voice1,Voice2があれば十分かと思います.(ハンドルの有効期限は1回だけではない)

あとこういう部分(Voice,Handleとか)は配列のほうがいいかも
配列には数字から対応するものを引き出すことができるというメリットがあります

例えば

コード:

int shohai = 9;  //勝敗の記録用変数 0:勝ち, 1:あいこ, 2:負け, 9:未判定

int player_gh[2];    //プレイヤー画像のグラフィックハンドル配列
player_gh[0] = LoadGraph( "画像/ゆっくり霊夢.png" );
player_gh[1] = LoadGraph("画像/しょぼん.png");

int te_gh[3];    //手の画像のグラフィックハンドル配列
te_gh[0] = LoadGraph( "画像/グー.png" );
te_gh[1] = LoadGraph( "画像/チョキ.png" );
te_gh[2] = LoadGraph( "画像/パー.png" );

int Voice[3];    //音声のハンドル配列
Voice[0] = LoadSoundMem("サウンド/勝ち.wav");
Voice[1] = LoadSoundMem("サウンド/あいこ.wav");
Voice[2] = LoadSoundMem("サウンド/負け.wav");

/*  ・・・  */

if(PC==1){
    shohai = 1;
    DrawGraph( 155, 88, te_gh[a], TRUE );   //aは相手の手の対応番号,te_gh[a]はaに対する画像
    DrawGraph( 330, 88, te_gh[b], TRUE );   //bは自分の手の対応番号,te_gh[b]はbに対する画像

    if( CheckHitKey(KEY_INPUT_1) == 0 && CheckHitKey(KEY_INPUT_2) == 0 && CheckHitKey(KEY_INPUT_3) == 0)
    {
        PlaySoundMem( Voice[shohai], DX_PLAYTYPE_NORMAL ); // 効果音を再生する
        PC = 11;       //← 前状態の +9 という形だと対応付けがわかりづらいからあえて10を使わずに +10でわかりやすくしている
    }
}
else if( PC == 11)
{
    DrawFormatString( 0, 60, Col,"あなた:グー");
    DrawFormatString( 0, 80, Col,"あいて:グー");
    DrawFormatString( 0, 100, Col,"結果:あいこです。");
    DrawFormatString(0, 120, GetColor(255, 255, 0), "ESCキーで終了します。"); //GetColor(255,255,0)も文字がいいかも

    if( CheckHitKey( KEY_INPUT_ESCAPE ) == 1 )
    {
        break;
    }
}
まだまだこの他にもまとめ上げられる箇所があります

・手の文字列配列("グー","チョキ,パー)
(aやbを使って参照,結果に利用)

・結果の文字列配列("あなたの勝ちです!","結果:あいこです。","あなたの負けです・・・")
(shohaiを使って参照,結果に利用)

・相手の手と自分の手からの勝敗結果を格納する二次配列
(aとbを使って参照,shohaiの代わりにできる)

・色(白,黄色)
(ただし,今回の場合は配列にするメリットはない)

これらの配列を使えばわざわざ9パターンの場合分けをせずに
めちゃくちゃ簡単にかけます.

興味があるなら考えてみて
わからなければ質問しに来てみてください
(もちろん強制じゃないです)
確実に力がつくかと思いますので挑戦することをおすすめします


エルフさんがプログラミングが上達することを祈ってます

閉鎖

“C言語何でも質問掲示板” へ戻る