/*姣忎釜鏋氫妇鍏冪礌鍚勮〃绀轰竴涓柟鍚戠殑鎺у埗鐏�/
S2N("N2S","S2W",false),S2W("N2E","E2W",false),E2W("W2E","E2S",false),E2S("W2N","S2N",false),
/*涓嬮潰鍏冪礌琛ㄧず涓庝笂闈㈢殑鍏冪礌鐨勭浉鍙嶆柟鍚戠殑鐏紝瀹冧滑鐨勨�鐩稿弽鏂瑰悜鐏�鍜屸�涓嬩竴涓伅鈥濆簲蹇界暐涓嶈锛�/
N2S(null,null,false),N2E(null,null,false),W2E(null,null,false),W2N(null,null,false),
/*鐢卞崡鍚戜笢鍜岀敱瑗垮悜鍖楃瓑鍙虫嫄寮殑鐏笉鍙楃孩缁跨伅鐨勬帶鍒讹紝鎵�互锛屽彲浠ュ亣鎯冲畠浠�鏄豢鐏�/
S2E(null,null,true),E2N(null,null,true),N2W(null,null,true),W2S(null,null,true);
private Lamp(String opposite,String next,boolean lighted){
this.opposite = opposite;
this.next = next;
this.lighted = lighted;
}
/*褰撳墠鐏槸鍚︿负缁�/
private boolean lighted;
/*涓庡綋鍓嶇伅鍚屾椂涓虹豢鐨勫搴旀柟鍚�/
private String opposite;
/*褰撳墠鐏彉绾㈡椂涓嬩竴涓彉缁跨殑鐏�/
private String next;
public boolean isLighted(){
return lighted;
}
/**
* 鏌愪釜鐏彉缁挎椂锛屽畠瀵瑰簲鏂瑰悜鐨勭伅涔熻鍙樼豢
*/
public void light(){
this.lighted = true;
if(opposite != null){
Lamp.valueOf(opposite).light();
}
System.out.println(name() + " lamp is green锛屼笅闈㈡�鍏卞簲璇ユ湁6涓柟鍚戣兘鐪嬪埌姹借溅绌胯繃锛�);
}
/**
* 鏌愪釜鐏彉绾㈡椂锛屽搴旀柟鍚戠殑鐏篃瑕佸彉绾紝骞朵笖涓嬩竴涓柟鍚戠殑鐏鍙樼豢
* @return 涓嬩竴涓鍙樼豢鐨勭伅
*/
public Lamp blackOut(){
this.lighted = false;
if(opposite != null){
Lamp.valueOf(opposite).blackOut();
}
Lamp nextLamp= null;
if(next != null){
nextLamp = Lamp.valueOf(next);
System.out.println("缁跨伅浠� + name() + "-------->鍒囨崲涓� + next);
nextLamp.light();
}
return nextLamp;
}
}
|