📄 movingshape.java
字号:
import java.awt.Image;
import java.awt.image.ImageObserver;
/*
* Created on 12/04/2007
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
/**
* @author user
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class MovingShape extends SimpleShape
{
public static int nBHit = 0;
public static int nWHit = 0;
private
int
nType, // Black L, Black T,
// White L, White T, Cross Type
deltaX = 0,
deltaY = 0;
public MovingShape( int nT, /* Symbol Type */
int x, /* Top Left of Symbol */
int y, /* Top Right of Symbol */
Image img, /* Image Symbol */
int deltaX, /* Each X Move */
int deltaY) /* Each Y Move */
{
super(x, y, img);
this.nType = nT;
this.deltaX = deltaX;
this.deltaY = deltaY;
return;
}// End Constructor Method
public MovingShape(Image img)
{
super(img);
return;
}
public void setType(int nT)
{
this.nType = nT;
return;
}
public void setDeltaX(int x)
{
this.deltaX = x;
return;
}
public void setDeltaY(int y)
{
this.deltaY = y;
return;
}
public int getDeltaX()
{
return this.deltaX;
}
public int getDeltaY()
{
return this.deltaY;
}
public void move(int canvasWidth, int canvasHeight, ImageObserver observer)
{
boolean
isTouched = false;
if( (x+img.getWidth(observer)+ deltaX > canvasWidth) && (deltaX > 0))
{
deltaX = - deltaX;
isTouched = true;
// Boundary Touch
}
else if( (y+img.getHeight(observer)+deltaY > canvasHeight) && (deltaY > 0))
{
deltaY = - deltaY;
isTouched = true;
// Boundary Touch
}
else if( (x+deltaX<0) && (deltaX<0))
{
deltaX = - deltaX;
isTouched = true;
// Boundary Touch
}
else if( (y+deltaY<0) && (deltaY)<0 )
{
deltaY = -deltaY;
isTouched = true;
// Boundary Touch
}
if(isTouched)
{
if(nType == SetReader.BLACK_L || nType == SetReader.BLACK_T)
{
nBHit++;
//System.out.println("Black Hits: " + nBHit);
}
if(nType == SetReader.WHITE_L || nType == SetReader.WHITE_T)
{
nWHit++;
}
}//End if isTouched
x = this.x + deltaX;
y = this.y + deltaY;
return;
}// End move method
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -