2.运用函数的重载提升代码的重用性,提高程序可读性,节省类似类的重复定义。 在本程序中将敌机,我机,和boss飞机定义在同一个类的构造函数中,使用不同参数区分
public Plane(JPanel p,Graphics g){ //我方飞机构造方法 } public Plane(Graphics g,JPanel p){ // boss飞机构造方法 } public Plane(JPanel p){ // 敌人飞机构造方法 } 我方子弹、敌方子弹、boss子弹在Bullet中用构造函数重载区别
public Bullet(int x,int y){ //我方子弹的构造函数 } public Bullet(ArrayList<Plane> enemyplanelist,ArrayList<Bullet> enemybulletlist){ //敌方子弹的构造函数 } public Bullet(Plane bossplane){ //Boss子弹的构造函数 }
3.IO流的使用,在java中,数据随着程序的关闭而销毁,若想保存数据这需要用到数据库或文件流存储,在此用到了文件流。 使用到了原始流FileInputStream、FileOutputStream
处理流DataInputStream、DataOutputStream