21. Star-Circle
Surround the star with the colored circle. Click and move action.
We will make a simple game where you control a circle and try to surround a star.
- The center of the circle follows the mouse.
- Clicking changes the circle between solid and outline.
- When the solid circle completely surrounds the star, you win.
- My images below are based on a 400x200 scene.
We will call the structure scg
for “star circle game”.
- Write a data description for
scg
. Make sure to include the type and human-understandable purpose for each field. (In class they got calledstp
,cp
, andfill
.) - Write an example
scg
that represents the initial state, shown on the left, where the star is centered at (50,75) and the outline circle is centered at (300,100). Store it in a variableex-a
. - Write a check-expect for the mouse handler
mh
that shows what happens when you are in stateex-a
and:- Move the mouse to (290,80).
- Click at location (292,75). Call the resulting state
ex-c
.
- Write the part of the mouse handler to handle movement.
- Write another check-expect for the mouse handler that shows what
happens when you are in the state
ex-c
and click at (300,100). The circle should change back to an outline.
There is a video showing the game in action.
<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen="allowfullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/TV34itNilb8?autoplay=0&controls=1&end=0&loop=0&mute=0&start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="Star-Circle game demo video"
></iframe>
</div>