moveWorker()
- Use four keys 'H', 'K', 'J', 'L' to move the worker to the left,
up, down, right, respectively.
- Assume you have an enumeration data
type which consists of 4
members { LEFT, UP, DOWN, RIGHT }.
- Define a function char NextToWorker(Direction d), which will return
the neighbor cell of the worker in the d direction. For example, in the
following figure, NextToWorker(LEFT) == 'H' and NextToWorker(UP) == ' '.
- Define a function MoveWorker(Direction d).
- In your main loop, when the user press the UP key ('K'), and NextToWorker(UP) == ' ',
call MoveWorker(d) to move the worker and re-draw.
- Handle DOWN, LEFT and RIGHT similarly.
- Define a function error_message(char* s = "Warning!") to
warn the player if it is not a legal move.
- You may want the computer to generate audio signals to warn
the user.
- The following are some useful functions in C++ to generate audio: