Here is a jawbreaker wannabe game for matlab. I mainly made it to see if it could be done. It obviously good use some better graphics, but it actually works pretty well on my version of matlab (R2008a). To get it to run, you will probably have to comment out some lines of code that involve separate files (i.e., wav files and an icon file). I tried to catch as many as I could find, but there may be more.

Sorry for not having any pics...I can't figure out how. I'm new to this.


Code:

% Jawbreaker Mania 1.0
% by Matt Pierce
% Copywrite 2008

function jawbreaker(arg1)

global scr bh undoh scrh tscr cYY cFS nYY nFS soundflag nbh goh pch tsh abouth
global ball field temp1 temp2 numc tYY tFS tc tk ch

if nargin < 1
   arg1 = 'start';
end

if strcmp(arg1,'start')

    clc;
    scr = 0;
    tscr = scr;
    %[cYY cFS] = wavread('click.wav');
    %[nYY nFS] = wavread('new.wav');
    %[tYY tFS] = wavread('tada.wav');
    ball = [
        0 0 0 0 0 0 0 0 0 0 0 0 0
        0 0 0 0 1 1 1 1 1 0 0 0 0
        0 0 0 1 1 1 1 1 1 1 0 0 0
        0 0 1 1 1 1 1 1 1 1 1 0 0
        0 1 1 1 1 1 1 1 1 1 1 1 0
        0 1 1 1 1 1 1 1 1 1 1 1 0
        0 1 1 1 1 1 1 1 1 1 1 1 0
        0 1 1 1 1 1 1 1 1 1 1 1 0
        0 1 1 1 1 1 1 1 1 1 1 1 0
        0 0 1 1 1 1 1 1 1 1 1 0 0
        0 0 0 1 1 1 1 1 1 1 0 0 0
        0 0 0 0 1 1 1 1 1 0 0 0 0
        0 0 0 0 0 0 0 0 0 0 0 0 0];

    figure('Name','Jawbreaker Mania','NumberTitle','off',...
        'Resize','off',...
        'Toolbar','none',...
        'Menubar','none',...
        'Position',[300 300 450 510],... %480 height
        'Color',[.75 .75 .75],...
        'WindowButtonDownFcn','jawbreaker(''click'');');

    uicontrol('Style','pushbutton',...
        'Position',[25 470 75 30],...
        'String','New',...
        'Callback','jawbreaker(''newgame'');');

    undoh = uicontrol('Style','pushbutton', ...
        'Position',[110 470 75 30], ...
        'String','Undo',...
        'Enable','off',...
        'Callback','jawbreaker(''undo'');');

    uicontrol('Style','pushbutton',...
        'Position',[420 20 20 20],...
        'String','?',...
        'Callback','jawbreaker(''about'');');

    soundflag = uicontrol( ...
        'Style','checkbox', ...
        'Position',[195 477 50 15], ...
        'String','Sound', ...
        'Callback','', ...
        'BackgroundColor',[.75 .75 .75],...
        'Value',1);

    scrh = uicontrol('Style','text',...
        'BackgroundColor',[.75 .75 .75],...
        'Units','pixels',...
        'FontSize',20,...
        'FontWeight','bold',...
        'Position', [270 460 180 40],...
        'HorizontalAlignment','left',...
        'String',['Score: ',num2str(scr)]);

    axes('Units','pixels',...
        'Position',[25 60 400 400],...
        'Color','none',...
        'XLimMode','manual',...
        'YLimMode','manual',...
        'XLim',[0 20],...
        'YLim',[0 20],...
        'Box','off',...
        'XColor','k','YColor','k',...
        'Tag','mainaxes',...
        'Xtick',[],'Ytick',[]);

    colormap([0 0 0;...     % (0) Black
              1 0 0;...     % (1) Red
              0 1 0;...     % (2) Green
              0 0 1;...     % (3) Blue
              1 1 0;...     % (4) Yellow
              .75 0 1;...   % (5) Purple
              .75 .75 .75]);% (6) Gray
    % Create original field
    numc = [0 0 0 0 0];
    for m = 1:20
        for n = 1:20
            field(n,m) = floor(5*rand)+1;
            numc(field(n,m)) = numc(field(n,m))+1;
            hold on;
            bh(n,m) = image([m-1,m],[n-1,n],ball*(field(n,m)+1));
        end
    end
    temp1 = field;
    tc = 1;
    tk = 0;
   
    % Create bottom balls
    axes('Units','pixels',...
        'Position',[25 20 400 20],...
        'Color',[.75 .75 .75],...
        'XLimMode','manual',...
        'YLimMode','manual',...
        'XLim',[0 20],...
        'YLim',[0 1],...
        'Box','off',...
        'XColor',[.75 .75 .75],'YColor',[.75 .75 .75],...
        'Tag','mainaxes',...
        'Xtick',[],'Ytick',[]);
    for m = 1:5
        hold on;
        ih(m) = image([4*(m-1),4*(m-1)+1],[0 1],(m+1)*ball);
        C = get(ih(m),'CData');
        for n = 1:169
            if C(n) == 0
                C(n) = 7;
            end
        end
        set(ih(m),'CData',C);
        nbh(m) = uicontrol('Style','text',...
            'BackgroundColor',[.75 .75 .75],...
            'Units','pixels',...
            'FontSize',10,...
            'FontWeight','bold',...
            'Position', [80*(m-1)+47 22 50 15],...
            'HorizontalAlignment','left',...
            'String',num2str(numc(m)));
    end

    % Game Over Box
    goh = figure('Name','Game Over!','NumberTitle','off',...
        'Resize','off',...
        'Visible','off',...
        'Toolbar','none',...
        'Menubar','none',...
        'Position',[400 470 250 200],...
        'Color',[.75 .75 .75]);
    uicontrol('Parent',goh,'Style','pushbutton',...
        'Position',[80 25 95 30],...
        'String','New Game',...
        'Callback','jawbreaker(''newgame'');');
    pch = uicontrol('Style','text',...
        'BackgroundColor',[.75 .75 .75],...
        'Units','pixels',...
        'FontSize',11,...
        'FontWeight','bold',...
        'Position', [45 140 180 20],...
        'HorizontalAlignment','left',...
        'String','Percent Complete:');
    tsh = uicontrol('Style','text',...
        'BackgroundColor',[.75 .75 .75],...
        'Units','pixels',...
        'FontSize',11,...
        'FontWeight','bold',...
        'Position', [60 110 180 20],...
        'HorizontalAlignment','left',...
        'String','Total Score:');
    abouth = figure('Name','About Jawbreaker Mania','NumberTitle','off',...
        'Resize','off',...
        'Visible','off',...
        'Toolbar','none',...
        'Menubar','none',...
        'Position',[400 470 250 200],...
        'Color',[.75 .75 .75]);
    uicontrol('Parent',abouth,'Style','pushbutton',...
        'Position',[80 25 95 30],...
        'String','Ok',...
        'Callback','jawbreaker(''about'');');
    uicontrol('Style','text',...
        'BackgroundColor',[.75 .75 .75],...
        'Units','pixels',...
        'FontSize',11,...
        'FontWeight','bold',...
        'Position', [85 100 150 80],...
        'HorizontalAlignment','left',...
        'String',{'Jawbreaker Mania';'by Matt Pierce';'(c) 2008'});
    %SAPic = imread('jb.ico');
    %image(SAPic);
    set(gca,'Units','pixels','Position',[35 140 32 32],'XTick',[],'YTick',[]);
    return
   
elseif strcmp(arg1,'newgame')
    check = get(soundflag,'Value');
    if check
        wavplay(nYY,nFS,'async');
    end
    % Reset field
    numc = [0 0 0 0 0];
    for m = 1:20
        for n = 1:20
            field(n,m) = floor(5*rand)+1;
            numc(field(n,m)) = numc(field(n,m))+1;
            set(bh(n,m),'CData',ball*(field(n,m)+1));
        end
    end
    scr = 0;
    tscr = 0;
    set(scrh,'String',['Score: ',num2str(scr)]);
    set(undoh,'Enable','on');
    for m = 1:5
        set(nbh(m),'String',num2str(numc(m)));
    end
    set(goh,'Visible','off');
    set(undoh,'Enable','off');
    return

elseif strcmp(arg1,'click')
    pt = get(gca,'CurrentPoint');
    m = floor(pt(1,1))+1;
    n = floor(pt(1,2))+1;
    if m > 0 & m < 21 & n > 0 & n < 21
        temp2 = field;
        x = m;
        y = n;
        c = field(n,m);
        i = 1;
        a = [1];
        field(y,x) = 0;
        k = 1;
        while a(1) < 5 & c ~= 0     % Collect similar balls & erase
            if a(i) == 1
                if y < 20
                    y = y + 1;
                else
                    a(i) = 2;
                end
            end
            if a(i) == 2
                if x < 20
                    x = x + 1;
                else
                    a(i) = 3;
                end
            end
            if a(i) == 3
                if y > 1
                    y = y - 1;
                else
                    a(i) = 4;
                end
            end
            if a(i) == 4
                if x > 1
                    x = x - 1;
                else
                    a(i) = 5;
                end
            end
            if a(i) < 5
                if field(y,x) ~= c
                    y = y - (a(i) == 1) + (a(i) == 3);
                    x = x - (a(i) == 2) + (a(i) == 4);
                    a(i) = a(i) + 1;
                else
                    field(y,x) = 0;
                    k = k + 1;
                    i = i + 1;
                    a(i) = 1;
                end
            end
            if a(i) == 5 & i > 1
                i = i - 1;
                y = y - (a(i) == 1) + (a(i) == 3);
                x = x - (a(i) == 2) + (a(i) == 4);
                a(i) = a(i) + 1;
            end
        end
        if k > 1
            numc(c) = numc(c) - k;
            tc = c;
            tk = k;
            set(nbh(c),'String',numc(c));
            check = get(soundflag,'Value');
            if check
                %wavplay(cYY,cFS,'async');
            end
            temp1 = temp2;
            set(undoh,'Enable','on');
            f = 1;
            while f == 1        % Move Downward
                f = 0;
                for m = 1:20
                    for n = 1:19
                        if field(n,m) == 0
                            c = field(n+1,m);
                            field(n,m) = c;
                            if c ~= 0
                                f = 1;
                                field(n+1,m) = 0;
                            end
                        end
                    end
                end
            end
            f = 1;
            while f == 1        % Move to right
                f = 0;
                for m = 2:20
                    if field(1,m) == 0
                        for n = 1:20
                            c = field(n,m-1);
                            field(n,m) = c;
                            if c ~= 0
                                f = 1;
                                field(n,m-1) = 0;
                            end
                        end
                    end
                end
            end
            for m = 1:20
                for n = 1:20
                    set(bh(n,m),'CData',ball*(field(n,m)+1));
                end
            end
            tscr = scr;
            scr = scr + k*(k-1);
            set(scrh,'String',['Score: ',num2str(scr)]);
            q = 0;
            for m = 1:20
                for n = 2:20
                    if field(n,m) == field(n-1,m) & field(n,m) ~= 0
                        q = q + 1;
                    end
                    if field(m,n) == field(m,n-1) & field(m,n) ~= 0
                        q = q + 1;
                    end
                end
            end
            if q == 0
                check = get(soundflag,'Value');
                if check & scr >= 3000
                    %wavplay(tYY,tFS,'async');
                end
                pp = floor(100*(1 - sum(numc)/400));
                totscr = scr;
                if pp > 90
                    totscr = scr + 20*(40-sum(numc));
                end
                set(pch,'String',['Percent Complete: ',num2str(pp),'%']);
                set(tsh,'String',['Total Score: ',num2str(totscr)]);
                set(goh,'Visible','on');
            end
        else
            field(y,x) = c;
        end
    end
    return

elseif strcmp(arg1,'undo')
    check = get(soundflag,'Value');
    if check
        %wavplay(cYY,cFS,'async');
    end
    set(undoh,'Enable','off');
    field = temp1;
    for m = 1:20
        for n = 1:20
            set(bh(n,m),'CData',ball*(field(n,m)+1));
            scr = tscr;
            set(scrh,'String',['Score: ',num2str(scr)]);
        end
    end
    numc(tc) = numc(tc) + tk;
    set(nbh(tc),'String',numc(tc));
    return

elseif strcmp(arg1,'about')
    ch = get(abouth,'Visible');
    if strcmp(ch,'off')
        set(abouth,'Visible','on');
    else
        set(abouth,'Visible','off');
    end
    return

end

end
[img][/img][img][/img]
Nina88 wrote:
To get it to run, you will probably have to comment out some lines of code that involve separate files. I have done a lot of research about the electronic cigarette and my goal is to help you make an informed decision about this product. Thanks a lots


Whahahahaha, WHAT?
(a) Hahaha, silly spambot
(b) Why is this topic in Cemetech Labs?
haha, spambot, I lost it at "electronic cigarette" Sometimes the spambots can really post some golden material XD
Haha me too . Golden stuff. I reported it also.

And incoherent tool post annoyed me
I was going to check this post when I saw it pop up, then I saw Nina actually *edited* their post. So, I didn't bother.

It appears these spammers have learned how to edit. If memory serves, this actually wasn't the first time. But, I might be mixing two things together.
It appears these spammers have learned how to edit. If memory serves, this actually wasn't the first time. But, I might be mixing two things together.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement