Java坦克大战游戏设计 下载本文

内容发布更新时间 : 2024/5/6 1:19:10星期一 下面是文章的全部内容请认真阅读。

Java大作业报告(截止5月20日)

五、游戏软件的主要界面截图

六、程序代码:

import javax.swing.*;

public class TankGame extends JFrame { //面板

MyPanel mp = null;

public static void main(String[] args) { //创建窗口

TankGame tankegame = new TankGame(); }

//构造函数

Java大作业报告(截止5月20日)

public TankGame(){ //创建面板对象 mp = new MyPanel(); //将面板添加到JFrame this.add(mp);

this.addKeyListener(mp);

//启动面板线程,让其paint方法不断调用,从而不断刷新,达到动态效果

Thread t = new Thread(mp); t.start(); //设置窗口大小

this.setSize(400,300); //设置小图标

this.setIconImage(new

ImageIcon(\).getImage());

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setVisible(true); } }

Java大作业报告(截止5月20日)

********************************************** public class Tank { //坦克的很坐标 int x; //坦克的纵坐标 int y; //坦克的方向

//0表示上,1右,2下,3表示左 int direct=0; //坦克的速度 int speed=4; //坦克的外观 int color=0; //坦克是否死亡

boolean isLive =true;

public int getColor() { return color; }

public void setColor(int color) { this.color = color;

Java大作业报告(截止5月20日)

} public int getSpeed() { return speed; } public void setSpeed(int speed) { this.speed = speed; } public int getDirect() { return direct; } public void setDirect(int direct) { this.direct = direct; }

public Tank(int x,int y){ this.x = x; this.y = y; }

Java大作业报告(截止5月20日)

public int getX() { return x; }

public void setX(int x) { this.x = x; }

public int getY() { return y; }

public void setY(int y) { this.y = y; } }

*********************************************** import java.util.Vector;

public class Hero extends Tank{ //放置子弹的类集框架

Vector ss= new Vector(); //子弹