Пример #1
0
        private void ObserveNextTurnImpl(ObserveNextTurnReq req, ObserveNextTurnResp resp)
        {
            ObservedGameInfo gi = Server.GameManager.ObserveNextTurn(req.ObserverId, req.GameId, req.Auth.GetClientCode());

            resp.GameInfo = new EnObsGameInfo(gi);
            resp.TurnInfo = (gi.TurnInfo == null) ? null : new EnObsTurnInfo(gi.TurnInfo);
        }
        private void ObserveNextTurnImpl(ObserveNextTurnReq req, ObserveNextTurnResp resp)
        {
            Team             team = Server.TeamRegistry.GetTeam(req.Auth.TeamName);
            ObservedGameInfo gi   = Server.GameManager.ObserveNextTurn(req.ObserverId, req.GameId, req.Auth.GetClientCode(), team);

            resp.GameInfo = new EnObsGameInfo(gi);
            resp.TurnInfo = (gi.TurnInfo == null) ? null : new EnObsTurnInfo(gi.TurnInfo);
        }
 public ObserveNextTurnResp ObserveNextTurn(ObserveNextTurnReq req)
 {
     return(HandleServiceCall(req, new ObserveNextTurnResp(), ObserveNextTurnImpl));
 }
Пример #4
0
        public async Task <Turn> GetNextTurnAsync(int gameId)
        {
            using (var adminService = new AdminServiceClient(new BasicHttpBinding(), new EndpointAddress(ConnectionData.Url)))
            {
                int sequenceNumber = SequenceNumber;

                var req = new ObserveNextTurnReq
                {
                    Auth = new ReqAuth
                    {
                        ClientName     = ConnectionData.Username,
                        TeamName       = ConnectionData.TeamName,
                        SessionId      = _sessionId,
                        SequenceNumber = sequenceNumber,
                        AuthCode       =
                            GetAuthCode(string.Format("{0}:{1}:{2}:{3}{4}", ConnectionData.TeamName, ConnectionData.Username,
                                                      _sessionId, sequenceNumber, ConnectionData.Password)),
                    },
                    GameId     = gameId,
                    ObserverId = _observerId,
                };

                _stopwatch.Start();

                var resp = await adminService.ObserveNextTurnAsync(req);

                _stopwatch.Stop();
                LastCallTime = _stopwatch.ElapsedMilliseconds;
                _stopwatch.Reset();

                if (resp.Status != "OK")
                {
                    throw new Exception(resp.Message);
                }

                var turn = new Turn
                {
                    Game = new Models.Game
                    {
                        GameId = resp.GameInfo.GameId,
                        State  = resp.GameInfo.GameState,
                    },
                    NumberOfQueuedTurns = resp.GameInfo.QueuedTurns,
                    SlowPlayers         = resp.GameInfo.SlowPlayers
                };

                if (resp.TurnInfo == null)
                {
                    turn.TurnNumber   = -1;
                    turn.PlayerStates = null;
                }
                else
                {
                    turn.TurnNumber   = resp.TurnInfo.Turn;
                    turn.PlayerStates = resp.TurnInfo.PlayerStates.Select(p => new PlayerState
                    {
                        Condition = p.Condition,
                        //Position = new Point(p.Position.Col, p.Position.Row),
                        Score = p.Score
                    }).ToList();

                    turn.MapChanges = resp.TurnInfo.MapChanges.Select(p => new MapChange
                    {
                        Position = new Point(p.Position.Col, p.Position.Row),
                        Value    = p.Value,
                    }).ToList();

                    turn.TecmanPosition = new Point(resp.TurnInfo.TecmanPosition.Col, resp.TurnInfo.TecmanPosition.Row);
                    turn.GhostPositions = resp.TurnInfo.GhostPositions.Select(p => new Point(p.Col, p.Row)).ToList();
                }

                return(turn);
            }
        }