CodeForge QQ客服 CodeForge 400电话 客服电话 4006316121
首页 » 源代码 » 一块拼图 » Tile.java

Tile.java ( 文件浏览 )

文件源自:一块拼图
  • 发布于2016-05-18
  • 浏览次数:0
  • 下载次数:0
  • 下载需 1 积分
  • 侵权举报
			package com.tamal.tiles;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

public class Tile extends Piece {

	private RawPiece raw;
	private int size;

	int[][] pX;
	int[][] pY;
	char[][] pCh;
	int[][] tDim; // 0 = height, 1 = width
	int oCount;
	int curO;

	public Tile(int id, RawPiece raw) {

		this.id = id;
		this.raw = raw;
		this.size = raw.size();
		process(new int[] {
 Piece.ROTATE_0 
});
	
}

	public void process(int[] orientation) {

		int rawLeft = raw.getLeft();
		int rawTop = raw.getTop();
		this.right = raw.getRight() - rawLeft;
		this.bottom = raw.getBottom() - rawTop;

		int o;
		ArrayList<Square[]> lstPoints = new ArrayList<Square[]>();
		ArrayList<int[]> lstDimention = new ArrayList<int[]>();
		oCount = 0;
		int adjX;
		int index;
		Square[] points;
		Square[] ref;
		boolean matched;
		int x, y;
		for (int oi = 0; oi < orientation.length; oi++) {

			o = orientation[oi];

			adjX = Integer.MAX_VALUE;
			for (Square sq : raw.points) {

				x = sq.x - rawLeft;
				y = sq.y - rawTop;

				if (getY(x, y, o) == 0) {

					if (getX(x, y, o) <= adjX) {

						adjX = getX(x, y, o);
					
}
				
}
			
}
			index = 0;
			points = new Square[this.size];
			for (Square sq : raw.points) {

				x = sq.x - rawLeft;
				y = sq.y - rawTop;

				points[index++] = new Square(getX(x, y, o) - adjX,
						getY(x, y, o), sq.ch);
			
}
			Arrays.sort(points, new Comparator<Square>() {

				@Override
				public int compare(Square o1, Square o2) {

					return (o1.y - o2.y) != 0 ? o1.y - o2.y : o1.x - o2.x;
				
}
			
});

			// if new, add to lstPoints
			matched = false;
			for (curO = oCount; curO-- > 0 && !matched;) {

				ref = lstPoints.get(curO);
				for (index = size; index-- > 0;) {

					if (!ref[index].equals(points[index])) {

						break;
					
}
				
}
				matched = index == -1;
			
}
			if (!matched) {

				lstPoints.add(points);
				if ((o & RF_90_270) == 0)
					lstDimention.add(new int[] {
 bottom + 1, right + 1 
});
				else
					lstDimention.add(new int[] {
 right + 1, bottom + 1 
});
				oCount++;
			
}
		
}
		pX = new int[oCount][size];
		pY = new int[oCount][size];
		pCh = new char[oCount][size];
		tDim = new int[oCount][];
		for (curO = 0; curO < lstPoints.size(); curO++) {

			ref = lstPoints.get(curO);
			for (index = 0; index < size; index++) {

				pX[curO][index] = ref[index].x;
				pY[curO][index] = ref[index].y;
				pCh[curO][index] = ref[index].ch;
			
}
			tDim[curO] = lstDimention.get(curO);
		
}
		curO = 0;
	
}

	@Override
	public int height() {

		return tDim[curO][0];
	
}

	@Override
	public int width() {

		return tDim[curO][1];
	
}

	@Overr
...
...
(完整源码请下载查看)
			
...
展开> <收缩

下载源码到电脑,阅读使用更方便

1 积分

快速下载
还剩0行未阅读,继续阅读
云测速

源码文件列表

温馨提示: 点击源码文件名可预览文件内容哦 ^_^
...
名称 大小 修改日期
Puzzle0.00 B2010-05-09|20:37
Puzzle516.00 B2008-04-14|03:27
Puzzle252.00 B2008-04-18|23:36
Puzzle268.00 B2008-04-18|23:36
Puzzle392.00 B2008-04-14|18:24
Puzzle304.00 B2008-04-14|22:08
Puzzle309.00 B2008-04-19|01:56
Puzzle340.00 B2008-04-19|02:32
Puzzle316.00 B2008-04-19|02:32
Puzzle322.00 B2008-04-23|23:33
Puzzle429.00 B2008-04-23|23:33
Puzzle431.00 B2008-04-23|23:33
Puzzle429.00 B2008-04-23|23:34
Puzzle428.00 B2008-04-23|23:34
Puzzle427.00 B2008-04-23|23:34
Puzzle428.00 B2008-04-23|23:34
Puzzle322.00 B2008-04-23|23:34
Puzzle321.00 B2008-04-23|23:34
Puzzle323.00 B2008-04-23|23:34
Puzzle337.00 B2008-04-14|18:30
Puzzle56.00 B2008-04-13|22:31
LICENSE-2.0.txt11.09 kB2010-05-11|11:33
readme.txt521.00 B2010-05-11|11:32
01.96 kB
.classpath2.14 kB2010-05-06|13:08
.project385.00 B2010-05-06|13:06
01.96 kB
org.eclipse.jdt.core.prefs629.00 B2010-05-06|13:06
01.96 kB
application_view_tile.png465.00 B2006-03-12|21:48
readme.txt626.00 B2006-03-12|22:19
logging.properties1.29 kB2010-04-19|01:37
01.96 kB
01.96 kB
01.96 kB
01.96 kB
Board.java3.20 kB2010-05-09|22:26
IMonitor.java137.00 B2010-05-06|13:09
IntChPair.java676.00 B2010-05-06|13:09
IntPair.java662.00 B2010-05-06|13:09
MergedBoard.java2.89 kB2010-05-06|13:45
Piece.java3.13 kB2010-05-07|14:42
Point.java652.00 B2010-05-06|13:09
Program.java6.29 kB2010-05-11|03:07
Puzzle.java12.63 kB2010-05-10|03:05
RawPiece.java1.94 kB2010-05-06|14:49
Solution.java1.31 kB2010-05-10|02:56
Square.java661.00 B2010-05-06|13:23
Tile.java3.99 kB2010-05-07|13:43
01.96 kB
ImageUtil.java1.54 kB2010-05-06|13:10
MainDialog.java12.50 kB2010-05-07|14:32
PieceComposite.java1.80 kB2010-05-06|16:19
云测速

Tile.java (29.94 kB)

需要 1 积分
您持有 积分

CodeForge积分(原CF币)全新升级,功能更强大,使用更便捷,不仅可以用来下载海量源代码马上还可兑换精美小礼品了 了解更多

您的积分不足

支付宝优惠套餐快速获取 30 积分

订单支付完成后,积分将自动加入到您的账号。以下是优惠期的人民币价格,优惠期过后将恢复美元价格。

更多付款方式:网银PayPal

上传代码,免费获取

您本次下载所消耗的积分将转交上传作者。

同一源码,30天内重复下载,只扣除一次积分。

登录 CodeForge

还没有CodeForge账号? 立即注册
关注微博
联系客服

Switch to the English version?

Yes
CodeForge 英文版
No
CodeForge 中文版

完善个人资料,获价值¥30元积分奖励!

^_^"呃 ...

Sorry!这位大神很神秘,未开通博客呢,请浏览一下其他的吧
好的