private bool CheckMovePermissibility(int i, int j, IGameHandler handler)
 {
     if (!_cells.IsCellEmpty(i, j))
     {
         handler.BroadcastMessage(true, "You can't draw in non-empty cell");
         return(false);
     }
     return(true);
 }
        public void OnClick(int x, int y, string playerId, IGameHandler handler)
        {
            if (_players.Count < 2)
            {
                handler.BroadcastMessage(true,
                                         "Please, wait for the second player before starting the game");
                return;
            }
            var i = x / CellSize + _players[0].ViewportLeft;
            var j = y / CellSize + _players[0].ViewportTop;

            UpdateCell(i, j, playerId, handler);
            if (IsWinMove(i, j))
            {
                handler.BroadcastMessage(false,
                                         "The " + (_isFirstPlayerTurn ? "Second" : "First") + " player won!");
            }
        }
 private void UpdateCell(int i, int j, string playerId, IGameHandler handler)
 {
     if (_isFirstPlayerTurn && _players[0].PlayerId == playerId &&
         CheckMovePermissibility(i, j, handler))
     {
         _cells[i, j] = CellType.Zero;
         handler.DrawZero(i - _players[0].ViewportLeft, j - _players[0].ViewportTop);
         _isFirstPlayerTurn = false;
     }
     else if (!_isFirstPlayerTurn && _players[1].PlayerId == playerId &&
              CheckMovePermissibility(i, j, handler))
     {
         _cells[i, j] = CellType.X;
         handler.DrawX(i - _players[0].ViewportLeft, j - _players[0].ViewportTop);
         _isFirstPlayerTurn = true;
     }
     else
     {
         handler.BroadcastMessage(true, "Please, wait... it's not your turn");
     }
 }