private void CheckWinner(Room room)
        {
            if (room.stage == 13)
            {
                List <GamePlayer> playerList = table.SelectSitGamePlayer(room.index);
                WinnerValidator   validator  = WinnerValidator.Instance;

                for (int i = 0; i < playerList.Count; i++)
                {
                    HandResult result = validator.GetResult(new int[] { room.card1, room.card2, room.card3, room.card4, room.card5, playerList[i].card1, playerList[i].card2 });
                    playerList[i].result = result;

                    table.UpdateGamePlayer(room.index, playerList[i]);
                }

                room.winnerUserIndex  = WinnerValidator.Instance.GetWinner(playerList);
                room.waitTimeout      = Room.WAITTIMEOUT_BY_READY;
                room.currentUserIndex = 0;
                room.currentOrderNo   = -1;
                room.stage            = 14;
                table.UpdateRoom(room);
            }
            else
            {
                room.stage           += 1;
                room.waitTimeout      = Room.WAITTIMEOUT_BY_SETTING;
                room.stageBet         = 0;
                room.currentOrderNo   = 0;
                room.currentUserIndex = 0;

                table.UpdateRoom(room);
            }
        }
Ejemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();

            _grid                 = new Grid();
            _gridPresenter        = new GridPresenter(_grid, _cellSize);
            _pointToCellConverter = new PointToCellConverter(_cellSize);
            _currentMove          = new CurrentMove();

            _winnerValidator = new WinnerValidator(_grid);
            _tieValidator    = new TieValidator(_grid);

            _gameState = new GameState(new IGameOverValidator[] { _winnerValidator, _tieValidator });

            _grid.OnCellOccupied += pnl.Invalidate;
            _grid.OnCellOccupied += _currentMove.SwitchMove;
            _grid.OnCellOccupied += _gameState.ValidateGameOver;

            _winnerValidator.OnWinner += ShowWinnerMessage;
            _winnerValidator.OnWinner += _ => ResetGame();
            _tieValidator.OnTie       += ShowTieMessage;
            _tieValidator.OnTie       += ResetGame;
        }
        //// TODO: Remove magic values and make them better formated
        /// <summary>
        /// Execute a play command.
        /// </summary>
        /// <param name="playBoard">Current play board.</param>
        /// <param name="playerMoves">Value of player moves.</param>
        public void Execute(ref char[,] playBoard, ref int playerMoves)
        {
            var userRow = int.Parse(this.currentCommand[0].ToString());
            if (userRow > playBoard.GetLength(0) - 1)
            {
                Console.WriteLine("Wrong input ! Try Again ! ");
                return;
            }

            var userColumn = int.Parse(this.currentCommand[2].ToString());

            var gameLogic = new GameLogic();

            if (gameLogic.CheckIfEmpty(playBoard, userRow, userColumn))
            {
                Console.WriteLine("cannot pop missing ballon!");
                return;
            }

            gameLogic.PopBaloons(playBoard, userRow, userColumn);

            playerMoves++;

            var winner = new WinnerValidator();

            if (winner.CheckIfIsWinner(playBoard))
            {
                Console.WriteLine("Gratz ! You completed it in {0} moves.", playerMoves);
                if (winner.SignIfSkilled(this.topPlayers, playerMoves))
                {
                    this.scoreBoard.PrintTopPlayers(this.topPlayers);
                }
                else
                {
                    Console.WriteLine("I am sorry you are not skillful enough for TopFive chart!");
                }

                playBoard = this.board.GenerateBoard();
                playerMoves = 0;
            }

            this.printer.PrintPlayBoard(playBoard);
        }