package MapT;
import java.awt.Color;
import java.awt.Point;
import EnumT.ObjectType.TankType;
import EnumT.PanelType;
import ObjectT.ObjString;
public class Map_Score extends ObjectPanel implements ScoreListener{
private static final long serialVersionUID = 1L;
public static final int WIDTH=200;
private int player1=3;
private int player2=-1;
private int tankNumber=20;
private int tank1=0;
private int tank2=0;
private int tank3=0;
ObjString[] objstrs=new ObjString[4];
public Map_Score(MainFram parent) {
super(PanelType.map_score,parent);
player1=3;
player2=-1;
tankNumber=20;
tank1=0;
tank2=0;
tank2=0;
objstrs[0]=new ObjString(new Point(20,180), String.format("̹坦克数量: %2d",tankNumber) , this);
objstrs[1]=new ObjString(new Point(20,180+80),String.format("player1: %d", player1) , this);
objstrs[2]=new ObjString(new Point(20,180+160), String.format("player2: %d", player2) , this);
objstrs[3]=new ObjString(new Point(20,180+400), String.format("关卡: %2d", ((MainFram)getParent()).getMap_war().getState()), this);
IniMap_Score();
}
public void IniMap_Score(){
add(objstrs[0]);
add(objstrs[1]);
if(player2>=0)add(objstrs[2]);
else remove(objstrs[2]);
add(objstrs[3]);
StateChanged(getParent().getState());
}
public void StateChanged(int state) {
objstrs[3].setContent(String.format("关卡: %2d",((MainFram)getParent()).getMap_war().getState()));
}
protected void initialPanel() {
setBackground(Color.GRAY);
setSize(WIDTH, Map_War.WIDTH);
setLocation(Map_War.WIDTH,0);
}
public void LifeTimeChanged(int tag, int lifeTime) {
if(tag==1){
//System.err.println(MainFram.status+":"+lifeTime);
player1=lifeTime;
objstrs[1].setContent(String.format("player1: %d", player1));
}else{
player2=lifeTime;
if(player2>=0){
if(!Contain(objstrs[2]))add(objstrs[2]);
objstrs[2].setContent(String.format("player2: %d", player2));
}
}
if(player1<=0&&player2<=0){
((MainFram)getParent()).getMap_war().gameOver();
}
}
public void TankNumberChanged(int tankNumber) {
this.tankNumber=tankNumber;
if(tankNumber==20){
tank1=tank2=tank3=0;
}
objstrs[0].setContent(String.format("坦克数量: %2d", tankNumber));
}
public void TankDestroyed(TankType tanktype) {
switch (tanktype) {
case tank1:
tank1++;
break;
case tank2:
tank2++;
break;
case tank3:
tank3++;
break;
default:
break;
}
if( tank1+tank2+tank3>=20&&tankNumber==0){
((MainFram)getParent()).getMap_war().nextClass();
}
}
public int getTank1() {
int t1=tank1;
tank1=0;
return t1;
}
public int getTank2() {
int t2=tank2;
tank2=0;
return t2;
}
public int getTank3() {
int t3=tank3;
tank3=0;
return t3;
}
public void setPlayer1(int player1) {
this.player1 = player1;
}
public void setPlayer2(int player2) {
this.player2 = player2;
}
}