java编程开发技巧与实例的编译测试通过的所有例程

源代码在线查看: sharkprey.java

软件大小: 867 K
上传用户: junbo2009
关键词: java 编程 开发技巧 测试
下载地址: 免注册下载 普通下载 VIP

相关代码

				import java.awt.*;
				
				public class SharkPrey
				{
					private SharkAttack	applet	=	null;
					private Image		animal	=	null;
					private	Rectangle	bounds	=	new Rectangle();
					private	int			deltaX, amp;
					
					public SharkPrey(Image _animal, SharkAttack _applet)
					{
						animal	=	_animal;
						applet	=	_applet;
						deltaX	=	(int)(2 * Math.random()) + 1;
						amp		=	(int)(55 * Math.random()) + 10;
						bounds.x		=	(int)(applet.getSize().width * Math.random());
						bounds.y		=	120 + (int)(amp * Math.sin(bounds.x / 20.0));
						bounds.height	=	animal.getHeight(null);
						bounds.width	=	animal.getWidth(null);
					}
					public void move()
					{
						if ((bounds.x > applet.getSize().width) || (bounds.x < 0))
							deltaX *= (- 1);
						bounds.x += deltaX;
						bounds.y += 120 + (int)(amp * Math.sin(bounds.x /20));
					}
					public boolean isEatenBy(Shark shark)
					{
						return bounds.contains(shark.getTip());
					}
					public void paintComponent(Graphics g)
					{
						g.drawImage(animal, bounds.x, bounds.y, null);
					}
				}
							

相关资源