Mouse Run

This Scratch code has a mouse running from a cat and the has the cat pursuing. The cat finds out where the mouse it and heads towards it. When the cat gets close the mouse heads to the quadrant farthest away. the program demonstrates two threads running at the same time.






The Cat first broadcast the Mouse Thread to start (Start). It then broadcast message (KeepinBounds) that will keep the cat in bounds and waits for its completion. It is really not needed since the Cat will always head towards the Mouse. The Cat senses where the Mouse is and then heads towards it.

This is the call to broadcast to keep Cat in bounds.




The main mouse function starts and then run independently after it receives a broadcast from the Cat (start). It then determines if the cat is close. If it is then it sets the close variable to 1. If the close variable has been set to 1 it runs for the quadrant of the screen furthest away.


The second mouse function IsClose determines if the Cat is close to it

The third Mouse function FindCorner, finds the quadrant that is farthest away from the Cat and then sets the variable crrner to a String naming the quadrant (Northeast, SouthWest) ..)

The fourth Mouse function Move moves the Mouse towards the corner it has found to be safe. it runs 70 steps and then resets the close and running variables.