#include "DxLib.h" #include #include int Init(std::vector>& t_Vec, int t_Width, int t_Height) { int result = -1; //最小でも7×7の幅は必要 if(t_Width >= 6 && t_Height >= 6){ //大きすぎる場合は、とりあえず100×100のサイズにする if(t_Width * t_Height > 20000){ t_Width = t_Height = 100; } if((t_Width & 1) == 0){ t_Width += 1; } if((t_Height & 1) == 0){ t_Height += 1; } t_Vec.resize(t_Height); for(int i = 0, count = (int)t_Vec.size(); i < count; i++) { t_Vec[i].resize(t_Width); for(int j = 0, count2 = (int)t_Vec[i].size(); j < count2; j++) { if(i % (t_Height - 1) == 0 || j % (t_Width - 1) == 0){ t_Vec[i][j] = 0; }else{ t_Vec[i][j] = 1; } } } result = 0; } return(result); } void Boll(std::vector>& t_Vec, int x, int y) { int t_Flag[] = {0, 1, 2, 3};//右、左、上、下、どの方向に掘るかのフラグ int t_Change[2] = {0}; //フラグを混ぜる。 for(int i = 0; i < 6; i++) { t_Change[0] = rand() % 4; t_Change[1] = rand() % 4; int t = t_Flag[t_Change[0]]; t_Flag[t_Change[0]] = t_Flag[t_Change[1]]; t_Flag[t_Change[1]] = t; } for(int i = 0; i < 4; i++) { switch(t_Flag[i]){ case 0: if(t_Vec[y][x + 2] == 1){ t_Vec[y][x + 2] = t_Vec[y][x + 1] = 2; Boll(t_Vec, x + 2, y); } break; case 1: if(t_Vec[y][x - 2] == 1){ t_Vec[y][x - 2] = t_Vec[y][x - 1] = 2; Boll(t_Vec, x - 2, y); } break; case 2: if(t_Vec[y - 2][x] == 1){ t_Vec[y - 2][x] = t_Vec[y - 1][x] = 2; Boll(t_Vec, x, y - 2); } break; case 3: if(t_Vec[y + 2][x] == 1){ t_Vec[y + 2][x] = t_Vec[y + 1][x] = 2; Boll(t_Vec, x, y + 2); } break; default:break; } } } void Create(std::vector>& t_Vec, int t_Width, int t_Height) { //初期化に成功すれば、Boll関数を実行 if(Init( t_Vec, t_Width, t_Height) == 0){ Boll( t_Vec, 2, 2); } } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){ ChangeWindowMode( TRUE ); if(DxLib_Init() == -1 ) return -1; SetDrawScreen( DX_SCREEN_BACK ); SetGraphMode(1024, 768, 32); SetWindowPosition( 100, 32 ); srand((unsigned int)time(NULL)); std::vector> t_MapVec; Create(t_MapVec, 60, 40); int t_Green = GetColor(0, 180, 0); while(ProcessMessage()==0 && ClearDrawScreen()==0 ){ for(int i = 0, count = (int)t_MapVec.size(); i < count; i++) { for(int j = 0, count2 = (int)t_MapVec[i].size(); j < count2; j++) { switch(t_MapVec[i][j]){ case 0: DrawString(j<<4, i<<4, " ", t_Green);break; case 1: DrawString(j<<4, i<<4, "■", t_Green);break; case 2: DrawString(j<<4, i<<4, "×", t_Green);break; default: break; } } } ScreenFlip(); } DxLib_End(); return 0; }