Mouse Sensors

You may have noticed that there is a small handheld device attached to your computer. There may be a ball on the bottom or a red light. There is a cord that connects this device to the computer. This is called a MOUSE. Perhaps you are familiar with it?

Mice are input devices that have sensors inside then to note the relative position on the screen. They gather data about how far the user has moved and relay it to the computer. We are going to pretend that this data is stored in a file and we are going to manipulate it.

The file of mouse data can come in two formats (well, not really. But it's fun to pretend). The first line states the format. It is either: COMPACT or HUGE.

HUGE mouse files will be set up in the following way:

  • First line is file type > HUGE
  • Second line is starting x co-ordinate >100
  • Third line is starting y co-ordinate > 200
  • Fourth line is the maximum x co-ordinate > 600
  • Fifth lines is the maximum y co-ordinate > 800
  • Sixth line is how far the mouse moves left/right number > 12
  • Sixth line is how far the mouse moves up/down > -5
  • Lines continue showing how far the mouse moves left-right > 23
  • Up, down > 56
  • Until the final two lines which are> 0
  • Final line>0

HUGE
100
200
600
800
12
-5
23
56
0
0

COMPACT mouse files will be set up in the following way:

  • First line is file type > COMPACT
  • Second line is starting co-ordinates seperated by a space >100 200
  • Third line is the maximum x, y co-ordinate seperated by a space > 600 800
  • Third line is how far the mouse moves, left/right number, followed by up/down > 12 -5
  • Lines continue showing how far the mouse moves > 23 56
  • Until the final line which is > 0 0

COMPACT
100 200
600 800
12 -5
23 56
0 0

Both file types yield the same output (to another data file, let your user type in the file name).

Starting Postion: 100, 200
Moves to: 112, 195
Moves to: 135, 251
Stops.

Note that if the mouse moves off the screen (as specified by the file) then the mouse should just move to the edge of the screen and stay there until it is moved back. It can still move in the other direction while it is on the edge of the screen.

Further note that negative values in the up/down direction mean move up. Negative numbers in the left/right direction mean move left.

Create your own text files to test this. Choose some boundary cases (go off the screen for starters).