Code covered by the BSD License  

Highlights from
BattleShip (R)

image thumbnail

BattleShip (R)

by

 

23 Oct 2008 (Updated )

Learn and have fun with an old classic.

locgridpt(ax)
function obj = locgridpt(ax)
%  	Author: Isaac Noh
%   Copyright 2008-2009 The MathWorks, Inc.
%   Version: 1.1

% "Constructor" for psuedo object LOCGRIDPT
obj.axhandle = ax;

% Methods for LOCGRIDPT
obj.sethit = @sethit;
obj.gethit = @gethit;
obj.setlocation = @setlocation;
obj.getlocation = @getlocation;

% Properties for LOCGRIDPT
location = '';
hit = '';

% Definition of methods
    function sethit(val)
        hit = val;
        loc = location;
        row = (11 - (double(loc(1)) - 64))/10;
        col = str2double(loc(2:end))/10;

        ax = obj.axhandle;

        if val == true
            H = zeros(2,2,3);
            H(:,:,1) = 1;

        else
            H = ones(2,2,3);
        end
        surface(zeros(2),H,...
            'XData',[(col - 0.1) col],...
            'YData',[(row - 0.1) row],...
            'Parent',ax);

    end

    function out = gethit
        out = hit;
    end

    function setlocation(val)
        location = val;
    end

    function out = getlocation
        out = location;
    end
end

Contact us