- 首先,基础!基础!基础!用的全部都是基础的知识,只是连接了起来!
- 然后,思想!思想!思想!编程的思想一定要锻炼出来!
- 再就是,细节!细节!细节!很多语句及各种类/接口/枚举等使用上的细节务必注意!!!
只是做了一个Demo,因为生疏了,花了一天时间,想想就很气,尤其气自己平时的小聪明.
Class | Father:Element Son:SteelWall,WaterWal,Wall,GrassWall,Tank(MyTank,EnemyTank),Blast,Bullet | |||
Interface | Config,Moveable,Hitable,Destroyable,Blockable,Attackable | |||
Enum | Direction,(Keyboard ->UP,DOWN,RIGHT,LEFT) | |||
Package | libs\jar , |
// The method of using important
public Window(String title, int width, int height, int fps);
public final void start();
protected abstract void onCreate();
protected abstract void onKeyEvent(int key);
protected abstract void onDisplayUpdate()
public boolean checkHit(Blockable blockable);
public abstract boolean checkAttack(Hitable hitable);
public abstract boolean isDestroy();
public abstract Blast showAttack();
//Window子类
package com.itheima.game;
import com.itheima.game.business.*;
import com.itheima.game.Inter.Config;
import com.itheima.game.Inter.Direction;
import com.itheima.game.domain.*;
import org.itheima.game.DrawUtils;
import org.itheima.game.SoundUtils;
import org.itheima.game.Window;
import org.lwjgl.input.Keyboard;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.concurrent.CopyOnWriteArrayList;
public class GameWindow extends Window {
MyTank mt;
EnemyTank et1;
EnemyTank et2;
CopyOnWriteArrayList<Element> cwlist = new CopyOnWriteArrayList<>();
public GameWindow(String title, int width, int height, int fps) {
super(title, width, height, fps);
}
@Override
protected void onCreate() {
for (int i = 1; i < Config.WIDTH / 64; i++) {
if (i != 12) {
Wall wall = new Wall(i * 64, 64 * 5);
cwlist.add(wall);
}
}
for (int i = 1; i < Config.WIDTH / 64; i++) {
Water water = new Water(i * 64, 64 * 3);
cwlist.add(water);
}
for (int i = 0; i < Config.WIDTH / 64 - 1; i++) {
if (i != 6) {
Steel steel = new Steel(i * 64, 64 * 1);
cwlist.add(steel);
}
}
for (int i = 1; i < Config.WIDTH / 64; i++) {
Grass grass = new Grass(i * 64, 64 * 7);
cwlist.add(grass);
}
mt = new MyTank(Config.WIDTH / 2 - 32, Config.HEIGHT - 64);
cwlist.add(mt);
et1 = new EnemyTank(0, 0);
et2 = new EnemyTank(Config.WIDTH - 64, 0);