A22.0002 - ASSIGNMENT 5
You are part of a team that is developing a new video game and you
have been assigned the task to write the part that computes the new
cursor position on the screen and prints a specific symbol. Your
procedure will also detect errors (illegal moves and illegal input)
and report the number of errors.
Specs : (i.e., what your procedure should and should not do)
- CursorMovement: this is the main part of the program. It
should call procedure GetNextInput (see below) to
get the next command. It will then process the command and do one of
CursorMovement will return the number of errors
that it encountered (it should not display error messages).
- if illegal command, update the error count,
- compute new position,
- call procedure Draw (see below) to display
- GetNextInput will in reality be written by
someone else, but, in order to test the program, you will write a
dummy procedure that will simply read a character from the screen
and return it to the caller.
- Draw also will be written by someone else, but,
again, in order to test your program, you will have to write a
simplified version of it. The procedure will take three parameters:
- the symbol to be displayed,
- the vertical offset (how many lines must be skipped),
- the horizontal offset (how many characters must be skipped)
- In order to test it, you will also write a small main
that will simply call CursorMovement and then
display how many errors where encountered.
- Valid commands:
| l|| : || move left.
| r|| : || move right.
| u|| : || move up.
| d|| : || move down.
| +, |, >,
|| symbols to be displayed (without the commas, of course).
| $|| : || end of input.
- Errors that must be detected:
- Invalid command (i.e., not part of the above list)
- Invalid move: move above the current line, print on the
same line but to the left of another symbol, move off the
left-hand side of the screen, move past off the right-hand side
of the screen (column 80).
Test-run of CursorMovement. Enter series of commands ending in $
There where 3 errors
CursorMovement will keep on fetching characters until
it reaches the end command ($). You will need to keep two counters,
the horizontal offset and the vertical offset; which you will update
depending on the command you just received. If the command is a
printable symbol, verify that the counters have a legal value, then
either print the symbol or update the error count.