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();
}
}