Archived

This topic is now archived and is closed to further replies.

Puzzle game problems

This topic is 5140 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites
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 illegal
C:\C++\puzzlegame\game.cpp(523) : error C2234: '''' : arrays of references are illegal
C:\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 ambiguous
C:\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.cpp
c:\c++\puzzlegame\game.h(45) : error C2234: '''' : arrays of references are illegal
Error executing cl.exe.

Share this post


Link to post
Share on other sites