tile.java
来自「mywork是rcp开发的很好的例子」· Java 代码 · 共 202 行
JAVA
202 行
/************************************************************
*
* Copyright (c) 2003 Chemi. All rights reserved.
*
* This program and the accompanying materials
* are made available under the terms of the MIT License
* which accompanies this distribution, and is available at
* http://www.opensource.org/licenses/mit-license.html
*
************************************************************/
package es.org.chemi.games.sokoban.ui;
import net.sf.pim.game.util.DiamondMap;
import net.sf.pim.game.util.DiamondMap.IsoDirection;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import es.org.chemi.games.sokoban.SokobanPlugin;
import es.org.chemi.games.sokoban.util.Constants;
public class Tile implements Cloneable
{
private int row = 0;
private int column = 0;
private Image image = null;
private boolean isModified = true;
private boolean isWall = false;
private boolean isBox = false;
private boolean isHole = false;
private boolean isFloor = false;
//设置脚印
private boolean isTrack =false;
//设置外地板
private boolean isOutFloor = false;
//小人的方向,初始为右
private IsoDirection direction=IsoDirection.SOUTH_EAST;
public Tile(int row, int column)
{
this.row = row;
this.column = column;
}
public void repaint(GC gc, int deltaWidth, int deltaHeight)
{
SokobanPlugin.trace(this.getClass().getName(),"Repainting tile [" + row + "][" + column + "]."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Point pt=reviseXY(Constants.TILE_SIZE,Constants.TILE_SIZE/2,column,row,deltaWidth,deltaHeight);
//调试用坐标输出
// if(row % 2 == 0 && column %2 == 0){
// gc.setLineStyle(SWT.LINE_SOLID);
// gc.drawImage(SokobanPlugin.getResourceManager().getImage(Constants.IMAGE_FLOOR),pt.x, pt.y);
// gc.drawPolygon(new int[]{pt.x,pt.y,pt.x+48,pt.y,pt.x+48,pt.y+24,pt.x,pt.y+24});
// gc.drawText("("+row+","+column+")",pt.x+8, pt.y+6);
// }
// else{
// gc.setLineStyle(SWT.LINE_DOT);
// gc.drawPolygon(new int[]{pt.x,pt.y,pt.x+48,pt.y,pt.x+48,pt.y+24,pt.x,pt.y+24});
// gc.drawText("("+row+","+column+")",pt.x+8, pt.y+6);
// }
if(isTrack && isFloor){
//是脚印且不是小人所在tile
gc.drawImage(SokobanPlugin.getResourceManager().getImage(Constants.IMAGE_TRACK),pt.x, pt.y);
}else if(image != null){
gc.drawImage(image,pt.x, pt.y);
}
else if(isFloor){
gc.drawImage(SokobanPlugin.getResourceManager().getImage(Constants.IMAGE_FLOOR),pt.x, pt.y);
}
}
private Point reviseXY(int width, int height,int column, int row, int offsetX, int offsetY) {
return DiamondMap.tilePlotter(new Point(column,row), width, height, offsetX, offsetY);
}
protected Object clone() throws CloneNotSupportedException
{
return super.clone();
}
// Getters & Setters.
public void setImage(Image image)
{
this.image = image;
if(image != null)
this.isFloor = false;
}
public void setModified(boolean isModified)
{
this.isModified = isModified;
}
public boolean isModified()
{
return isModified;
}
public void setWall(boolean isWall)
{
this.isWall = isWall;
}
public boolean isWall()
{
return isWall;
}
public void setBox(boolean isBox)
{
this.isBox = isBox;
}
public boolean isBox()
{
return isBox;
}
public void setHole(boolean isHole)
{
this.isHole = isHole;
}
public boolean isHole()
{
return isHole;
}
public void setFloor(boolean isFloor)
{
this.isFloor = isFloor;
if(!isHole)
this.image = null;
else
this.image = SokobanPlugin.getResourceManager().getImage(Constants.IMAGE_HOLE);
}
public boolean isFloor()
{
return isFloor;
}
public int getRow()
{
return row;
}
public int getColumn()
{
return column;
}
public IsoDirection getDirection() {
return direction;
}
public void setDirection(IsoDirection direction) {
this.direction = direction;
}
public boolean isTrack() {
return isTrack;
}
public void setTrack(boolean isTrack) {
this.isTrack = isTrack;
}
public boolean isBlank(){
return image == null && !isWall && !isFloor;
}
@Override
public boolean equals(Object o) {
if(o instanceof Tile){
Tile t=(Tile)o;
if(t.getRow() == this.getRow() && t.getColumn() == this.getColumn())
return true;
else
return false;
}
return super.equals(o);
}
public boolean isOutFloor() {
return isOutFloor;
}
public void setOutFloor(boolean isOutFloor) {
this.isOutFloor = isOutFloor;
}
public Image getImage() {
return image;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?