moveBox()
- Extend the previous homework. This time we want to enable the
worker to
push a box.
- Define a function char NextNextToWorker(Direction d), which will return
the next next cell of the worker in the d direction. For example, in the
following figure, NextToWorker(RIGHT) == 'B' and NextNextToWorker(RIGHT) == ' '.
- Define a function MoveBox(Direction d).
- As we have done in the previous homework, in your main loop, when the user press the UP key ('K'), and NextToWorker(UP) == ' ',
call MoveWorker(d) to move the worker.
- If NextToWorker(UP) == 'B', but NextNextToWorker(UP) == ' ',
call MoveBox(d) together with MoveWorker(d) to move the box and the worker
concurrently.
- If NextNextToWorker(UP) is not empty, the box cannot be moved.
- Handle DOWN, LEFT and RIGHT similarly.
- After each move, count the number of boxes which have arrived at
the destinations. If all boxes have arrived,
(you may optionally play a music and)
move to the next level.