示例#1
0
        /// <summary>
        /// Lets clients pull a client view object on init
        /// </summary>
        /// <returns>ClientView object</returns>
        public ClientView Init()
        {
            using (var db = new PersistedRepository())
            {
                // Diagnostics
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                // Get the grid the player sits on
                var grid = db.Grid.GetByConnectionId(Context.ConnectionId);
                if(grid != null)
                {
                    var initData = new ClientView
                    {
                        Round = 0,
                        OwnType = 0,
                        Move = false,
                        TypeChange = false,
                        Timeout = false,
                        LastPayoff = 0,
                        TotalPayoff = 0,
                        BlueCount = 0,
                        YellowCount = 0,
                        WhiteCount = 0,
                        OwnShare = "",
                        OtherShare = "",
                        CountDown = grid.IntroTimer
                    };
                    return initData;
                }
            }
            return null;
        }
示例#2
0
        /// <summary>
        /// Set of client status information pushed at regular intervals
        /// </summary>
        /// <param name="g">The grid</param>
        /// <param name="p">The player</param>
        /// <param name="nei">Players neighborhood</param>
        /// <returns>A client status view</returns>
        public ClientView GetClientStatus(Grid g, Player p)
        {
            int blueCount;
            int yellowCount;

            if (p.PlayerType == 1)
            {
                blueCount = p.Neighborhood.OwnTypeCount;
                yellowCount = p.Neighborhood.OtherTypeCount;
            }
            else
            {
                blueCount = p.Neighborhood.OtherTypeCount;
                yellowCount = p.Neighborhood.OwnTypeCount;
            }

            var cv = new ClientView
            {
                Round = g.Round,
                OwnType = p.PlayerType,
                Move = p.RequestMove,
                TypeChange = p.RequestTypeChange,
                Timeout = p.HasTimeout,
                LastPayoff = p.LastPoints,
                TotalPayoff = p.GridPoints,
                BlueCount = blueCount,
                YellowCount = yellowCount,
                WhiteCount = p.Neighborhood.EmptyCount,
                OwnShare = p.Neighborhood.OwnShare.ToString("P1"),
                OtherShare = p.Neighborhood.OtherShare.ToString("P1"),
                CountDown = g.RoundTimer
            };

            return cv;
        }