var grid:Array = [[2,3,2,2,2,4],
[ .. ]]; //multidimensional array
var matches:uint;
var gemType:uint;
for(col = 0; col < grid.length; col++){
matches = 0;
gemType = 0; //Reserve 0 for the empty state. If we make it a normal gem type, then only 2 are needed to match for the start.
for(i = 0; i < grid[0].length; i++){
if(grid[col][i] == gemType){
matches++;
}
if(grid[col][i] != gemType || i == grid[0].length - 1){ //subtract 1 because arrays start at 0
if(matches >= 3){
removeMatches(blah);
}
gemType = grid[col][i];
matches = 1;
}
}
}int item = grid[x,y];
if(grid[x-1,y]==item)
{
int step=x;
int matches =2;
while(grid[step-1,y]==item)
{
step++;
matches++
}
if(matches>2)
//remove all matching items
}
else if(grid[x+1,y]==item
//....
else if(grid[x,y-1==item)
//...
else if(grid[x,y+1]==item)
//... public int getHMatchSize(int row, int column)
{
int returnMe = getMatchValue(row, 0, column, 1);
if (returnMe < 3)
{
return 0;
}
else return returnMe;
}
public int getVMatchSize(int row, int column)
{
int returnMe = getMatchValue(row, 1, column, 0);
if (returnMe < 3)
{
return 0;
}
else return returnMe;
}
/// <summary>
/// I return the match size.
/// </summary>
/// <param name="row"></param>
/// <param name="rowDelta">1 means look vertically. Dont set both deltas to 1.</param>
/// <param name="column"></param>
/// <param name="columnDelta">1 means look horizontally. Dont set both deltas to 1.</param>
/// <returns>The number of contiguous matching things</returns>
public int getMatchValue(int row, int rowDelta, int column, int columnDelta)
{
int[] start = getEndItem(row, -1 * rowDelta, column, -1 * columnDelta);
int[] end = getEndItem(row, rowDelta, column, columnDelta);
int returnMe = 0;
returnMe += end[0] - start[0];
returnMe += end[1] - start[1];
return returnMe;
}
/// <summary>
/// I will return the end of a sequence of matching items.
/// </summary>
/// <param name="row">start here</param>
/// <param name="column">start here</param>
private int[] getEndItem(int row, int rowDelta, int column, int columnDelta)
{
Gem matchGem = new Gem(-1);
int[] returnMe = new int[2];
if (boardSpace[row + rowDelta][column + columnDelta] == boardSpace[row][column])
{
return getEndItem(row + rowDelta, rowDelta, column + columnDelta, columnDelta);
}
else
{
returnMe[0] = row;
returnMe[1] = column;
return returnMe;
}
}'잡다한것들전부 > 팁' 카테고리의 다른 글
| 헥사 게임 알고리즘 (0) | 2013.12.03 |
|---|---|
| 비쥬얼드 로직 (0) | 2013.12.02 |
| 비쥬얼드 3개 블록 맞추는 로직 (0) | 2013.12.02 |
| cocos2d-x 3.0 관련 컴포넌트 사용 (0) | 2013.12.02 |
| ios7 UITableView 사용시 배경화면 흰색으로 나오는 현상 (0) | 2013.12.02 |
| iOS7 상태바 안보이게 설정하기 (0) | 2013.12.02 |
Trackback 0 And
Comment 0


