randomball.java
来自「Java变的几个小程序」· Java 代码 · 共 42 行
JAVA
42 行
// RandomBall.java
public class RandomBall extends Ball
{
public RandomBall (int newX, int newY, int newRadius, int newXMotion, int newYMotion)
{
// call the Ball constructor
super( newX, newY, newRadius, newXMotion, newYMotion );
}
public void move()
{
// 50% chance of chaning X motion
if( Math.random() > 0.5 )
dx = -dx;
// 50% chance of changing Y motion
if( Math.random() > 0.5 )
dy = -dy;
// move centre of object
x = x + dx;
y = y + dy;
}
} // class RandomBall
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?