Program Design of Puzzle Game like "Diamond Dash, Bejewel" ?

Started by
6 comments, last by kburkhart84 10 years, 3 months ago

hi all,

I am going to make a puzzle game similar to Bejewel and Diamond Dash, Match-3 puzzle;

Need help on the design of it. It seem a bit difficult;

I have done some analysis; The operation contain the followings:

- Breaking a puzzle block (a jewel)

- Move down the existing blocks to the empty spaces

- Regenerate new blocks

Hope experts can help me and give me some hints

Regards,

ken

Advertisement

Hi,

I've been trying to develop something similar, but with elements of Tetris Attack, where the grid moves up slowly and you have to clear the blocks to stop them reaching the top, but including some of the popular elements of bejeweled etc, i.e. the special combo-blocks for 4-in-a-row and 5-in-a-row. Here are some of the main problems I've faced so far:

1) Creating a Grid object to hold all the blocks

2) How to check for combos? Check every single block each tick or only check those which have moved? We can suppose that a new combo will only happen if blocks move, but even if you parse every block that moves, the algorithm to check for combos is a tricky one (any advice from other people is welcome here)

3) I'm having a lot of problems with the falling blocks part, it seems that some of them occasionally disappear, but I'm too ashamed to post my awful code... :(

hi all,

I am going to make a puzzle game similar to Bejewel and Diamond Dash, Match-3 puzzle;

Need help on the design of it. It seem a bit difficult;

I have done some analysis; The operation contain the followings:

- Breaking a puzzle block (a jewel)

- Move down the existing blocks to the empty spaces

- Regenerate new blocks

Hope experts can help me and give me some hints

Regards,

ken

Puzzles are indeed much more difficult than people think.

I've never done one myself(except for tetris) since I'm more interested in action. But one approach that may be useful is to do things more "physical". It may be easier to code for if you have each block be an object, and each one knows what blocks are around it. Then, you easily have access within each block to know if another like block is matching with it. On the other hand, having things in a grid can make this access easier by simply incrementing/decrementing the indices to get to the adjacent blocks.

If you guys have Unity and are willing to invest, there are a couple of Unity projects on the asset store that may help. They are both "Match 3" games. One is $25, and the other is $50. I don't know what you guys are using to code, but both of these projects' scripting is using C#. If you purchase them, I'm sure you use the free version of Unity to access them, and even finish making them into your own project. But at the least, you can look at the code and see how they did them.



I'm currently writing a falling block puzzle game in Javascript (jsfiddle: http://jsfiddle.net/dr01d3k4/p26bh/15/). The way I store the grid is in a 2d array with many helper methods such as "getColourAt(x, y)", "setColourAt(x, y, colour)" or "isSolidAt(x, y)". The updating of the game is done through a state machine. At the top, I declared constants in a dictionary:


var GameState = {
	NONE: 0,
	INITIALIZING: 1,
	ADDING_NEW_ROW: 2,
	PLAYER_FALLING: 3,
	LANDING_CELLS: 4,
	PRE_CLEARING: 5,
	CLEARING: 6,
	GAP_FILL_FALL: 7,
	LOST: 100
};

Then in the game.update(dt) method, I have a big switch that calls the correct function for each state the game could be in:


Game.prototype.update = function (dt) {
	switch (this.state) {
		case GameState.INITIALIZING: {
			if (this.addedRows < this.startingRows) {
				this.changeState(GameState.ADDING_NEW_ROW);
			} else {
				this.changeState(GameState.PLAYER_FALLING);
			}
			break;
		}

		case GameState.ADDING_NEW_ROW: {
			this.updateStateAddingNewRow(dt);
			break;
		}

		case GameState.PLAYER_FALLING: {
			this.updateStatePlayerFalling(dt);
			break;	
		}

		case GameState.LANDING_CELLS: {
			this.updateLandingCells();
			break;
		}

		case GameState.PRE_CLEARING: {
			this.updatePreClearing(dt);
			break;
		}

		case GameState.CLEARING: {
			this.updateClearing(dt);
			break;
		}

		case GameState.GAP_FILL_FALL: {
			this.updateGapFillFall(dt);
			break;
		}

		case GameState.LOST: {
			this.lose();
			break;
		}

		case GameState.NONE:
		default: {
			break;
		}
	}

	this.newRowCumulativeTime += dt;
	if (this.newRowCumulativeTime > this.newRowTime) {
		this.newRowCumulativeTime = this.newRowTime;
	}

	if (this.grid.isDirty) {
		this.grid.calculateLessStateChange();
		this.renderGrid();
	}
};

By using a state machine, each of the separate parts of the code (player block falling and giving input, clearing out parts, other parts falling from gravity) into their own individual functions.

Falling block colour flood game thing I'm making: http://jsfiddle/dr01d3k4/JHnCV/

I have done the game mechanic of Diamond Dash. Same as what "dr01d3k4" has said, I am using State Machine on the Block (INIT, NORMAL, MOVING, BREAKING, DELETED) as well.

And there are several part in the update logic of the Game Board (the container of the blocks);

The steps are:

- Remove (or Recycle) the deleted blocks

- Move Down the existing blocks due to fill the deleted position

- Regenerating new blocks

Thanks for discussion. Looking for more sharing smile.png

Puzzles are indeed much more difficult than people think.

I've never done one myself(except for tetris) since I'm more interested in action. But one approach that may be useful is to do things more "physical". It may be easier to code for if you have each block be an object, and each one knows what blocks are around it. Then, you easily have access within each block to know if another like block is matching with it. On the other hand, having things in a grid can make this access easier by simply incrementing/decrementing the indices to get to the adjacent blocks.

If you guys have Unity and are willing to invest, there are a couple of Unity projects on the asset store that may help. They are both "Match 3" games. One is $25, and the other is $50. I don't know what you guys are using to code, but both of these projects' scripting is using C#. If you purchase them, I'm sure you use the free version of Unity to access them, and even finish making them into your own project. But at the least, you can look at the code and see how they did them.

I think it (25 & 50 starter code) is a good price to invest. However, could we ask for help or suggest if we cannot run the code or want to do somethings special ?

Thanks for the help.

For Tetris the trick to make things simpler is : make the array bigger then what is on screen, handle it like this for simpler programming.

greetings

S T O P C R I M E !

Visual Pro 2005 C++ DX9 Cubase VST 3.70 Working on : LevelContainer class & LevelEditor


I think it (25 & 50 starter code) is a good price to invest. However, could we ask for help or suggest if we cannot run the code or want to do somethings special ?

Thanks for the help.

Well, if you are actually going to go through with using Unity, you could ask on the Unity forums, or even here on Gamedev. As far as asking the actual creators of the example, it should also be possible, but I'm not sure, considering some people are more responsive than others in that sense.



This topic is closed to new replies.

Advertisement