トップページ > 過去ログ > 記事閲覧
うまくいかない、、、
名前:ジーク 日時: 2008/04/16 00:27

麻雀ゲームを作っているのですが、牌を配るところでうまく行きません 下のswitch命令でいうところの0〜2番の人に牌を配るまではうまく表示されるのですが、3番だけうまく表示されません それどころか3番を通過した後の人まで表示位置が崩れてしまいます 色々調べたのですが、 case 3: Player4[Rand] ++ ; HaiNum4[HaiCount[3]] = Rand; HaiCount[3] ++ ; break ; の中で HaiNum4[HaiCount[3]]にRandが代入されるハズなのに何故か通過するたびに1加算されているみたいです どうか解決策をお願いします //透過色を設定 SetTransColor( 0 , 255 , 0 ) ; //グラフィックハンドル int GHHai[36]; int GHMat ; GHHai[0] = LoadGraph("img/1man.bmp"); GHHai[1] = LoadGraph("img/2man.bmp"); GHHai[2] = LoadGraph("img/3man.bmp"); GHHai[3] = LoadGraph("img/4man.bmp"); GHHai[4] = LoadGraph("img/5man.bmp"); GHHai[5] = LoadGraph("img/5man_aka.bmp"); GHHai[6] = LoadGraph("img/7man.bmp"); GHHai[7] = LoadGraph("img/8man.bmp"); GHHai[8] = LoadGraph("img/9man.bmp"); GHHai[9] = LoadGraph("img/1pin.bmp"); GHHai[10] = LoadGraph("img/2pin.bmp"); GHHai[11] = LoadGraph("img/3pin.bmp"); GHHai[12] = LoadGraph("img/4pin.bmp"); GHHai[13] = LoadGraph("img/5pin.bmp"); GHHai[14] = LoadGraph("img/5pin_aka.bmp"); GHHai[15] = LoadGraph("img/6pin.bmp"); GHHai[16] = LoadGraph("img/7pin.bmp"); GHHai[17] = LoadGraph("img/8pin.bmp"); GHHai[18] = LoadGraph("img/9pin.bmp"); GHHai[19] = LoadGraph("img/1sou.bmp"); GHHai[20] = LoadGraph("img/2sou.bmp"); GHHai[21] = LoadGraph("img/3sou.bmp"); GHHai[22] = LoadGraph("img/4sou.bmp"); GHHai[23] = LoadGraph("img/5sou.bmp"); GHHai[24] = LoadGraph("img/5sou_aka.bmp"); GHHai[25] = LoadGraph("img/6sou.bmp"); GHHai[26] = LoadGraph("img/7sou.bmp"); GHHai[27] = LoadGraph("img/8sou.bmp"); GHHai[28] = LoadGraph("img/9sou.bmp"); GHHai[29] = LoadGraph("img/ton.bmp"); GHHai[30] = LoadGraph("img/nan.bmp"); GHHai[31] = LoadGraph("img/sya.bmp"); GHHai[32] = LoadGraph("img/pei.bmp"); GHHai[33] = LoadGraph("img/haku.bmp"); GHHai[34] = LoadGraph("img/hatu.bmp"); GHHai[35] = LoadGraph("img/tyun.bmp"); GHHai[36] = LoadGraph("img/null.bmp"); GHMat = LoadGraph("img/mat.jpg"); //山の牌 int Hai[35]; for(int i = 0 ;i <= 35; i++){ Hai[i] = 4 ; } //赤ドラ Hai[5] = 1 ; Hai[14] = 2 ; Hai[24] = 1 ; //牌の位置格納 int Player1_HaiX = 272; int Player1_HaiY = 647; int Player1_HaiX_Def = 272; int Player1_HaiY_Def = 647; int Player2_HaiX = 799; int Player2_HaiY = 168; int Player2_HaiX_Def = 799; int Player2_HaiY_Def = 168; int Player3_HaiX = 317; int Player3_HaiY = 66; int Player3_HaiX_Def = 317; int Player3_HaiY_Def = 66; int Player4_HaiX = 190; int Player4_HaiY = 144; int Player4_HaiX_Def = 190; int Player4_HaiY_Def = 144; //もち牌 int Player1[35] ; int Player2[35] ; int Player3[35] ; int Player4[35] ; //初期化 for(int i = 0 ;i < 35; i++){ Player1[i] = 0 ; Player2[i] = 0 ; Player3[i] = 0 ; Player4[i] = 0 ; } int HaiCount[3] ; HaiCount[0] = 0; HaiCount[1] = 0; HaiCount[2] = 0; HaiCount[3] = 0; int HaiNum1[13] ; int HaiNum2[13] ; int HaiNum3[13] ; int HaiNum4[13] ; for(int i = 0 ; i < 13 ;i ++ ){ HaiNum1[i] = 36; HaiNum2[i] = 36; HaiNum3[i] = 36; HaiNum4[i] = 36; } int Rand ; int Player = 0 ;//取る順番用 int HaipaiMainLoop ; int HaipaiSubLoop ; SetDrawScreen( DX_SCREEN_BACK ) ; for(HaipaiMainLoop = 0 ; HaipaiMainLoop <= 11 ; HaipaiMainLoop ++){ for(HaipaiSubLoop = 0; HaipaiSubLoop <= 3; HaipaiSubLoop ++){ Rand = GetRand( 35 ) ; //ランダムで牌番号を取得 while(Hai[Rand] == 0){ //その牌番号の牌が山にまだ残っているか判定 Rand ++; if(Rand == 36){ //ループの結果牌番号が最大数を超えたらリセット Rand = 0; } } switch(Player){ case 0: Player1[Rand] ++ ; HaiNum1[HaiCount[0]] = Rand; HaiCount[0] ++ ; break ; case 1: Player2[Rand] ++ ; HaiNum2[HaiCount[1]] = Rand; HaiCount[1] ++ ; break ; case 2: Player3[Rand] ++ ; HaiNum3[HaiCount[2]] = Rand; HaiCount[2] ++ ; break ; case 3: Player4[Rand] ++ ; HaiNum4[HaiCount[3]] = Rand; HaiCount[3] ++ ; break ; } Hai[Rand] -- ;//牌が確定したら残数から個数を引く } Player ++ ; if(Player == 4){ Player = 0 ; } //一斉描画 ClearDrawScreen() ; DrawGraph(0,0,GHMat,FALSE); DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[0]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[1]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[2]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[3]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[4]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[5]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[6]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[7]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[8]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[9]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[10]],TRUE); Player1_HaiX = Player1_HaiX + 35; DrawGraph(Player1_HaiX,Player1_HaiY,GHHai[HaiNum1[11]],TRUE); Player1_HaiX = Player1_HaiX + 35; Player1_HaiX = Player1_HaiX_Def ; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[0]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[1]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[2]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[3]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[4]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[5]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[6]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[7]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[8]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[9]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[10]],TRUE); Player2_HaiY = Player2_HaiY + 35; DrawGraph(Player2_HaiX,Player2_HaiY,GHHai[HaiNum2[11]],TRUE); Player2_HaiY = Player2_HaiY + 35; Player2_HaiY = Player2_HaiY_Def ; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[0]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[1]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[2]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[3]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[4]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[5]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[6]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[7]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[8]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[9]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[10]],TRUE); Player3_HaiX = Player3_HaiX + 35; DrawGraph(Player3_HaiX,Player3_HaiY,GHHai[HaiNum3[11]],TRUE); Player3_HaiX = Player3_HaiX + 35; Player3_HaiX = Player3_HaiX_Def ; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[0]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[1]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[2]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[3]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[4]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[5]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[6]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[7]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[8]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[9]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[10]],TRUE); Player4_HaiY = Player4_HaiY + 35; DrawGraph(Player4_HaiX,Player4_HaiY,GHHai[HaiNum4[11]],TRUE); Player4_HaiY = Player4_HaiY + 35; Player4_HaiY = Player4_HaiY_Def ; // 裏画面の内容を表画面に反映させる ScreenFlip() ; // Windows システムからくる情報を処理する if( ProcessMessage() == -1 ) break ; WaitTimer( 800 ) ; }

Page: 1 |

Re: うまくいかない、、、 ( No.1 )
名前:かたぱると 日時:2008/04/16 12:41

int HaiCount[3] ; HaiCount[0] = 0; HaiCount[1] = 0; HaiCount[2] = 0; HaiCount[3] = 0; HaiCountは3つしか用意していないのに HaiCount[3]にアクセスしているから しっちゃかめっちゃかになっているのではないかと。 あと一斉描画の部分ですが //一斉描画 ClearDrawScreen() ; DrawGraph(0,0,GHMat,FALSE); int j,k; int Xpos,Ypos,Graph; for( j = 0 ; j < 4 ; j++ ) { for( k = 0 ; k < 12 ; k++ ) { switch(j) { case 0: Xpos = Player1_HaiX_Def + ( 35 * k ); Ypos = Player1_HaiY_Def; Graph = GHHai[HaiNum1[k]]; break; case 1: Xpos = Player2_HaiX_Def; Ypos = Player2_HaiY_Def + ( 35 * k ); Graph = GHHai[HaiNum2[k]]; break; case 2: Xpos = Player3_HaiX_Def + ( 35 * k ); Ypos = Player3_HaiY_Def; Graph = GHHai[HaiNum3[k]]; break; case 3: Xpos = Player4_HaiX_Def; Ypos = Player4_HaiY_Def + ( 35 * k ); Graph = GHHai[HaiNum4[k]]; break; } DrawGraph(Xpos ,Ypos,Graph,TRUE); } } // 裏画面の内容を表画面に反映させる ScreenFlip() ; みたいにするとすっきりするかと思います。
Re: うまくいかない、、、 ( No.2 )
名前: 日時:2008/04/16 16:50

>>int GHHai[36]; >>GHHai[36] = LoadGraph("img/null.bmp"); >>int HaiCount[3] ; >>HaiCount[3] = 0; かたぱるとさんが既に指摘していますが、 念のため。。。 C言語の配列の添え字は配列Nに対して0オリジン (0から)始まるN-1までの範囲です。 よって上記のようなアクセスは違反のため、 メモリを破壊している可能性があります。 何が起こっても不思議ではありません。 Load部分も、画像を一枚にまとめてしまうのも ありかと思います。 例えば、1牌の大きさを24*32とし縦6個・横6個に 敷き詰めた場合、以下ような感じで読み込めます。 #define MAXHAICNT 36 int GHHai[MAXHAICNT]; LoadDivGraph("img/hai.bmp", MAXHAICNT, 6, 6, 24, 32, GHHai ); これだけでGHHaiには 0〜MAXHAICNT-1の領域に それぞれの画像ハンドルがとれます。
Re: うまくいかない、、、 ( No.3 )
名前:ジーク 日時:2008/04/16 17:13

なるほど! 配列を正しく理解できてなかったみたいです・・・ 描画処理もそのような手があったのですね とても参考になりました お二方ともありがとうございます

Page: 1 |