java之坦克大战(一)

package 坦克游戏第二版;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
public class TanKe extends JFrame{
	MyPanel mp = null;
	public TanKe() {
		// TODO Auto-generated constructor stub
		mp = new MyPanel(400,400,0,2,0);
		this.add(mp);
		this.addKeyListener(mp);
		this.setSize(500, 500); // 设置框体大小
		this.setLocation(400, 150); // 设置框体显示的位置
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置框体退出
		this.setVisible(true); // 显示框体
	}
	public static void main(String[] args) {
		TanKe tk = new TanKe();
	}
}

class MyPanel extends JPanel implements KeyListener{	
	Tank tank = null;  // 采用多态的形式编写代码
	Vector vc = null;
	int enSize = 3;
	public MyPanel(int x,int y,int color,int speed,int direct) {
		tank = new Hero(x, y, speed, color, direct); // 多态
		vc = new Vector(); // 存放敌人坦克的容器
		for(int i=0;i

你可能感兴趣的:(java程序设计)