Lab 28
Graphics: Positions, Units,
and Defaults
CS211 Lab Policy:
- This lab exercise will not be graded.
- Submit as much as you have completed before the end of the lab period in
which it is assigned.
- If you do not finish this lab work, it is to your advantage to finish it
outside of class. Please re-submit your finished work to the course web
site.
- You may receive help from anyone in completing this lab.
- You may not submit another student's code as part of your
lab.
Instructions:
For this lab you will modify a graphical tick-tack-toe program,
lab28.m. This program
allows a user to play tick-tack-toe on a graphical board and select the next
move using mouse clicks. The Lab28() program is fully functional and you can
play tick-tack-toe without any modifications to the file. Your task is to make
it more "exciting" by generating motion after the game finishes. You can download and execute an example of this lab assignment,
lab28p.p.
Your assignment is to add code to the 4 functions at the end of the file as
described below:
To complete the function
Display_winner(Board_size, Winning_player)
- Calculate the center of the Board. Use the equation
1 + (Board_size / 2). This works for
both the vertical and horizontal axis directions.
- Use the text() function and the
input argument Winning_player (which
has a value of 'X',
'O', or
'C') to display a message that says who won the game. The message
should be displayed exactly in the middle of the axes object. Make
the text size large (set
'FontSize' to 72) and use the
'HorizontalAlignment' and
'VerticalAlignment' properties to center the
text.
To complete the function O_won()
- Set the 'Units' property of the
axes object to 'normalized'.
- Get the current location of the axes object. (Use the
'Position' property.) The value that
is returned will be a 4-element row vector containing the values
[x_offset y_offset axes_width axes_height]
in normalized units.
- Repeat the following 20 times: (This will make the axes object
"shutter" up and down.)
- Set the 'Position' property
of the axes object to its current value, but with the
y_offset value higher by 5
hundredths.
- Call the function drawnow()
to redraw the axes object.
- Call the pause(0.05) to pause
5 hundredths of a second.
- Set the 'Position' property
of the axes object to its current value, but with the
y_offset value lower by 5
hundredths.
- Call the function drawnow()
to redraw the axes object.
- Call the pause(0.05) to pause
5 hundredths of a second.
- Set the 'Position' property of
the axes object back to its original value.
To complete the function X_won()
(Copy and paste the code from O_won()
and change appropriately.)
- Set the 'Units' property of the
axes object to 'normalized'.
- Get the current location of the axes object. (Use the
'Position' property.) The value that
is returned will be a 4-element row vector containing the values
[x_offset y_offset axes_width axes_height]
in normalized units.
- Repeat the following 20 times: (This will make the axes object
"shutter" back and forth.)
- Set the 'Position' property
of the axes object to its current value, but with the
x_offset
value left by 5 hundredths.
- Call the function drawnow()
to redraw the axes object.
- Call the pause(0.05) to pause
5 hundredths of a second.
- Set the 'Position' property
of the axes object to its current value, but with the
x_offset value right by 5
hundredths.
- Call the function drawnow()
to redraw the axes object.
- Call the pause(0.05) to pause
5 hundredths of a second.
- Set the 'Position' property of
the axes object back to its original value.
To complete the function Cat_won()
(Copy and paste the code from O_won()
and change appropriately.)
- Set the 'Units' property of the
axes object to 'normalized'.
- Get the current location of the axes object. (Use the
'Position' property.) The value that
is returned will be a 4-element row vector containing the values
[x_offset y_offset axes_width axes_height]
in normalized units.
- Repeat the following until the axes object is no longer visible: (This
will make the axes object slide down the figure and out of sight.)
- Change the y_offset
value of the location by subtracting 5 hundredths.
- Set the 'Position' property
of the axes object.
- Call the function drawnow()
to redraw the axes object.
- Call the pause(0.05) to pause
5 hundredths of a second.
Turn-in:
Submit your
Lab28.m file.