package MapT;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.KeyEvent;
import EnumT.ObjectType.WallType;
import EnumT.PanelType;
import EnumT.Status;
import EnumT.Status.Result;
import MapT.Map_Seting.BaseWllType;
import ObjectT.Arr2;
import ObjectT.ImgBox;
import ObjectT.ObjectT;
import ObjectT.Rectangle;
import ObjectT.Wall;
public class Map_Seting extends ObjectPanel implements Runnable{
private static final long serialVersionUID = 1L;
Arr2<WallArr> mapArr=null;
ImgBox tank_set=null;
Point p=null;
int key=-1;
public Map_Seting(MainFram parent) {
super(PanelType.map_seting, parent);
setLayout(null);
setSize(Map_War.WIDTH+Map_Score.WIDTH, Map_War.WIDTH);
setLocation(0,0);
setBackground(Color.GRAY);
}
public void InitMap_set(){
mapArr=new Arr2<WallArr>(Map_War.GRIDN, Map_War.GRIDN);
tank_set=new ImgBox(new Rectangle(0,0,Map_War.GRIDNE*Map_War.WIDTHE,Map_War.GRIDNE*Map_War.WIDTHE),100, "/STank/tank1_yellow_up1.png", this);
p=new Point(0,0);
add(tank_set);
BaseWllType.initIndex();
mapArr.set(5, 12, new WallArr(new Point(5,12),BaseWllType.bao, this));
}
protected void initialPanel() {
}
public void preDraw(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, Map_War.WIDTH, Map_War.WIDTH);
}
public void keyPressed(KeyEvent key){
switch (key.getKeyCode()) {
case KeyEvent.VK_ENTER:
{
Arr2<String> arr2=new Arr2<String>(mapArr.getM(), mapArr.getN());
boolean k=true;
for (int i = 0; i < arr2.getM(); i++) {
for (int j = 0; j < arr2.getN(); j++) {
String str="00";
WallArr wa=mapArr.get(j, i);
if(i<11||(i>=11&&(j<5||j>7))){
if(i==0&&(wa==null||wa.getBtype()==BaseWllType.nu)){
k=false;
}
if(wa==null){
str="nu";
}else{
str=wa.getBtype().toString();
}
}
arr2.set(i, j,str);
}
}
if(k){
arr2.set(0, 0, "nu");
arr2.set(0, 5, "nu");
arr2.set(0, 12, "nu");
}
RSourse.MapSourse.saveMap(arr2);
}
case KeyEvent.VK_ESCAPE:
MainFram.status=Status.selectMode;
MainFram.result=Result.exit;
removeAll();
setVisible(false);
getParent().change(false, true);
getParent().goBack();
break;
case KeyEvent.VK_SPACE:
{
WallArr warr=mapArr.get(p.x, p.y);
if(warr!=null){
warr.destroy();
}
mapArr.set(p.x, p.y,new WallArr(p,this.key==key.getKeyCode()? BaseWllType.next(): BaseWllType.get(), this));
}
break;
case KeyEvent.VK_UP:
{
if(p.y>0){
p.y--;
}
}
break;
case KeyEvent.VK_LEFT:
{
if(p.x>0){
p.x--;
}
}
break;
case KeyEvent.VK_RIGHT:
{
if(p.x<Map_War.GRIDN-1){
p.x++;
}
}
break;
case KeyEvent.VK_DOWN:
{
if(p.y<Map_War.GRIDN-1){
p.y++;
}
}
break;
default:
break;
}
tank_set.setLocation(p.x*Map_War.WIDTHE*Map_War.GRIDNE, p.y*Map_War.WIDTHE*Map_War.GRIDNE);
this.key=key.getKeyCode();
}
@Override
public void run() {
try {
while(MainFram.status==Status.setting){
tank_set.setCurIntList(0);
Thread.sleep(500);
tank_set.setCurIntList(-1);
Thread.sleep(300);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public enum BaseWllType{
nu,wr,wd,wl,wu,wa,sr,sd,sl,su,sa,se,ga,bao;
private static int index=1;
public static BaseWllType next(){
index= (++index)%(BaseWllType.values().length-1);
return BaseWllType.values()[index];
}
public static BaseWllType get(){
return BaseWllType.values()[index];
}
public static void initIndex(){
index=1;
}
}
}
class WallArr{
ObjectT[] wallarr=null;
BaseWllType btype=null;
ObjectPanel objp=null;
public WallArr(Point p,BaseWllType type,ObjectPanel objp) {
this.btype=type;
this.objp=objp;
if(type==BaseWllType.nu){
}
else if(type==BaseWllType.bao){
wallarr=new ObjectT[33];
int i=0;
for (ObjectT objectT : Wall.getWalls(objp)) {
wallarr[i++]=objectT;
}
wallarr[i]=Wall.getEWall(6, 12, WallType.bao, objp)[0];
}else{
wallarr=Wall.getEWall(p.x, p.y, Wall.getByValue(type.name()), objp);
}
add();
}
public void add(){
if(wallarr!=null){
objp.addAll(wallarr);
}
}
public BaseWllType getBtype() {
return btype;
}
public void destroy(){
if(wallarr!=null){
for (ObjectT objectT : wallarr) {
objectT.destroyE();
}
}
}
}