关于使用JAVA实现坦克大战练习后的感想

  1. 首先,基础!基础!基础!用的全部都是基础的知识,只是连接了起来!
  2. 然后,思想!思想!思想!编程的思想一定要锻炼出来!
  3. 再就是,细节!细节!细节!很多语句及各种类/接口/枚举等使用上的细节务必注意!!!

     只是做了一个Demo,因为生疏了,花了一天时间,想想就很气,尤其气自己平时的小聪明.

The specification of Class/Interface  and method
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);
     
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值