Example #1
0
        /// <summary>
        /// 在押分的前一秒发送
        /// </summary>
        public void SendBetStartToHttpServer()
        {
            //如果本场是最后一场
            if (Game.Instance.RoundIndex + 1 == Setting.Instance._round_num_per_session)
            {
                return;
            }
            var msg = new ParamToServer()
            {
                RoundIndex   = Game.Instance.RoundIndex + 1,  //这里是下一场的场数
                SessionIndex = Game.Instance.SessionIndex,
                Countdown    = Setting.Instance._betTime + 1, //线上接收到后要减一
                State        = (int)GameState.Betting,
                Winner       = -1
            };

            var ip = Setting.Instance.ServerUrl;
            //var url = "http://" + ip + ":98/getmsg";
            var url = "http://" + ip + ":" + Settings.Default.port + "/" + Settings.Default.url;

            string Cards   = "";
            var    str     = JsonConvert.SerializeObject(msg);
            var    waybill = JsonConvert.SerializeObject(Game.Instance.HistoryWaybill);

            url += ("?" + "msg=" + str + "&waybill=" + waybill + "&cards=" + Cards + "&room=" + Settings.Default.Room);

            try
            {
                httpClient.GetAsync(url);
                //LogHelper.WriteLog(typeof(Object), "发送提前倒计时:" + (Setting.Instance._betTime + 1) + "  时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"));
            }
            catch (Exception)
            {
            }
        }
Example #2
0
        public void SendDealStartToHttpServer()
        {
            var msg = new ParamToServer()
            {
                RoundIndex   = Game.Instance.RoundIndex,
                SessionIndex = Game.Instance.SessionIndex,
                Countdown    = 0,
                State        = (int)GameState.Dealing,
                Winner       = (int)Game.Instance.CurrentRound.Winner.Item1,
            };

            var ip = Setting.Instance.ServerUrl;
            //var url = "http://" + ip + ":98/getmsg";
            var url = "http://" + ip + ":" + Settings.Default.port + "/" + Settings.Default.url;
            var str = JsonConvert.SerializeObject(msg);

            string Cards   = "";
            var    waybill = JsonConvert.SerializeObject(Game.Instance.HistoryWaybill);

            Cards = JsonConvert.SerializeObject(Game.Instance.CardsForDeal);
            url  += ("?" + "msg=" + str + "&waybill=" + waybill + "&cards=" + Cards + "&room=" + Settings.Default.Room);

            try
            {
                httpClient.GetAsync(url);
            }
            catch (Exception)
            {
            }
        }
Example #3
0
        public void SendToHttpServer()
        {
            if (Game.Instance._isSendingToServer)
            {
                if (Game.Instance.PriorCountDown != Game.Instance.CountDown)
                {
                    Game.Instance.PriorCountDown = Game.Instance.CountDown;

                    if (Game.Instance.CurrentState != Game.Instance.PriorState)
                    {
                        Game.Instance.PriorState = Game.Instance.CurrentState;
                    }

                    var msg = new ParamToServer()
                    {
                        RoundIndex   = Game.Instance.RoundIndex,
                        SessionIndex = Game.Instance.SessionIndex,
                        Countdown    = Game.Instance.CountDown,
                        State        = (int)Game.Instance.CurrentState,
                        Winner       = -1
                    };
                    //LogHelper.WriteLog(typeof(Object), "发送普通倒计时:" + Game.Instance.CountDown + "  时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"));

                    var ip = Setting.Instance.ServerUrl;
                    //var url = "http://" + ip + ":98/getmsg";
                    var url = "http://" + ip + ":" + Settings.Default.port + "/" + Settings.Default.url;

                    string Cards = "";
                    if (Game.Instance.CurrentState == GameState.Dealing)
                    {
                        msg.Winner = (int)Game.Instance.CurrentRound.Winner.Item1;
                        Cards      = JsonConvert.SerializeObject(Game.Instance.CardsForDeal);
                    }
                    var str     = JsonConvert.SerializeObject(msg);
                    var waybill = JsonConvert.SerializeObject(Game.Instance.HistoryWaybill);
                    url += ("?" + "msg=" + str + "&waybill=" + waybill + "&cards=" + Cards + "&room=" + Settings.Default.Room);

                    try
                    {
                        httpClient.GetAsync(url);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Example #4
0
        public void SendBoomToHttpServer()
        {
            var msg = new ParamToServer()
            {
                RoundIndex   = Game.Instance.RoundIndex,
                SessionIndex = Game.Instance.SessionIndex,
                Countdown    = Game.Instance.CountDown,
                State        = (int)GameState.Booming,
                Winner       = (int)Game.Instance.CurrentRound.Winner.Item1,
            };

            var ip  = Setting.Instance.ServerUrl;
            var url = "http://" + ip + ":98/getmsg";
            var str = JsonConvert.SerializeObject(msg);

            ArrayList arr = new ArrayList();

            for (int i = 0; i < Game.Instance.CurrentSession.RoundNumber; i++)
            {
                arr.Add(Game.Instance.CurrentSession.RoundsOfSession[i].Winner.Item1);
            }
            var waybill = JsonConvert.SerializeObject(arr);

            url += ("?" + "msg=" + str + "&waybill=" + waybill + "&room=" + Settings.Default.Room);

            try
            {
                httpClient.GetAsync(url).ContinueWith((task) =>
                {
                    HttpResponseMessage rslt = task.Result;
                    if (rslt.IsSuccessStatusCode)
                    {
                        rslt.Content.ReadAsStringAsync().ContinueWith((rTask) =>
                        {
                            if (rTask.Result == "baoji")
                            {
                                Game.Instance._isServerBoom = true;
                            }
                        });
                    }
                });
            }
            catch (Exception)
            {
            }
        }
Example #5
0
        public void SendDealEndToHttpServer()
        {
            var msg = new ParamToServer()
            {
                RoundIndex   = Game.Instance.RoundIndex,
                SessionIndex = Game.Instance.SessionIndex,
                Countdown    = Game.Instance.CountDown,
                State        = (int)GameState.DealOver,
                Winner       = (int)Game.Instance.CurrentRound.Winner.Item1,
            };

            var ip = Setting.Instance.ServerUrl;
            //var url = "http://" + ip + ":98/getmsg";
            var url = "http://" + ip + ":" + Settings.Default.port + "/" + Settings.Default.url;
            var str = JsonConvert.SerializeObject(msg);

            var waybill = JsonConvert.SerializeObject(Game.Instance.HistoryWaybill);

            url += ("?" + "msg=" + str + "&waybill=" + waybill + "&room=" + Settings.Default.Room);

            try
            {
                //httpClient.Timeout = TimeSpan.FromSeconds(5);
                //httpClient.SendAsync()
                httpClient.GetAsync(url).ContinueWith((task) =>
                {
                    HttpResponseMessage rslt = task.Result;
                    if (rslt.IsSuccessStatusCode)
                    {
                        rslt.Content.ReadAsStringAsync().ContinueWith((rTask) =>
                        {
                            if (rTask.Result == "baoji")
                            {
                                Game.Instance._isServerBoom = true;
                            }
                        });
                    }
                });
                //httpClient.Timeout = TimeSpan.FromSeconds(0.5);
            }
            catch (Exception)
            {
            }
        }