public void TestFuruRon() { Semaphore semaphore = new Semaphore(0, 4); LoveLive_MahjongClass.InitializeMahjongClass(); MahjongLogic mahjongLogic = new MahjongLogic(); // 反射,强行配置玩家顺序 FieldInfo field = mahjongLogic.GetType().GetField("order", BindingFlags.NonPublic | BindingFlags.Instance); field.SetValue(mahjongLogic, new int[] { 0, 1, 2, 3 }); field = mahjongLogic.GetType().GetField("playing", BindingFlags.NonPublic | BindingFlags.Instance); field.SetValue(mahjongLogic, 3); // 配置一些可以副露和荣和的牌组 // 玩家A(等待杠Ruby) mahjongLogic.player_info[0].card_onhand = new List <MahjongCard>() { LoveLive_MahjongClass.GetCard(MahjongCardName.Ruby), LoveLive_MahjongClass.GetCard(MahjongCardName.Ruby), LoveLive_MahjongClass.GetCard(MahjongCardName.Ruby), }; // 玩家B(等待吃Ruby(年级)) mahjongLogic.player_info[1].card_onhand = new List <MahjongCard>() { LoveLive_MahjongClass.GetCard(MahjongCardName.Yoshiko), LoveLive_MahjongClass.GetCard(MahjongCardName.Hanamaru), }; // 玩家C(等待荣Ruby) mahjongLogic.player_info[2].waiting.Add(LoveLive_MahjongClass.GetCard(MahjongCardName.Ruby)); // 当前D (打出了Ruby) mahjongLogic.player_info[3].card_played.Add(LoveLive_MahjongClass.GetCard(MahjongCardName.Ruby)); // 设置回调 mahjongLogic.PlayerActionResponseCallback = delegate(List <PlayerAction> actions) { foreach (PlayerAction act in actions) { Trace.WriteLine(act.ToString()); } semaphore.Release(); }; mahjongLogic.PlayerActionAcceptedCallback = delegate(int playerId, bool accept) { Trace.WriteLine($"ID = {playerId}, Accept = {accept}"); semaphore.Release(); }; // 强行设定状态机 mahjongLogic.StartGamingThread(); mahjongLogic.gameStateMachine.SetState(MahjongLogic.GameStateMachine.State.SendPlayerAction); mahjongLogic.gameStateMachine.ReleaseSemaphore(); // 等待回调执行完毕后再继续 semaphore.WaitOne(); // 模拟发送消息 mahjongLogic.SendPlayerAction(new PlayerAction(2) { actionType = PlayerActionType.Cancel }); //mahjongLogic.SendPlayerAction(new PlayerAction(1) { actionType = PlayerActionType.Cancel }); mahjongLogic.SendPlayerAction(new PlayerAction(0) { actionType = PlayerActionType.Pong }); // 等待回调执行完毕后再继续 semaphore.WaitOne(); semaphore.WaitOne(); semaphore.WaitOne(); }
public void CreatePlayerActionPanel(int playerId, bool[] actions) { int location = GetPlayerLocation(playerId); Grid panel = grdsPlayerAction[location]; panel.Children.Clear(); string[] actions_str = { "吃(年级)", "吃(小组)", "碰", "杠", "荣", "自摸", "取消" }; for (int i = 0; i < 6; i++) { Button btnAction = new Button() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Width = 60, Content = actions_str[i], IsEnabled = actions[i], Margin = new Thickness(10 + (i * 63), 10, 0, 0), }; int f_i = i; btnAction.Click += delegate { if ((f_i == 0) || (f_i == 1)) { // Chi IEnumerable <PlayerAction> acts = (from action in playerActionGroup where action.Key == playerId select action).First().ToList(); PlayerActionType type = ConvertType(f_i); IEnumerable <PlayerAction> act = from action in acts where action.actionType == type select action; int q = ShowChiDetermineDialog(playerId, act); mahjongLogic.SendPlayerAction(act.ToList()[q]); grdsPlayerAction[location].Children.Clear(); } else { IEnumerable <PlayerAction> acts = (from action in playerActionGroup where action.Key == playerId select action).First().ToList(); PlayerActionType type = ConvertType(f_i); PlayerAction act; if (type == PlayerActionType.Kong) { act = (from action in acts where (action.actionType == PlayerActionType.Kong) || (action.actionType == PlayerActionType.Kong_Add) || (action.actionType == PlayerActionType.Kong_Self) select action).First(); } else { act = (from action in acts where action.actionType == type select action).First(); } mahjongLogic.SendPlayerAction(act); grdsPlayerAction[location].Children.Clear(); } }; panel.Children.Add(btnAction); } Button btnCancel = new Button() { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Width = 60, Content = actions_str[6], Margin = new Thickness(10 + (6 * 63), 10, 0, 0), }; btnCancel.Click += delegate { mahjongLogic.SendPlayerAction(new PlayerAction(playerId) { actionType = PlayerActionType.Cancel }); grdsPlayerAction[location].Children.Clear(); }; panel.Children.Add(btnCancel); }