package extend.mj; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import com.game.Global; import extend.mj.player.rule.RuleChow; import extend.mj.player.rule.RuleHaidi; import extend.mj.player.rule.RuleOtherKong; import extend.mj.player.rule.RuleOtherOpenKong; import extend.mj.player.rule.RuleOtherWin; import extend.mj.player.rule.RulePong; import extend.mj.player.rule.RulePongKong; import extend.mj.player.rule.RulePongOpenKong; import extend.mj.player.rule.RuleQSWin; import extend.mj.player.rule.RuleSelfKong; import extend.mj.player.rule.RuleSelfOpenKong; import extend.mj.player.rule.RuleSelfWin; import extend.mj.player.rule.RuleZTWin; import extend.mj.player.state.EXPlayerDisCardTipState; import extend.mj.player.state.EXPlayerDrawTipState; import extend.mj.player.state.EXPlayerHaidiTipState; import extend.mj.player.state.EXPlayerKongWinState; import extend.mj.player.state.EXPlayerQSWinTipState; import extend.mj.player.state.EXPlayerTipState; import extend.mj.player.state.EXPlayerZTWinTipState; import extend.mj.tip.IRuleBase; /** * */ public class PlayerRuleManager { public static final int DRAW_RULE = 1; public static final int OTHER_DISCARD_RULE = 2; public static final int KONG_HU_RULE = 3; public static final int QS_HU_RULE = 4; public static final int OPENKONG_RULE = 5; public static final int HAIDI_RULE = 6; public static final int CHOW_PONG_DISCARD_RULE = 7; public static final int ZT_HU_RULE = 8; public HashMap> ruleMap = null; public HashMap tipMap = null; public PlayerRuleManager() { ruleMap = new HashMap>(); tipMap = new HashMap(); tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); tipMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); tipMap.put(PlayerRuleManager.KONG_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerKongWinState.class)); tipMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); tipMap.put(PlayerRuleManager.QS_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerQSWinTipState.class)); tipMap.put(PlayerRuleManager.OPENKONG_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); tipMap.put(PlayerRuleManager.HAIDI_RULE, (EXPlayerTipState) Global.getState(EXPlayerHaidiTipState.class)); tipMap.put(PlayerRuleManager.ZT_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerZTWinTipState.class)); List drawRuleList = new ArrayList(); drawRuleList.add(new RuleSelfKong()); drawRuleList.add(new RuleSelfOpenKong()); drawRuleList.add(new RulePongKong()); drawRuleList.add(new RulePongOpenKong()); drawRuleList.add(new RuleSelfWin()); ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); List otherDiscardList = new ArrayList(); otherDiscardList.add(new RuleChow()); otherDiscardList.add(new RulePong()); otherDiscardList.add(new RuleOtherKong()); otherDiscardList.add(new RuleOtherOpenKong()); otherDiscardList.add(new RuleOtherWin()); ruleMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, otherDiscardList); List konghuList = new ArrayList(); konghuList.add(new RuleOtherWin()); ruleMap.put(PlayerRuleManager.KONG_HU_RULE, konghuList); List qshuList = new ArrayList(); qshuList.add(new RuleQSWin()); ruleMap.put(PlayerRuleManager.QS_HU_RULE, qshuList); List cpDiscardRuleList = new ArrayList(); cpDiscardRuleList.add(new RuleSelfKong()); cpDiscardRuleList.add(new RuleSelfOpenKong()); cpDiscardRuleList.add(new RulePongKong()); cpDiscardRuleList.add(new RulePongOpenKong()); ruleMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, cpDiscardRuleList); List openkongList = new ArrayList(); openkongList.add(new RuleChow()); openkongList.add(new RulePong()); openkongList.add(new RuleOtherKong()); openkongList.add(new RuleOtherOpenKong()); openkongList.add(new RulePongOpenKong()); openkongList.add(new RuleOtherWin()); openkongList.add(new RuleSelfWin()); ruleMap.put(PlayerRuleManager.OPENKONG_RULE, openkongList); List haidiList = new ArrayList(); haidiList.add(new RuleHaidi()); ruleMap.put(PlayerRuleManager.HAIDI_RULE, haidiList); List zthuList = new ArrayList(); zthuList.add(new RuleZTWin()); ruleMap.put(PlayerRuleManager.ZT_HU_RULE, zthuList); } public boolean condition(int type, EXPlayer player) { return condition(type, player, true); } public boolean condition(int type, EXPlayer player, boolean tonextState) { player.getRoom().actionWinList.clear(); List ruleList = this.ruleMap.get(type); boolean result = false; for (IRuleBase rule : ruleList) { result = rule.condition(player) || result; } if (result) { player.stateMachine.changeState(this.tipMap.get(type)); } else { if (tonextState) player.stateMachine.toNextState(); } return result; } }