示例#1
0
	/*
	 * Check if given piece is placeable onto grid.
	 */
	public bool IsPlaceable(PieceLogic piece)
	{
		int pHeight = piece.GetHeight();
		int pWidth = piece.GetWidth();
		int or = (int)piece.GetOrigin().y;
		int oc = (int)piece.GetOrigin().x;
		for(int r = 0; r < pHeight; r++)
			for(int c = 0; c < pWidth; c++)
			{
				// if cell is NoColor it's not necessary to check it.
				if(piece.GetCell(r,c).Match(CellColor.NoColor))
					continue;
				// piece cell position on grid 
				int row = or - r;
				int col = oc + c;
				// if cell outbounds of the grid, return false.
				if(row < 0 || row >= HEIGHT || col < 0 || col >= WIDTH)
					return false;	
				// if that cell is already taken, return false.
				if(!cells[row][col].Match(CellColor.NoColor))
					return false;
			}
		return true;
	}
示例#2
0
	public void Copy(PieceLogic root)
	{
		SetWidth(root.GetWidth());
		SetHeight(root.GetHeight());
		ResetCells();
		for(int r = 0; r < height; r++)
			for(int c = 0; c < width; c++)
			{
				cells[r][c].SetColor(root.GetCell(r,c).GetColor());
				cells[r][c].SetFeature(root.GetCell(r,c).GetFeature());
			}
	}
示例#3
0
	/*
	 * Put given piece onto grid.
	 * The piece will be colidable when consolidated.
	 */
	public void ConsolidatePiece(PieceLogic piece)
	{
		int pHeight = piece.GetHeight();
		int pWidth = piece.GetWidth();
		int oc = (int)piece.GetOrigin().x;
		int or = (int)piece.GetOrigin().y;
		// Printing piece onto grid
		for(int r = 0; r < pHeight; r++)
		for(int c = 0; c < pWidth; c++)
		{
			// sanity check for when piece is not completely shown.
			if(or-r < 0)	continue;

			if(!piece.GetCell(r,c).Match(CellColor.NoColor))
			{
				cells[or-r][oc+c].SetColor(piece.GetCell(r,c).GetColor());
				cells[or-r][oc+c].SetFeature(piece.GetCell(r,c).GetFeature());
			}
		}
	}