Skip to content

Instantly share code, notes, and snippets.

@mrlin0518
Created July 5, 2018 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrlin0518/e72e1f7746324c4cee19092e0a1001af to your computer and use it in GitHub Desktop.
Save mrlin0518/e72e1f7746324c4cee19092e0a1001af to your computer and use it in GitHub Desktop.
Game-使用DAO概念設計兩種JUDGE
package Judge;
public interface JudgeDAO {
void JUDGE(Enum Players, Enum computer);
JUDGE getValue();
}
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;
}
}
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;
}
}
package Judge;
public enum JudgeEnum {
平手, 贏, 輸;
}
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