コード例 #1
0
ファイル: AgentBase.cs プロジェクト: jklung/BellTowerEscape
 protected async Task<LogonResult> Logon(LogonResult result)
 {
     AuthToken = result.AuthToken;
     GameId = result.GameId;
     Console.WriteLine("Your game Id is " + result.GameId);
     return result;
 }
コード例 #2
0
ファイル: Game.cs プロジェクト: randombits01/BellTowerEscape
 public void StartDemoAgent(LogonResult demoResult, string playerName)
 {
     var agentTask = Task.Factory.StartNew(() =>
     {
         string endpoint = "";
         if (IsRunningLocally)
         {
             endpoint = "http://localhost:3193";
         }
         else {
             endpoint = "http://elevators.azurewebsites.net";
         }
         AgentBase sweetDemoAgent = new AgentBase(playerName, endpoint);
         sweetDemoAgent.Start(demoResult).Wait();
     });
 }
コード例 #3
0
ファイル: Game.cs プロジェクト: randombits01/BellTowerEscape
        /// <summary>
        /// Logs player with a certain name into the game and returns an authorization token
        /// </summary>
        /// <param name="playerName"></param>
        /// <returns></returns>
        public LogonResult LogonPlayer(string playerName)
        {
            var result = new LogonResult();
            if (!Players.ContainsKey(playerName))
            {
                var newPlayer = new Player()
                {
                    AuthToken = System.Guid.NewGuid().ToString(),
                    PlayerName = playerName
                };

                var success = Players.TryAdd(playerName, newPlayer);
                var success2 = _authTokens.TryAdd(newPlayer.AuthToken, newPlayer);

                if (success && success2)
                {
                    System.Diagnostics.Debug.WriteLine("Player logon [{0}]:[{1}]", newPlayer.PlayerName,
                        newPlayer.AuthToken);
                }

                _allocateElevators(newPlayer.AuthToken);
                result.AuthToken = newPlayer.AuthToken;
                result.GameId = Id;
                result.GameStart = (int) this.gameStartCountdown;
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Player {0} already logged on!", playerName);
            }
            result.GameId = Id;

            return result;
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: jklung/BellTowerEscape
        public void LogonDemoAgent(string playerName)
        {
            var result = new LogonResult();
            if (!_players.ContainsKey(playerName))
            {
                var newPlayer = new Player()
                {
                    AuthToken = System.Guid.NewGuid().ToString(),
                    PlayerName = playerName
                };

                var success = _players.TryAdd(playerName, newPlayer);
                var success2 = _authTokens.TryAdd(newPlayer.AuthToken, newPlayer);

                if (success && success2)
                {
                    System.Diagnostics.Debug.WriteLine("Player logon [{0}]:[{1}]", newPlayer.PlayerName,
                        newPlayer.AuthToken);
                }

                _allocateElevators(newPlayer.AuthToken);
                result.AuthToken = newPlayer.AuthToken;
                result.GameId = Id;
                result.GameStart = (int)this.gameStartCountdown;
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Player {0} already logged on!", playerName);
            }
            result.GameId = Id;
            var agentTask = Task.Factory.StartNew(() =>
            {
                AgentBase sweetDemoAgent = new AgentBase(playerName, "http://localhost:3193");
                sweetDemoAgent.Start(result).Wait();
            });
        }
コード例 #5
0
        public async Task Start(LogonResult demoLogon)
        {
            AuthToken = demoLogon.AuthToken;
            GameId = demoLogon.GameId;

            if (!_isRunning)
            {
                _isRunning = true;
                while (_isRunning)
                {

                    var gs = await UpdateGameState();
                    if (gs.IsGameOver)
                    {
                        _isRunning = false;
                        Console.WriteLine("Game Over!");
                        Console.WriteLine(gs.Status);
                        _client.Dispose();
                        break;
                    }

                    Update(gs);
                    var ur = await SendUpdate(this._pendingMoveRequests);
                    this._pendingMoveRequests.Clear();
                    if (TimeToNextTurn > 0)
                    {
                        await Task.Delay((int) (TimeToNextTurn));
                    }
                }
            }
        }