用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

花花shij    -  云代码空间

——

Java坦克

2017-11-08|914阅||

摘要:package MapT; import java.awt.Color; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.io.IOException; impor

package MapT;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.swing.JFrame;
import EnumT.Status;
import EnumT.Status.Result;
import ObjectT.TankFactory;
import ObjectT.Wall;
public class MainFram extends JFrame implements Runnable{
 private static final long serialVersionUID = 1L;
 public static Status status=Status.begin;
 public static Result result=Result.exit;
 
 Map_War map_war=new Map_War(this);
 MainPanel mpanel=new MainPanel(this);
 Map_Score map_score=new Map_Score(this);
 Map_Seting map_set=new Map_Seting(this);
 
 public MainFram() {
  
  setTitle("̹坦克大战");
  setDefaultCloseOperation(EXIT_ON_CLOSE);  
  setLayout(null);  
  getContentPane().setBackground(Color.BLACK);
  setSize(Map_War.WIDTH+Map_Score.WIDTH,Map_War.WIDTH+29);
  setLocationRelativeTo(null);
  setResizable(false);
  setIconImage(RSourse.ImgSourse.getImgByPath("/SOthers/logo.png"));
  
  (new Thread(){
   public void run() {
    try {
     Thread.sleep(200);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
    add(mpanel);
    change(false, true);
    add(map_score);
    add(map_war);
    add(map_set);
    map_set.setVisible(false);
    addKeyListener(new KeyAdapter());
   };
  }).start();
  
  setVisible(true);
  status=Status.selectMode;
  status.setSstr(Status.Mode.SS.toString());
 }
 
 public void change(boolean v1,boolean v2){
  
  map_score.setVisible(v1);
  map_war.setVisible(v1);
  mpanel.setVisible(v2);
  repaint();
  if(v1){
   map_score.repaint();
   map_war.repaint();
  }else
  mpanel.repaint();
 }
 
 public void playGame(){
  map_score.IniMap_Score();
  map_score.TankNumberChanged(20);
  map_war.setSizeTank(0);
  ExecutorService exec=Executors.newCachedThreadPool();
  exec.execute(this);
  exec.execute(map_war);
  TankFactory tf=new TankFactory(map_war);
  exec.execute(tf);
  map_war.addScoreListener(map_score);
  tf.addScoreListener(map_score);
  
  exec.shutdown();
 }
 
 public void goBack(){
  try {
   Thread.sleep(500);
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  mpanel.changeFace(false);
 }
 
 class KeyAdapter implements KeyListener{
  @Override
  public void keyPressed(KeyEvent e) {
   switch (status){
   case begin:
   case exit:
   case gameOver:
   case selectClass:
   case selectMode:
    mpanel.KeyPress(e);
    break;
   case setting:
    map_set.keyPressed(e);
    break;
   case stop:
   case playingGame:
    //map_war.keyPress(e);
    break;
   default:
    break;
   }
  }
  
  public void keyReleased(KeyEvent e) {
  }
  
  public void keyTyped(KeyEvent e) {
  }
  
 }
 
 
 public void run() {
  
  try {
   Wall.IniMap_Panel(map_war.getState(), map_war);
  } catch (IOException e) {
   // TODO Auto-generated catch block
   System.err.println("错误");
   e.printStackTrace();
  }
  change(true, false);
  MainFram.status=Status.playingGame;
 }
 public Map_Score getMap_score() {
  return map_score;
 }
 public Map_War getMap_war() {
  return map_war;
 }
 public MainPanel getMpanel() {
  return mpanel;
 }
 public Map_Seting getMap_set() {
  return map_set;
 }
 
 public static void main(String[] args) {
  new MainFram();
 }
}
顶 0踩 0收藏
文章评论
    发表评论

    个人资料

    • 昵称: 花花shij
    • 等级: 初级程序员
    • 积分: 12
    • 代码: 0 个
    • 文章: 7 篇
    • 随想: 0 条
    • 访问: 4 次
    • 关注

    人气文章

    人气代码

      最新提问

        站长推荐