package gui;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
public class MyTankGames extends JFrame{
MyPanel3 mp=null;
public static void main(String[] args) {
MyTankGames mtg=new MyTankGames();
}
public MyTankGames(){
mp=new MyPanel3();
this.add(mp);
Thread t1=new Thread(mp);
t1.start();
this.addKeyListener(mp);
this.setTitle("坦克大战");
this.setSize(900, 900);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
class MyPanel3 extends JPanel implements KeyListener,Runnable{
Hero hero=null;
Vector<Enermy> ets=new Vector<Enermy>();
int size=4;
public MyPanel3()
{
hero=new Hero(50,50);
for(int i=0;i<size;i++)
{
Enermy et=new Enermy((i+1)*50,0);
et.setColor(1);
et.setDirection(2);
ets.add(et);
}
}
public void paint(Graphics g){
super.paint(g);
this.drawTank(hero.getX(), hero.getY(), g, hero.getDirection(), 0);
for(int i=0;i<ets.size();i++)
{
this.drawTank(ets.get(i).getX(), ets.get(i).getY(), g, ets.get(i).getDirection(), 1);
}
if(hero.s!=null&&hero.s.isLive==true)
{
g.setColor(Color.BLACK);
g.draw3DRect(hero.s.x, hero.s.y, 1, 1, false);
}
}
public void drawTank(int x,int y,Graphics g,int direction,int type)
{
switch(type)
{
case 0:
g.setColor(Color.CYAN);
break;
case 1:
g.setColor(Color.YELLOW);
break;
}
switch(direction)
{
case 0:
g.fill3DRect(x, y, 5, 30,false);
g.fill3DRect(x+15, y, 5, 30,false);
g.fill3DRect(x+5, y+5, 10, 20,false);
g.fillOval(x+4, y+10, 10,10);
g.drawLine(x+9, y+15,x+9,y);
break;
case 1:
g.fill3DRect(x, y, 30, 5,false);
g.fill3DRect(x, y+15, 30, 5,false);
g.fill3DRect(x+5, y+5, 20, 10,false);
g.fillOval(x+10, y+5, 10,10);
g.drawLine(x+15, y+10,x+30,y+10);
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
public class MyTankGames extends JFrame{
MyPanel3 mp=null;
public static void main(String[] args) {
MyTankGames mtg=new MyTankGames();
}
public MyTankGames(){
mp=new MyPanel3();
this.add(mp);
Thread t1=new Thread(mp);
t1.start();
this.addKeyListener(mp);
this.setTitle("坦克大战");
this.setSize(900, 900);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
class MyPanel3 extends JPanel implements KeyListener,Runnable{
Hero hero=null;
Vector<Enermy> ets=new Vector<Enermy>();
int size=4;
public MyPanel3()
{
hero=new Hero(50,50);
for(int i=0;i<size;i++)
{
Enermy et=new Enermy((i+1)*50,0);
et.setColor(1);
et.setDirection(2);
ets.add(et);
}
}
public void paint(Graphics g){
super.paint(g);
this.drawTank(hero.getX(), hero.getY(), g, hero.getDirection(), 0);
for(int i=0;i<ets.size();i++)
{
this.drawTank(ets.get(i).getX(), ets.get(i).getY(), g, ets.get(i).getDirection(), 1);
}
if(hero.s!=null&&hero.s.isLive==true)
{
g.setColor(Color.BLACK);
g.draw3DRect(hero.s.x, hero.s.y, 1, 1, false);
}
}
public void drawTank(int x,int y,Graphics g,int direction,int type)
{
switch(type)
{
case 0:
g.setColor(Color.CYAN);
break;
case 1:
g.setColor(Color.YELLOW);
break;
}
switch(direction)
{
case 0:
g.fill3DRect(x, y, 5, 30,false);
g.fill3DRect(x+15, y, 5, 30,false);
g.fill3DRect(x+5, y+5, 10, 20,false);
g.fillOval(x+4, y+10, 10,10);
g.drawLine(x+9, y+15,x+9,y);
break;
case 1:
g.fill3DRect(x, y, 30, 5,false);
g.fill3DRect(x, y+15, 30, 5,false);
g.fill3DRect(x+5, y+5, 20, 10,false);
g.fillOval(x+10, y+5, 10,10);
g.drawLine(x+15, y+10,x+30,y+10);