Puzzle game problems

Started by
7 comments, last by H_Lowemark 20 years, 5 months ago
Hello. I''m creating a small puzzle game using the win32 API and now i have ran into some problems. The game consists of 8 tiles in 8 diffrent colors, the tiles are randomly placed on an imaginary grid which is 8x8 tiles in size (64bricks at all). the goal of the game is to switch places with two tiles at the time so that the tiles will line up according to their colors. If you get 3 or more tiles of the same color in a row they will disapear. Then the tiles above them will drop down and new random tiles will appear. The problems i have at the moment is how to actually make the tiles switch places. A small example: _ |_|<- blue tile |_|<- red tile |_|<- blue tile etc... Here i want to switch the red and blue tile so that the two blue tiles will be lined up next to eachother.. Any tips on how to achive this?
Advertisement
You could just have an array of 'Tile' objects and you can change there color setting rather than swapping tiles.
EG:

struct Tile{    int color;      //0=red 1 = blue etc//..other tile variables};


All you would need to do then is write a function to swap the color values from one tile object to another rather than moving the tile objects. If you write a class, you can make a swap() member function. It all depends on the amount of functionality you want with it.

-J

PS: assuming this is in C/C++

[edited by - jason2jason on November 12, 2003 10:17:37 AM]
Thanks for the fast reply.
This is almost exactly what i''m trying to do, the only problem i have is that i really dont know how to swap the color values of the tiles...
Well OK. Lets take a simple struct example. Here we have the Tile struct:

struct Tile{    int color;    //More Data here if needed}; 


To swap the color you could do this:

Tile a,b;void SwapTileColor(){    int tmpcolor = a.color;    //Temperary holding for a    a.color = b.color;         //Put b.color in a.color    b.color = tmpcolor;        //put tmpcolor (origanal a.color) in b.color}


You can easily implement that with an aray, that just gives you the basics. Is this what you meant?

-J

Yes that is what i ment, but how do i implement it with an array? Since the tiles are randomly placed at the start of the game i really dont know how to figure it out..
struct Tile{    int color;};struct Coord{    short x, y;};void Swap(Tile & board[8][8], Coord t1, Coord t2){    Tile temp = board[t1.y][t1.x];    board[t1.y][t1.x] = board[t2.y][t2.x];    board[t2.y][t2.x] = temp;}; 


[edited by - origamiman64 on November 12, 2003 1:35:55 PM]
well.. i dont know if it''s me who is stupid but that gives me several errors:

c:\c++\puzzlegame\game.h(45) : error C2234: '''' : arrays of references are illegalC:\C++\puzzlegame\game.cpp(523) : error C2234: '''' : arrays of references are illegalC:\C++\puzzlegame\game.cpp(525) : error C2440: ''initializing'' : cannot convert from ''struct Tile *'' to ''struct Tile''        No constructor could take the source type, or constructor overload resolution was ambiguousC:\C++\puzzlegame\game.cpp(527) : error C2679: binary ''='' : no operator defined which takes a right-hand operand of type ''struct Tile'' (or there is no acceptable conversion)winmain.cppc:\c++\puzzlegame\game.h(45) : error C2234: '''' : arrays of references are illegalError executing cl.exe. 
Well i rellay cant get it to work.. Anyone else have some tips?
"arrays of references are illegal"

Maybe if you use Tile board[8][8] instead of Tile& board[8][8]. An array is a pointer after all.

--------------------------------------
I am the master of stories.....
If only I could just write them down...
I am the master of ideas.....If only I could write them down...

This topic is closed to new replies.

Advertisement