Exemple #1
0
        //public Task<RoomInfo> WaitForRoomInfoUpdate(long uid)
        //{
        //    int roomKey;
        //    if (m_playings.TryGetValue(uid, out roomKey))
        //    {
        //        RoomInfo roomInfo;
        //        if (m_Hall.TryGetValue(roomKey, out roomInfo))
        //        {
        //            var tcs = new TaskCompletionSource<RoomInfo>();
        //            roomInfo.requestCallback += (response) =>
        //            {
        //                try
        //                {
        //                    tcs.SetResult(response);
        //                }
        //                catch (Exception e)
        //                {
        //                    tcs.SetException(e);
        //                }
        //            };

        //            return tcs.Task;
        //        }
        //    }
        //    return null;
        //}

        private void AIDiscard(RoomInfo room_info)
        {
            System.Timers.Timer timerClock = new System.Timers.Timer();
            timerClock.Elapsed += new ElapsedEventHandler((source, e) => {
                var player        = room_info.GetPlayer(room_info.discard_info.cur_uid);
                List <byte> cards = null;
                if (room_info.discard_info.pre_discard_uid <= 0 || room_info.discard_info.pre_discard_uid == room_info.discard_info.cur_uid)
                {
                    cards = TwillAI.ChooseCard(room_info.game, player.hand_cards, null);
                }
                else
                {
                    cards = TwillAI.ChooseCard(room_info.game, player.hand_cards, room_info.discard_info.pre_discard_cards, room_info.PreDiscardIsPartner());
                }

                if (cards != null)
                {
                    player.RemoveCards(cards);
                }

                NextPlayer(room_info, cards);
            });
            timerClock.Interval  = 1000;
            timerClock.AutoReset = false;
            timerClock.Enabled   = true;
        }
Exemple #2
0
 protected async void Start()
 {
     while (true)
     {
         DateTime now = DateTime.Now;
         foreach (var room in m_Hall)
         {
             if (room.Value.discard_info != null && room.Value.discard_info.wait_time <= now)
             {
                 List <byte> cards = null;
                 if (room.Value.MustDiscard())
                 {
                     cards = TwillAI.ChooseCard(room.Value.game, room.Value.GetDiscardPlayer().hand_cards, null);
                 }
                 NextPlayer(room.Value, cards);
             }
         }
         await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000);
     }
 }