public StatusResult Status(StatusCommand status) { if (IsValidStatusRequest(status)) { return _gameManager.Execute(status); } return null; }
public StatusResult Execute(StatusCommand command) { var game = Games[command.GameId]; var result = game.GetStatus(command); return result; }
public StatusResult GetStatus(StatusCommand command) { var status = "Initializing"; if (!this._started) { status = "Game waiting for Logons"; } if (this.Waiting) { status = "Waiting for another player to join..."; } if (this.GameOver) { if (this.Waiting) { status = "Other players never joined"; } else if (this._authTokens.Values.GroupBy(e => e.Score).First().Count() == this.Players.Count()) { status = "Game Over - It's a TIE!"; } else { var winningPlayer = this._authTokens.Values.OrderByDescending(e => e.Score).First().PlayerName; status = "Game Over - " + winningPlayer + " wins!"; } } if (this.Running) { status = "Game Running"; } return new StatusResult() { EnemyElevators = GetElevatorsForOtherPlayer(command.AuthToken), MyElevators = GetElevatorsForPlayer(command.AuthToken), TimeUntilNextTurn = (int) (_started ? (SERVER_PROCESSING + TURN_DURATION - this.elapsedTotalTurn - this.elapsedServerTime) : Waiting ? SERVER_PROCESSING + TURN_DURATION : this.gameStartCountdown), Delivered = _authTokens[command.AuthToken].Score, EnemyDelivered = this.Waiting ? 0 : GetEnemyDelivered(command.AuthToken), Floors = Floors.Values.Select(Mapper.Map<FloorLite>).ToList(), Id = this.Id, Turn = this.Turn, IsGameOver = this.GameOver, Status = status }; }
public StatusResult GetStatus(StatusCommand command) { var status = "Initializing"; if (this.GameOver) { status = "Game Over"; } if (this.Running) { status = "Game Running"; } if (!this._started) { status = "Game waiting for Logons"; } return new StatusResult() { EnemyElevators = GetElevatorsForOtherPlayer(command.AuthToken), MyElevators = GetElevatorsForPlayer(command.AuthToken), TimeUntilNextTurn = (int) (_started ? (SERVER_PROCESSING + TURN_DURATION - this.elapsedTotalTurn - this.elapsedServerTime) : this.gameStartCountdown), Delivered = _authTokens[command.AuthToken].Score, EnemyDelivered = GetEnemyDelivered(command.AuthToken), Floors = Floors.Values.Select(Mapper.Map<FloorLite>).ToList(), Id = this.Id, Turn = this.Turn, IsGameOver = this.GameOver, Status = status }; }
private bool IsValidStatusRequest(StatusCommand status) { if (status != null && !string.IsNullOrWhiteSpace(status.AuthToken) && (status.GameId >= 0)) { return true; } return false; }