% Matlab script to play a simple game: hunt for a horizontal line.
%
% Name =
% NetID = 

% Set up the window
close all           % Close all previous figure windows
figure              % Start a new figure window
hold on             % Allow multiple plots on the same set of axes
axis equal          % X- and Y-axis use the same unit-length
axis([1 9 1 9])     % X-axis limits = [1,9]; Y-axis limits = [1,9]
title('Click within the graph area below')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Modify the code below

line = 4.5;         % Location of horizontal line

% Modify the code above
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

delta = .1;         % How close we need to be for a hit

% Loop until the message is 'Hit!'
message = '';
while ~strcmp(message, 'Hit!')
    [x, y]= ginput(1);  % x and y represent the coordinates of the user's
                        % mouse click.
                        
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Modify the code below
    
    if line - delta < y && y < line + delta
        message = 'Hit!';
        plot(x, y, 'ro')    % Plot a red point to show mouse click
        plot([1 9], [line line], 'r-')  % Plot horizontal red line
    else
        message = 'Miss!';
        plot(x, y, 'bo')    % Plot a blue point to show mouse click
    end % if
    
    % Modify the code above
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    title(message)
end % while
hold off            % New plots will now erase any current plots