A matrix approach is adopted to evaluate the partition function of random-walk chains between parallel walls. Assuming an attractive potential epsilon at the sites contiguous to the walls, a second-order transition is deduced at the temperature T* that makes epsilon/T equal to the entropy loss of the chain bonds reaching those sites. At T = T*, the walls act as reflecting barriers to the chain, whereas at T > T* and at T < T*, they change to repelling and attracting barriers, respectively. In the limit of an infinitely long chain comprised between infinitely distant walls, T* takes the role of a tricritical temperature, as we have three distinct states at T > T* (the chain is repelled from the walls), at T = T* (the chain density is uniformly distributed between the walls), and at T < T* (the chain collapses on either wall). Denoting as r the ratio between the probability of an end atom and that of a middle-chain atom touching the walls, we obtain r much-greater-than 1, r= 6/5, and r < 1 at T > T*, T = T*, and T < T*, respectively.