(100 puntos) Java escribe "Batalla de tanques"
paquete com.bjsxt.tank;
importar java.awt.Color;
importar java.awt.Frame;
importar java.awt.Graphics;
importar java.awt.Image;
importar java.awt.event.KeyAdapter;
importar java.awt.event. KeyEvent;
importar java.awt.event.WindowAdapter;
importar java.awt.event.WindowEvent;
importar java.io.IOException; p>
importar java.awt.event.WindowEvent;
importar java.io.IOException;
p>
importar java.util.ArrayList;
importar java.util.List;
importar java.util.Properties;
/**
* Esta clase se utiliza como clase principal ventana del juego de tanques
* @author mashibing
*
*/
public class TankClient extends Frame {
/**
* El ancho de todo el juego de tanques
*/
public static final int GAME_WIDTH = 800;
public static final int GAME_HEIGHT = 600;
Tank myTank = new Tank(50, 50, true, Direction.STOP, this);
Wall w1 = new Wall(100 , 200, 20, 150, esto), w2 = new Wall(300, 100, 300, 20, this);
Lista
Lista
Lista
Imagen offScreenImage = null; ;
Sangre b = nueva Sangre();
public void paint(Gráficos g) {
/ *
* Especificar el número de balas, explosiones y tanques
* y la salud del tanque
*/
g.drawString( "recuento de misiles:" + misiles.tamaño (), 10, 50);
g.drawString("recuento de explosiones:" + explodes.size(), 10, 70);
g.drawString("recuento de tanques :" + tanks.size(), 10, 90);
g.drawString("vida de los tanques
:" + myTank.getLife(), 10, 110);
if(tanks.size() <= 0) {
for(int i=0; i tanks.add(new Tank(50 + 40*(i+1), 50, false, Direction.D, this) ); } } for(int i=0; i Misil m = misiles.get(i); m.hitTanks(tanques); m.hitTank(myTank); m.hitWall(w1 ); m.hitWall(w2); m.draw(g); //if(!m.isLive()) misiles. remove(m); //else m.draw(g); } for(int i=0; i Explotar e = explota.get(i); e.draw(g); } for(int i=0; i Tanque t = tanks.get(i); t.collidesWithWall(w1); t.collidesWithWall(w2); t.collidesWithTanks(tanques); t.draw(g); } miTanque.draw(g); miTanque.eat(b); w1.draw(g); w2 .draw(g); b.draw(g); } actualización pública de vacío (Gráficos g) { if(offScreenImage == null) { offScreenImage = this.createImage(GAME_WIDTH, GAME_HEIGHT); } Gráficos gOffScreen = offScreenImage.getGraphics(); Color c = gOffScreen.getColor(); gOffScreen.setColor(Color.BLACK); gOffScreen.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT ); gOffScreen.setColor(c); paint(gOffScreen); g.drawImage(offScreenImage, 0, 0, null); p> p> } /** * Este método muestra la ventana principal del tanque * */ public void lauchFrame() { int initTankCount = Integer. parseInt (PropertyMgr.getProperty("initTankCount")); for(int i=0; i tanks.add(new Tank(50 + 40 * (i+1), 50, false, Dirección.D, esto)); } //this.setLocation(400, 300); this.setSize(GAME_WIDTH, GAME_HEIGHT); this.setTitle("TankWar"); this.addWindowListener(new WindowAdapter() { ventana vacía públicaClosing(WindowEvent e) { System.exit(0); } }); this.setResizable (falso); this.setBackground(Color.GREEN); this.addKeyListener(new KeyMonitor()); setVisible(true); new Thread(new PaintThread()).start(); } public static void main(String[] args) { TankClient tc = new TankClient(); tc.lauchFrame(); } la clase privada PaintThread implementa Runnable { public void run() { while(true) { repaint(); prueba { Thread. dormir(50 ); } captura (InterruptedException e) { e.printStackTrace(); } } p> } } clase privada KeyMonitor extiende KeyAdapter { public void keyReleased(KeyEvent e) { myTank .keyReleased( e); } public void keyPressed(KeyEvent e) { myTank.keyPressed(e); } p> } }