This should detect if the player is on the top or bottom rows and restrict his movement outside those boundaries.