java编写捕鱼达人初学者
java小程序代码金鲨银鲨游戏
工具/原料eclipse方法/步骤1import java.awt.image.BufferedImage;
public abstract class Fish {public BufferedImage image;//每条鱼的全部是由多张图片组成public BufferedImage [] images;public int width;public int height;public int x;public int y;//每条鱼都有自己独特的走路方式public abstract void step();}
2import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;import javax.swing.JPanel;
public class FishGame extends JPanel{public static final int WIDTH=700;public static final int HEIGHT=400;public static BufferedImage buyu;public static BufferedImage fy1;public static BufferedImage fy2;public static BufferedImage fy3;public static BufferedImage fy4;public static BufferedImage fy5;public static BufferedImage fy6;public static BufferedImage fy7;public static BufferedImage fy8;public static BufferedImage fy9;public static BufferedImage fy10;public static BufferedImage fy11;public static BufferedImage fy12;public static BufferedImage fy13;public static BufferedImage fy14;public static BufferedImage fy15;public static BufferedImage fy16;public static BufferedImage fy17;
3public static BufferedImage zy1;public static BufferedImage zy2;public static BufferedImage zy3;public static BufferedImage zy4;public static BufferedImage zy5;public static BufferedImage zy6;public static BufferedImage zy7;public static BufferedImage zy8;public static BufferedImage zy9;public static BufferedImage zy10;public static BufferedImage zy11;public static BufferedImage zy12;public static BufferedImage zy13;public static BufferedImage zy14;public static BufferedImage zy15;public static BufferedImage zy16;
4//在静态代码块中对图片进行初始化操作金鲨银鲨游戏,静态代码块会随着类的加载就执行//而且只执行一次,所以静态代码块非常适合做资源加载static{try{buyu=ImageIO.read(FishGame.class.getResource("backgroundimage/buyu.jpg"));}catch( Exception e ){System.out.println("图片未找到");}}
5public void paint(Graphics g) {g.drawImage(buyu, 0, 0, null);for (int i = 0; i < Fy.length; i++) {Fy fy = Fy[i];g.drawImage(fy.image, fy.x, fy.y, null);}}
// 增加鱼// int index = 0;
public void addOneFy() {if (true) {Fy = Arrays.copyOf(Fy, Fy.length + 1);Fy[Fy.length - 1] = nextOneFy();}}
// 所有的鱼都移动一步public void stepAction() {for (int i = 0; i < Fy.length; i++) {Fy fy = Fy[i];fy.step();}}
身在繁忙都市,压力如影随形,焦虑、失眠、电子产品依赖等都是幸福感的隐形杀手。
本文由网上真钱棋牌游戏www.qpyouxi.net编辑整理,介绍各种网上真钱棋牌游戏技巧,澳门赌场博彩技巧,提供各种网上博彩游戏,网上真钱游戏,免费试玩。
Timer timer = new Timer();
public void action() {timer.schedule(new TimerTask() {
@Overridepublic void run() {addOneFy();stepAction();repaint();}
}, 0, 1000);}
// 产生一个Fy类的鱼public Fy nextOneFy() {return new Fy();}
6public static void main(String[] args) {JFrame frame = new JFrame();FishGame game = new FishGame();frame.add(game);frame.setTitle("捕鱼达人");frame.setSize(buyu.getWidth(), buyu.getHeight());frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setAlwaysOnTop(true);frame.setLocationRelativeTo(null);frame.setVisible(true);
game.action();}
END金鲨银鲨游戏