M
MaKiT
I have a program which on start makes a 4x4 grid of tiles. These tiles
are all blank. Two Array variables hold the position of 8 pairs of
images. Then when you click a tile it is uncovered and you try to
match up.
I attempted to modify this so it is a 8x8 grid with 16 pairs of
images. The only problem is that only some random tiles seem to be
placed and not all of them.
Heres the original start part of the code:
****************************************************
void GameStart(HWND hWindow)
{
// Seed the random number generator
srand(GetTickCount());
// Create and load the tile bitmaps
HDC hDC = GetDC(hWindow);
_pTiles[0] = new Bitmap(hDC, IDB_TILEBLANK, _hInstance);
_pTiles[1] = new Bitmap(hDC, IDB_TILE1, _hInstance);
_pTiles[2] = new Bitmap(hDC, IDB_TILE2, _hInstance);
_pTiles[3] = new Bitmap(hDC, IDB_TILE3, _hInstance);
_pTiles[4] = new Bitmap(hDC, IDB_TILE4, _hInstance);
_pTiles[5] = new Bitmap(hDC, IDB_TILE5, _hInstance);
_pTiles[6] = new Bitmap(hDC, IDB_TILE6, _hInstance);
_pTiles[7] = new Bitmap(hDC, IDB_TILE7, _hInstance);
_pTiles[8] = new Bitmap(hDC, IDB_TILE8, _hInstance);
// Clear the tile states and images
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
{
_bTileStates[j] = FALSE;
_iTiles[j] = 0;
}
// Initialize the tile images randomly
for (int i = 0; i < 2; i++)
for (int j = 1; j < 9; j++)
{
int x = rand() % 4;
int y = rand() % 4;
while (_iTiles[x][y] != 0)
{
x = rand() % 4;
y = rand() % 4;
}
_iTiles[x][y] = j;
}
// Initialize the tile selections and match/try count
_ptTile1.x = _ptTile1.y = -1;
_ptTile2.x = _ptTile2.y = -1;
_iMatches = _iTries = 0;
}
****************************************************
Heres what I modified:
****************************************************
void GameStart(HWND hWindow)
{
// Seed the random number generator
srand(GetTickCount());
// Create and load the tile bitmaps
HDC hDC = GetDC(hWindow);
_pTiles[0] = new Bitmap(hDC, IDB_TILEBLANK, _hInstance);
_pTiles[1] = new Bitmap(hDC, IDB_TILE1, _hInstance);
_pTiles[2] = new Bitmap(hDC, IDB_TILE2, _hInstance);
_pTiles[3] = new Bitmap(hDC, IDB_TILE3, _hInstance);
_pTiles[4] = new Bitmap(hDC, IDB_TILE4, _hInstance);
_pTiles[5] = new Bitmap(hDC, IDB_TILE5, _hInstance);
_pTiles[6] = new Bitmap(hDC, IDB_TILE6, _hInstance);
_pTiles[7] = new Bitmap(hDC, IDB_TILE7, _hInstance);
_pTiles[8] = new Bitmap(hDC, IDB_TILE8, _hInstance);
_pTiles[9] = new Bitmap(hDC, IDB_TILE9, _hInstance);
_pTiles[10] = new Bitmap(hDC, IDB_TILE10, _hInstance);
_pTiles[11] = new Bitmap(hDC, IDB_TILE11, _hInstance);
_pTiles[12] = new Bitmap(hDC, IDB_TILE12, _hInstance);
_pTiles[13] = new Bitmap(hDC, IDB_TILE13, _hInstance);
_pTiles[14] = new Bitmap(hDC, IDB_TILE14, _hInstance);
_pTiles[15] = new Bitmap(hDC, IDB_TILE15, _hInstance);
_pTiles[16] = new Bitmap(hDC, IDB_TILE16, _hInstance);
// Clear the tile states and images
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
{
_bTileStates[j] = FALSE;
_iTiles[j] = 0;
}
// Initialize the tile images randomly
for (i = 0; i < 2; i++)
for (int j = 1; j < 17; j++)
{
int x = rand() % 8;
int y = rand() % 8;
while (_iTiles[x][y] != 0)
{
x = rand() % 8;
y = rand() % 8;
}
_iTiles[x][y] = j;
}
// Initialize the tile selections and match/try count
_ptTile1.x = _ptTile1.y = -1;
_ptTile2.x = _ptTile2.y = -1;
_iMatches = _iTries = 0;
}
****************************************************
If you need the pait/click part of the codes just ask.
are all blank. Two Array variables hold the position of 8 pairs of
images. Then when you click a tile it is uncovered and you try to
match up.
I attempted to modify this so it is a 8x8 grid with 16 pairs of
images. The only problem is that only some random tiles seem to be
placed and not all of them.
Heres the original start part of the code:
****************************************************
void GameStart(HWND hWindow)
{
// Seed the random number generator
srand(GetTickCount());
// Create and load the tile bitmaps
HDC hDC = GetDC(hWindow);
_pTiles[0] = new Bitmap(hDC, IDB_TILEBLANK, _hInstance);
_pTiles[1] = new Bitmap(hDC, IDB_TILE1, _hInstance);
_pTiles[2] = new Bitmap(hDC, IDB_TILE2, _hInstance);
_pTiles[3] = new Bitmap(hDC, IDB_TILE3, _hInstance);
_pTiles[4] = new Bitmap(hDC, IDB_TILE4, _hInstance);
_pTiles[5] = new Bitmap(hDC, IDB_TILE5, _hInstance);
_pTiles[6] = new Bitmap(hDC, IDB_TILE6, _hInstance);
_pTiles[7] = new Bitmap(hDC, IDB_TILE7, _hInstance);
_pTiles[8] = new Bitmap(hDC, IDB_TILE8, _hInstance);
// Clear the tile states and images
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
{
_bTileStates[j] = FALSE;
_iTiles[j] = 0;
}
// Initialize the tile images randomly
for (int i = 0; i < 2; i++)
for (int j = 1; j < 9; j++)
{
int x = rand() % 4;
int y = rand() % 4;
while (_iTiles[x][y] != 0)
{
x = rand() % 4;
y = rand() % 4;
}
_iTiles[x][y] = j;
}
// Initialize the tile selections and match/try count
_ptTile1.x = _ptTile1.y = -1;
_ptTile2.x = _ptTile2.y = -1;
_iMatches = _iTries = 0;
}
****************************************************
Heres what I modified:
****************************************************
void GameStart(HWND hWindow)
{
// Seed the random number generator
srand(GetTickCount());
// Create and load the tile bitmaps
HDC hDC = GetDC(hWindow);
_pTiles[0] = new Bitmap(hDC, IDB_TILEBLANK, _hInstance);
_pTiles[1] = new Bitmap(hDC, IDB_TILE1, _hInstance);
_pTiles[2] = new Bitmap(hDC, IDB_TILE2, _hInstance);
_pTiles[3] = new Bitmap(hDC, IDB_TILE3, _hInstance);
_pTiles[4] = new Bitmap(hDC, IDB_TILE4, _hInstance);
_pTiles[5] = new Bitmap(hDC, IDB_TILE5, _hInstance);
_pTiles[6] = new Bitmap(hDC, IDB_TILE6, _hInstance);
_pTiles[7] = new Bitmap(hDC, IDB_TILE7, _hInstance);
_pTiles[8] = new Bitmap(hDC, IDB_TILE8, _hInstance);
_pTiles[9] = new Bitmap(hDC, IDB_TILE9, _hInstance);
_pTiles[10] = new Bitmap(hDC, IDB_TILE10, _hInstance);
_pTiles[11] = new Bitmap(hDC, IDB_TILE11, _hInstance);
_pTiles[12] = new Bitmap(hDC, IDB_TILE12, _hInstance);
_pTiles[13] = new Bitmap(hDC, IDB_TILE13, _hInstance);
_pTiles[14] = new Bitmap(hDC, IDB_TILE14, _hInstance);
_pTiles[15] = new Bitmap(hDC, IDB_TILE15, _hInstance);
_pTiles[16] = new Bitmap(hDC, IDB_TILE16, _hInstance);
// Clear the tile states and images
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++)
{
_bTileStates[j] = FALSE;
_iTiles[j] = 0;
}
// Initialize the tile images randomly
for (i = 0; i < 2; i++)
for (int j = 1; j < 17; j++)
{
int x = rand() % 8;
int y = rand() % 8;
while (_iTiles[x][y] != 0)
{
x = rand() % 8;
y = rand() % 8;
}
_iTiles[x][y] = j;
}
// Initialize the tile selections and match/try count
_ptTile1.x = _ptTile1.y = -1;
_ptTile2.x = _ptTile2.y = -1;
_iMatches = _iTries = 0;
}
****************************************************
If you need the pait/click part of the codes just ask.