Construct $f: X\to Y$ such that $f(p)=p$ 
Let , $X=[-1,1]\times [-1,1]$ and $Y=\{0\}\times \left[-\frac{1}{2},\frac{1}{2}\right]$. Construct an example of a continuous map $f:X\to Y$ such that $f(p)=p$ for each $p\in Y$.

I construct a function as below :
$$f(x,y)=\begin{cases}\left(0,\frac{1}{2}+y\right) & \text{ if }(x,y)\in[-1,1]\times\left[-1,-\frac{1}{2}\right]\\(0,y) & \text{ if }(x,y)\in [-1,1]\times\left[-\frac{1}{2},\frac{1}{2}\right]\\\left(0,\frac{1}{2}-y\right) & \text{ if }(x,y)\in[-1,1]\times \left[\frac{1}{2},1\right]\end{cases}$$
Is my construction correct ? Please check.
If wrong please tell me where my mistake.
 A: According to your definition, $f(0,-1/2)$ is being mapped to two distinct points : $(0,0)$ and $(0,-1/2)$. So it's not quite a function.
A: Your function is a) not a function and b) is not continuous.
f(0,- 1/2) = {0, -1/2} and f(0, 1/2) = {1/2, 0} have two values so it is not a function.  It can be made a function by setting:
$f(x,y)=\begin{cases}\left(0,\frac{1}{2}+y\right) & \text{ if }(x,y)\in[-1,1]\times\left[-1,-\frac{1}{2}\right)\\(0,y) & \text{ if }(x,y)\in [-1,1]\times\left[-\frac{1}{2},\frac{1}{2}\right)\\\left(0,\frac{1}{2}-y\right) & \text{ if }(x,y)\in[-1,1]\times \left[\frac{1}{2},1\right]\end{cases}$
but then it would be discontinuous at $(x,1/2)$ and $(x,-1/2)$  The $\lim_{y\rightarrow\frac {1}{ 2}^+} = 1/2$ but $\lim_{y\rightarrow\frac {1}{ 2}^-} = 0$ s0 it isn't continuous.
Try $f(x,y)=\begin{cases}\left(0,-\frac{1}{2}\right) & \text{ if }(x,y)\in[-1,1]\times\left[-1,-\frac{1}{2}\right]\\(0,y) & \text{ if }(x,y)\in [-1,1]\times\left[-\frac{1}{2},\frac{1}{2}\right]\\\left(0,\frac{1}{2}\right) & \text{ if }(x,y)\in[-1,1]\times \left[\frac{1}{2},1\right]\end{cases}$
Or if you want to be clever:
$f(x,y)=\begin{cases}\left(0,-1-y\right) & \text{ if }(x,y)\in[-1,1]\times\left[-1,-\frac{1}{2}\right]\\(0,y) & \text{ if }(x,y)\in [-1,1]\times\left[-\frac{1}{2},\frac{1}{2}\right]\\\left(0,1-y\right) & \text{ if }(x,y)\in[-1,1]\times \left[\frac{1}{2},1\right]\end{cases}$
