Created
July 5, 2018 10:41
-
-
Save mrlin0518/e72e1f7746324c4cee19092e0a1001af to your computer and use it in GitHub Desktop.
Game-使用DAO概念設計兩種JUDGE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Judge; | |
public interface JudgeDAO { | |
void JUDGE(Enum Players, Enum computer); | |
JUDGE getValue(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Judge; | |
import Create.CreateDAO; | |
import Create.CreateDAOFactory; | |
public class judgeDAOImp implements JudgeDAO { | |
private JUDGE Value; | |
@Override | |
public void JUDGE(Enum play, Enum con) { | |
int c = con.ordinal(); | |
int p = play.ordinal(); | |
if (p == 1 && c == 3) { | |
this.Value = JUDGE.贏; | |
} else if (p == 3 && c == 1) { | |
this.Value = JUDGE.輸; | |
} else if (p > c) { | |
this.Value = JUDGE.贏; | |
} else if (c > p) { | |
this.Value = JUDGE.輸; | |
} else if (c == p) { | |
this.Value = JUDGE.平手; | |
} | |
} | |
public JUDGE getValue() { | |
return Value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Judge; | |
import javax.swing.JOptionPane; | |
public class judgeDAOImp2 implements JudgeDAO { | |
private JUDGE Value; | |
@Override | |
public void JUDGE(Enum ply, Enum con) { | |
int c = con.ordinal(); | |
int p = ply.ordinal(); | |
if (p == 1 && c == 3) { | |
this.Value = JUDGE.贏; | |
} else if (p == 3 && c == 1) { | |
this.Value = JUDGE.輸; | |
} else if (p > c) { | |
this.Value = JUDGE.贏; | |
} else if (c > p) { | |
this.Value = JUDGE.輸; | |
} else if (c==p) { | |
this.Value = JUDGE.平手; | |
} | |
} | |
@Override | |
public JUDGE getValue() { | |
return Value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Judge; | |
public enum JudgeEnum { | |
平手, 贏, 輸; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Judge; | |
public class judgerDAOFactory { | |
public JudgeDAO creatJudge(){ | |
return new judgeDAOImp2(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment