Example #1
0
        private bool NextRound(int gameId)
        {
            GameManager gameManager = new GameManager();
            bool        isFinished  = false;
            var         gameObj     = EntityStateManager.CurrentGames.FirstOrDefault(a => a.GameId == gameId);

            if (gameObj.CurrentRound >= EntityStateManager.NumberOfRounds)
            {
                var gameCode = gameObj.GameCode;
                Clients.Group(gameCode).gameIsOver();
                //GAME OVER
                isFinished = true;
                var players = gameObj.Players.ToList();

                var winner = players.OrderByDescending(a => a.BankAccount.Balance).ThenByDescending(b => b.NoOfTransactions).FirstOrDefault();
                GetGameLeaders(gameObj.GameId);
                if (players != null)
                {
                    foreach (var player in players)
                    {
                        EntityStateManager.Players.Remove(player);
                        gameManager.DisconnectPlayer(player.PlayerId);
                        gameObj.Players.Remove(player);
                    }
                }
                gameManager.GameEnded(winner);
                EntityStateManager.CurrentGames.Remove(gameObj);
                Clients.Group(gameCode).gameOver(winner.GameId);
            }
            else
            {
                gameObj.CurrentRound += 1;
                if (gameObj.CurrentRound == 1)
                {
                    System.Threading.Thread.Sleep(3000);
                }
                else
                {
                    foreach (var ply in gameObj.Players)
                    {
                        GetPlayerStocks(gameObj.GameId, ply.PlayerId);
                    }
                }

                var turnDetails = gameObj.GameDetail.TurnDetail.FirstOrDefault(x => x.Turn == gameObj.CurrentRound);
                if (turnDetails != null)
                {
                    Clients.Group(gameObj.GameCode).startRound(turnDetails);
                }

                //PlayerAI player = new PlayerAI(gameObj);
                if (gameObj.IsPlayerAIAvailable)
                {
                    GameLogicManager gameLogic = new GameLogicManager();
                    var playerAIData           = gameLogic.GetPlayerAIData(gameObj);
                    decideBuySellForAI(playerAIData);
                }
                GetGameLeaders(gameObj.GameId);
            }

            return(isFinished);
        }