トップページ > 過去ログ > 記事閲覧
三目並べ
名前:01uNLUCKy 日時: 2012/02/18 21:52

#include "DxLib.h" void gameMain(); int Cell[2][2]; // プログラムは WinMain から始まります int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { //ウィンドウモード ChangeWindowMode(true); if( DxLib_Init() == -1 ) // DXライブラリ初期化処理 { return -1 ; // エラーが起きたら直ちに終了 } gameMain(); DxLib_End() ; // DXライブラリ使用の終了処理 return 0 ; // ソフトの終了 } void gameMain(){ SetMouseDispFlag(TRUE);//マウスを表示する SetDrawScreen(DX_SCREEN_BACK);//バックスクリーン //マウスについての変数 int MouseX,MouseY; int Cr0,Cr1,Cr2,Cr3; MouseX = 0; MouseY = 0; Cr0 = GetColor(0,255,0);//グリッドの色 Cr1 = GetColor(0,0,0);//線の色 Cr2 = GetColor(255,0,0);//丸の色 Cr3 = GetColor(0,0,255);//資格の色 int x,y; int turn = 0; int mapX,mapY; int oldinput = 0; int nowinput = 0; int edgeinput; for(x=0; x< 3; x++){ for(y=0; y< 3;y++){ Cell[x][y] = 2; } } while( ProcessMessage() == 0 && CheckHitKey( KEY_INPUT_ESCAPE ) == 0 ){ int X,Y; oldinput = nowinput; nowinput = GetMouseInput(); edgeinput = nowinput &~oldinput; GetMousePoint( &MouseX , &MouseY); mapX = (MouseX - 145) / 120; mapY = (MouseY - 60) / 120; if((edgeinput & MOUSE_INPUT_LEFT) != 0) { if(MouseX >144 && MouseX<505 && MouseY>60 && MouseY<420){ if(Cell[mapX][mapY] == 2){ Cell[mapX][mapY] = turn % 2; turn++; } } } ClearDrawScreen();//画面クリア DrawBox(145,60,506,421,Cr0,TRUE);//グリッド絵画 for(X = 0; X < 4; X++){ DrawLine(X*120+145,60,X*120+145,420,Cr1);//縦線を引く } for(Y = 0; Y < 4; Y++){ DrawLine(145,Y*120+60,506,Y*120+60,Cr1);//横線を引く } for( X = 0; X < 3; X++){ for( Y = 0; Y < 3; Y++){ if(Cell[X][Y]==0){ DrawCircle(X*120+205,Y*120+120,50,Cr2,TRUE);//丸絵画 } else if(Cell[X][Y]==1){ DrawBox(X*120+165,Y*120+160,X*120+245,Y*120+80,Cr3,TRUE);//資格絵画 } } } ScreenFlip();//バックとフロントチェンジ } } このソースで、クリックされた場所に丸と四角を交互に絵画するつもりなのですが、1段目の真ん中と3段目の左が、1段目の右と3段目の真ん中が同時に絵画されてしまいます。どうしてなのか教えてください。

Page: 1 |

Re: 三目並べ ( No.1 )
名前:いっち 日時:2012/02/18 23:05

配列の大きさが足りないです。 > int Cell[2][2]; ↓↓変更↓↓ > int Cell[3][3];
Re: 三目並べ ( No.2 )
名前:01uNLUCKy 日時:2012/02/19 09:25

ありがとうございました。 しょうもないミスでした。すいません。以後気を付けます。

Page: 1 |