% 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')

line = 8 * rand(1) + 1;     % Location of horizontal line

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.
    if y < line - delta
        message = 'Too low!';
        plot(x, y, 'go')    % Plot a green point to show mouse click
    elseif y > line + delta
        message = 'Too high!';
        plot(x, y, 'bo')    % Plot a blue point to show mouse click
    else
        message = 'Hit!';
        plot([1 9], [line line], 'r-')  % Plot horizontal red line
        plot(x, y, 'r*')    % Plot a red star to show mouse click
    end % if
    title(message)
end % while
hold off            % New plots will now erase any current plots
