V22.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 procedures you should write and what they
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
- if illegal command, update the error count,
- compute new position,
- call procedure Draw (see below) to display
The call to the procedure will look like: CursorMovement(errors);
- 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.
The call to the procedure will look like: GetNextInput(command);
- 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
from the left hand margin of the screen)
The call to the procedure will look like: Draw(symbol,
- 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.
| 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: print on the same line but to the left of
another symbol, move past the left-hand side of the screen
(column 1), move past the right-hand side of the screen (column 80).
Test-run of CursorMovement. Enter series of commands ending in $
There where 2 errors
The errors above are
- Using the illegal symbol #
- Trying to move left on the same line (after the symbol
CursorMovement will keep on fetching characters until
it reaches the end command ($). You will need to keep three counters,
the horizontal offset and the vertical offset and the previous
horizontal position, 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: i.e.,
If the counters have legal values, print the symbol (remembering to
update the previous position counter), otherwise update the error count.
- If the vertical counter is zero (you are on the same line), the
horizontal counter cannot be negative.
- The horizontal counter added to the previous position counter
cannot result in a horizontal position that is either negative, or
greater than 79.