基于Matlab实现俄罗斯方块游戏

我最早写的一个matlab小游戏

写的可能不够简洁,但还有可玩性,

先发上来,以后可能改进或出教程。

大家自己探索吧(外挂是哪个按键,更改颜色是哪个按键)

游戏效果

完整代码

function elos
hold on
axis equal
axis(0.5+[0,10,0,20])
set(gca,'xtick',[],'ytick',[],'xcolor','w','ycolor','w')
set(gca,'color','k')
%%%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%% %%%%%%%%%
A1=[5,23;5,24;6,23;6,24];%1
B1=[5,23;5,24;5,22;5,21];%21
B2=[5,23;4,23;6,23;7,23];%23
C1=[5,23;5,24;5,22;4,24];%31
C2=[5,23;6,23;4,23;6,24];%33
C3=[5,23;5,24;5,22;6,22];%35
C4=[5,23;4,23;6,23;4,22];%37
D1=[5,23;5,24;5,22;6,24];%41
D2=[5,23;4,23;6,23;6,22];%43
D3=[5,23;5,24;5,22;4,22];%45
D4=[5,23;4,23;6,23;4,24];%47
E1=[5,23;5,24;4,24;6,23];%51
E2=[5,23;6,24;6,23;5,22];%53
E3=[5,23;4,23;5,22;6,22];%55
E4=[5,23;5,24;4,23;4,22];%57
F1=[5,23;5,24;6,24;4,23];%61
F2=[5,23;6,23;6,22;5,24];%63
F3=[5,23;6,23;5,22;4,22];%65
F4=[5,23;4,24;4,23;5,22];%67
G1=[5,23;5,24;4,23;6,23];%71
G2=[5,23;6,23;5,24;5,22];%73
G3=[5,23;4,23;6,23;5,22];%75
G4=[5,23;4,23;5,24;5,22];%77
%%%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%% %%%%%%%%%
r=[1 0 0;1 0 0;1 0 0;1 0 0];
b=[0 0 1;0 0 1;0 0 1;0 0 1];
g=[0 1 0;0 1 0;0 1 0;0 1 0];
c=[0 1 1;0 1 1;0 1 1;0 1 1];
w=[1 1 1;1 1 1;1 1 1;1 1 1];
h=[-50,-50,0,0,1;-49,-49,0,0,1;-48,-48,0,0,1;-47,-47,0,0,1];
wall1=[1 0;2 0;3 0;4 0;5 0;6 0;7 0;8 0;9 0;10 0];
wall2=[0,0;0,1;0,2;0,3;0,4;0,5;0,6;0,7;0,8;0,9;0,10;0,11;0,12;0,13;0,14;0,15;
    0,16;0,17;0,18;0,19;0,20];
wall3=[11,0;11,1;11,2;11,3;11,4;11,5;11,6;11,7;11,8;11,9;11,10;11,11;11,12;
    11,13;11,14;11,15;11,16;11,17;11,18;11,19;11,20];
direct=[0,-1,0,0,0;0,-1,0,0,0;0,-1,0,0,0;0,-1,0,0,0];
dir=[0,-1;0,-1;0,-1;0,-1];
left=[-1,0,0,0,0;-1,0,0,0,0;-1,0,0,0,0;-1,0,0,0,0];
right=[1,0,0,0,0;1,0,0,0,0;1,0,0,0,0;1,0,0,0,0];
lefty=[-1,0;-1,0;-1,0;-1,0];
leftyy=[-1,-1;-1,-1;-1,-1;-1,-1];
righty=[1,0;1,0;1,0;1,0];
rightyy=[1,-1;1 ,-1;1,-1;1,-1];
s=[A1,c];
s1=A1;
change=1;
waigua=1;
color=1;
score=0;
%%%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%% %%%%%%%%%
kill1=[1,17;2,17;3,17;4,17;5,17;6,17;7,17;8,17;9,17;10,17];
kill2=[1,16;2,16;3,16;4,16;5,16;6,16;7,16;8,16;9,16;10,16];
kill3=[1,15;2,15;3,15;4,15;5,15;6,15;7,15;8,15;9,15;10,15];
kill4=[1,14;2,14;3,14;4,14;5,14;6,14;7,14;8,14;9,14;10,14];
kill5=[1,13;2,13;3,13;4,13;5,13;6,13;7,13;8,13;9,13;10,13];
kill6=[1,12;2,12;3,12;4,12;5,12;6,12;7,12;8,12;9,12;10,12];
kill7=[1,11;2,11;3,11;4,11;5,11;6,11;7,11;8,11;9,11;10,11];
kill8=[1,10;2,10;3,10;4,10;5,10;6,10;7,10;8,10;9,10;10,10];
kill9=[1,9;2,9;3,9;4,9;5,9;6,9;7,9;8,9;9,9;10,9];
kill10=[1,8;2,8;3,8;4,8;5,8;6,8;7,8;8,8;9,8;10,8];
kill11=[1,7;2,7;3,7;4,7;5,7;6,7;7,7;8,7;9,7;10,7];
kill12=[1,6;2,6;3,6;4,6;5,6;6,6;7,6;8,6;9,6;10,6];
kill13=[1,5;2,5;3,5;4,5;5,5;6,5;7,5;8,5;9,5;10,5];
kill14=[1,4;2,4;3,4;4,4;5,4;6,4;7,4;8,4;9,4;10,4];
kill15=[1,3;2,3;3,3;4,3;5,3;6,3;7,3;8,3;9,3;10,3];
kill16=[1,2;2,2;3,2;4,2;5,2;6,2;7,2;8,2;9,2;10,2];
kill17=[1,1;2,1;3,1;4,1;5,1;6,1;7,1;8,1;9,1;10,1];
%%%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%% %%%%%%%%%
plotelos=scatter(gca,s(:,1),s(:,2),220,s(:,3:5),'s','filled');
plott=scatter(gca,h(:,1),h(:,2),220,h(:,3:5),'s','filled');
set(gcf, 'KeyPressFcn', @key)
fps = 5;
game = timer('ExecutionMode', 'FixedRate', 'Period',1/fps, 'TimerFcn', @elosgame);
start(game)
%%%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%% %%%%%%%%%
    function elosgame(~,~)
        talant=find(h>18);
        if length(talant)==0
        else
            stop(game);
            ButtonName1 = questdlg('Game over','what do you mean to do?','restart','end', 'end');
            if ButtonName1 == 'restart';
                clf;
                elos();
            else
                close;
            end
        end
        if length(wall1)==length(unique([wall1;kill1],'rows'));
            wall1(find(wall1(:,2)==17),:)=[];
            h(find(h(:,2)==17),:)=[];
            wall1(wall1(:,2)>17)=wall1(wall1(:,2)>17)-1;
            h(h(:,2)>17)=h(h(:,2)>17)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill2],'rows'));
            wall1(find(wall1(:,2)==16),:)=[];
            h(find(h(:,2)==16),:)=[];
            wall1(wall1(:,2)>16)=wall1(wall1(:,2)>16)-1;
            h(h(:,2)>16)=h(h(:,2)>16)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill3],'rows'));
            wall1(find(wall1(:,2)==15),:)=[];
            h(find(h(:,2)==15),:)=[];
            wall1(wall1(:,2)>15)=wall1(wall1(:,2)>15)-1;
            h(h(:,2)>15)=h(h(:,2)>15)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill4],'rows'));
            wall1(find(wall1(:,2)==14),:)=[];
            h(find(h(:,2)==14),:)=[];
            wall1(wall1(:,2)>14)=wall1(wall1(:,2)>14)-1;
            h(h(:,2)>14)=h(h(:,2)>14)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill5],'rows'));
            wall1(find(wall1(:,2)==13),:)=[];
            h(find(h(:,2)==13),:)=[];
            wall1(wall1(:,2)>13)=wall1(wall1(:,2)>13)-1;
            h(h(:,2)>13)=h(h(:,2)>13)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill6],'rows'));
            wall1(find(wall1(:,2)==12),:)=[];
            h(find(h(:,2)==12),:)=[];
            wall1(wall1(:,2)>12)=wall1(wall1(:,2)>12)-1;
            h(h(:,2)>12)=h(h(:,2)>12)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill7],'rows'));
            wall1(find(wall1(:,2)==11),:)=[];
            h(find(h(:,2)==11),:)=[];
            wall1(wall1(:,2)>11)=wall1(wall1(:,2)>11)-1;
            h(h(:,2)>11)=h(h(:,2)>11)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill8],'rows'));
            wall1(find(wall1(:,2)==10),:)=[];
            h(find(h(:,2)==0),:)=[];
            wall1(wall1(:,2)>10)=wall1(wall1(:,2)>10)-1;
            h(h(:,2)>10)=h(h(:,2)>10)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill9],'rows'));
            wall1(find(wall1(:,2)==9),:)=[];
            h(find(h(:,2)==9),:)=[];
            wall1(wall1(:,2)>9,2)=wall1(wall1(:,2)>9,2)-1;
            h(h(:,2)>9,2)=h(h(:,2)>9,2)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill10],'rows'));
            wall1(find(wall1(:,2)==8),:)=[];
            h(find(h(:,2)==8),:)=[];
            wall1(wall1(:,2)>8,2)=wall1(wall1(:,2)>8,2)-1;
            h(h(:,2)>8,2)=h(h(:,2)>8,2)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill11],'rows'));
            wall1(find(wall1(:,2)==7),:)=[];
            h(find(h(:,2)==7),:)=[];
            wall1(wall1(:,2)>7,2)=wall1(wall1(:,2)>7,2)-1;
            h(h(:,2)>7,2)=h(h(:,2)>7,2)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill12],'rows'));
            wall1(find(wall1(:,2)==6),:)=[];
            h(find(h(:,2)==6),:)=[];
            wall1(wall1(:,2)>6,2)=wall1(wall1(:,2)>6,2)-1;
            h(h(:,2)>6,2)=h(h(:,2)>6,2)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill13],'rows'));
            wall1(find(wall1(:,2)==5),:)=[];
            h(find(h(:,2)==5),:)==[];
            wall1(wall1(:,2)>5,2)=wall1(wall1(:,2)>59,2)-1;
            h(h(:,2)>5,2)=h(h(:,2)>5,2)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill14],'rows'));
            wall1(find(wall1(:,2)==4),:)=[];
            h(find(h(:,2)==4),:)=[];
            wall1(wall1(:,2)>4,2)=wall1(wall1(:,2)>4,2)-1;
            h(h(:,2)>4,2)=h(h(:,2)>4,2)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill15],'rows'));
            wall1(find(wall1(:,2)==3),:)=[];
            h(find(h(:,2)==3),:)=[];
            wall1(wall1(:,2)>3,2)=wall1(wall1(:,2)>3,2)-1;
            h(h(:,2)>3,2)=h(h(:,2)>3,2)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill16],'rows'));
            wall1(find(wall1(:,2)==2),:)=[];
            h(find(h(:,2)==2),:)=[];
            wall1(wall1(:,2)>2,2)=wall1(wall1(:,2)>2,2)-1;
            h(h(:,2)>2,2)=h(h(:,2)>2,2)-1;
            score=score+10;
        end
        if length(wall1)==length(unique([wall1;kill17],'rows'));
            wall1(find(wall1(:,2)==1),:)=[];
            h(find(h(:,2)==1),:)=[];
            wall1(wall1(:,2)>1,2)=wall1(wall1(:,2)>1,2)-1;
            h(h(:,2)>1,2)=h(h(:,2)>1,2)-1;
            score=score+10;
        end
        s1=s1+dir;
        s=s+direct;
        control=length(intersect(dir+s1,wall1,'rows'));
        if control==0;
        else
            h=[h;s];
            wall1=[wall1;s1];
            power=randi(7);
            power2=randi(4);
            if power==1;
                sn=A1;
                change=1;
            end
            if power==2;
                sn=B1;
                change=21;
            end
            if power==3;
                sn=C1;
                change=31;
            end
            if power==4;
                sn=D1;
                change=41;
            end
            if power==5;
                sn=E1;
                change=51;
            end
            if power==6;
                sn=F1;
                change=61;
            end
            if power==7;
                sn=G1;
                change=71;
            end
            if power2==1;
                co=r;
            end
            if power2==2;
                co=b;
            end
            if power2==3;
                co=g;
            end
            if power2==4;
                co=c;
            end
            if waigua==1;
                s=[sn,co];
                s1=sn;
                tip=1;
            end
            if waigua==2;
                s=[B1,co];
                s1=B1;
                tip=1;
                change=21;
            end
        end
        if color==1;
            set(plott,'XData',h(:,1),'YData',h(:,2),'CData',h(:,3:5))
            set(plotelos,'XData',s(:,1),'YData',s(:,2),'CData',s(:,3:5))
        end
        if color==2;
            set(plott,'XData',h(:,1),'YData',h(:,2),'CData',[1 1 1])
            set(plotelos,'XData',s(:,1),'YData',s(:,2),'CData',[1 1 1])
        end
    end
    function key(~,event);
        switch event.Key;
            case 'uparrow';
                po=[s1(1,:);s1(1,:);s1(1,:);s1(1,:)];
                pp=[5,23;5,23;5,23;5,23];
                pa=[s(1,3:5);s(1,3:5);s(1,3:5);s(1,3:5)];
                pos=po-pp;
                if change==21;
                    if length(intersect(B2+pos,wall1,'rows'))==0;
                        if length(intersect(B2+pos,wall2,'rows'))==0;
                            if length(intersect(B2+pos,wall3,'rows'))==0;
                                s=[B2+pos,pa];
                                s1=B2+pos;
                                change=22;
                            end
                        end
                    end
                end
                if change==23;
                    if length(intersect(B1+pos,wall1,'rows'))==0;
                        if length(intersect(B1+pos,wall2,'rows'))==0;
                            if length(intersect(B1+pos,wall3,'rows'))==0;
                                s=[B1+pos,pa];
                                s1=B1+pos;
                                change=20;
                            end
                        end
                    end
                end
                if change==31;
                    if length(intersect(C2+pos,wall1,'rows'))==0;
                        if length(intersect(C2+pos,wall2,'rows'))==0;
                            if length(intersect(C2+pos,wall3,'rows'))==0;
                                s=[C2+pos,pa];
                                s1=C2+pos;
                                change=32;
                            end
                        end
                    end
                end
                if change==33;
                    if length(intersect(C3+pos,wall1,'rows'))==0;
                        if length(intersect(C3+pos,wall2,'rows'))==0;
                            if length(intersect(C3+pos,wall3,'rows'))==0;
                                s=[C3+pos,pa];
                                s1=C3+pos;
                                change=34;
                            end
                        end
                    end
                end
                if change==35;
                    if isempty(intersect(C4+pos,wall1,'rows'));
                        if length(intersect(C4+pos,wall2,'rows'))==0;
                            if length(intersect(C4+pos,wall3,'rows'))==0;
                                s=[C4+pos,pa];
                                s1=C4+pos;
                                change=36;
                            end
                        end
                    end
                end
                if change==37;
                    if length(intersect(C1+pos,wall1,'rows'))==0;
                        if length(intersect(C1+pos,wall2,'rows'))==0;
                            if length(intersect(C1+pos,wall3,'rows'))==0;
                                s=[C1+pos,pa];
                                s1=C1+pos;
                                change=30;
                            end
                        end
                    end
                end
                if change==41;
                    if length(intersect(D2+pos,wall1,'rows'))==0;
                        if length(intersect(D2+pos,wall2,'rows'))==0;
                            if length(intersect(D2+pos,wall3,'rows'))==0;
                                s=[D2+pos,pa];
                                s1=D2+pos;
                                change=42;
                            end
                        end
                    end
                end
                if change==43;
                    if length(intersect(D3+pos,wall1,'rows'))==0;
                        if length(intersect(D3+pos,wall2,'rows'))==0;
                            if length(intersect(D3+pos,wall3,'rows'))==0;
                                s=[D3+pos,pa];
                                s1=D3+pos;
                                change=44;
                            end
                        end
                    end
                end
                if change==45;
                    if length(intersect(D4+pos,wall1,'rows'))==0;
                        if length(intersect(D4+pos,wall2,'rows'))==0;
                            if length(intersect(D4+pos,wall3,'rows'))==0;
                                s=[D4+pos,pa];
                                s1=D4+pos;
                                change=46;
                            end
                        end
                    end
                end
                if change==47;
                    if length(intersect(D1+pos,wall1,'rows'))==0;
                        if length(intersect(D1+pos,wall2,'rows'))==0;
                            if length(intersect(D1+pos,wall3,'rows'))==0;
                                s=[D1+pos,pa];
                                s1=D1+pos;
                                change=40;
                            end
                        end
                    end
                end
                if change==51;
                    if length(intersect(E2+pos,wall1,'rows'))==0;
                        if length(intersect(E2+pos,wall2,'rows'))==0;
                            if length(intersect(E2+pos,wall3,'rows'))==0;
                                s=[E2+pos,pa];
                                s1=E2+pos;
                                change=52;
                            end
                        end
                    end
                end
                if change==53;
                    if length(intersect(E3+pos,wall1,'rows'))==0;
                        if length(intersect(E3+pos,wall2,'rows'))==0;
                            if length(intersect(E3+pos,wall3,'rows'))==0;
                                s=[E3+pos,pa];
                                s1=E3+pos;
                                change=54;
                            end
                        end
                    end
                end
                if change==55;
                    if length(intersect(E4+pos,wall1,'rows'))==0;
                        if length(intersect(E4+pos,wall2,'rows'))==0;
                            if length(intersect(E4+pos,wall3,'rows'))==0;
                                s=[E4+pos,pa];
                                s1=E4+pos;
                                change=56;
                            end
                        end
                    end
                end
                if change==57;
                    if length(intersect(E1+pos,wall1,'rows'))==0;
                        if length(intersect(E1+pos,wall2,'rows'))==0;
                            if length(intersect(E1+pos,wall3,'rows'))==0;
                                s=[E1+pos,pa];
                                s1=E1+pos;
                                change=50;
                            end
                        end
                    end
                end
                if change==61;
                    if length(intersect(F2+pos,wall1,'rows'))==0;
                        if length(intersect(F2+pos,wall2,'rows'))==0;
                            if length(intersect(F2+pos,wall3,'rows'))==0;
                                s=[F2+pos,pa];
                                s1=F2+pos;
                                change=62;
                            end
                        end
                    end
                end
                if change==63;
                    if length(intersect(F3+pos,wall1,'rows'))==0;
                        if length(intersect(F3+pos,wall2,'rows'))==0;
                            if length(intersect(F3+pos,wall3,'rows'))==0;
                                s=[F3+pos,pa];
                                s1=F3+pos;
                                change=64;
                            end
                        end
                    end
                end
                if change==65;
                    if length(intersect(F4+pos,wall1,'rows'))==0;
                        if length(intersect(F4+pos,wall2,'rows'))==0;
                            if length(intersect(F4+pos,wall3,'rows'))==0;
                                s=[F4+pos,pa];
                                s1=F4+pos;
                                change=66;
                            end
                        end
                    end
                end
                if change==67;
                    if length(intersect(F1+pos,wall1,'rows'))==0;
                        if length(intersect(F1+pos,wall2,'rows'))==0;
                            if length(intersect(F1+pos,wall3,'rows'))==0;
                                s=[F1+pos,pa];
                                s1=F1+pos;
                                change=60;
                            end
                        end
                    end
                end
                if change==71;
                    if length(intersect(G2+pos,wall1,'rows'))==0;
                        if length(intersect(G2+pos,wall2,'rows'))==0;
                            if length(intersect(G2+pos,wall3,'rows'))==0;
                                s=[G2+pos,pa];
                                s1=G2+pos;
                                change=72;
                            end
                        end
                    end
                end
                if change==73;
                    if length(intersect(G3+pos,wall1,'rows'))==0;
                        if length(intersect(G3+pos,wall2,'rows'))==0;
                            if length(intersect(G3+pos,wall3,'rows'))==0;
                                s=[G3+pos,pa];
                                s1=G3+pos;
                                change=74;
                            end
                        end
                    end
                end
                if change==75;
                    if length(intersect(G4+pos,wall1,'rows'))==0;
                        if length(intersect(G4+pos,wall2,'rows'))==0;
                            if length(intersect(G4+pos,wall3,'rows'))==0;
                                s=[G4+pos,pa];
                                s1=G4+pos;
                                change=76;
                            end
                        end
                    end
                end
                if change==77;
                    if length(intersect(G1+pos,wall1,'rows'))==0;
                        if length(intersect(G1+pos,wall2,'rows'))==0;
                            if length(intersect(G1+pos,wall3,'rows'))==0;
                                s=[G1+pos,pa];
                                s1=G1+pos;
                                change=70;
                            end
                        end
                    end
                end
                change=change+1;
            case 'w'
                color=2;
            case 'c'
                color=1
            case '1';
                waigua=1;
            case '2';
                waigua=2;
            case 'leftarrow';
                if length(intersect(s1+lefty,wall1,'rows'))==0
                    if length(intersect(s1+leftyy,wall1,'rows'))==0
                        if length(intersect(s1+lefty,wall2,'rows'))==0;
                            s=s+left;
                            s1=s1+lefty;
                        end
                    end
                end
            case 'rightarrow';
                if length(intersect(s1+righty,wall1,'rows'))==0
                    if length(intersect(s1+rightyy,wall1,'rows'))==0
                        if length(intersect(s1+righty,wall3,'rows'))==0;
                            s=s+right;
                            s1=s1+righty;
                        end
                    end
                end
        end
    end
end

到此这篇关于基于Matlab实现俄罗斯方块游戏的文章就介绍到这了,更多相关Matlab俄罗斯方块内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Python实现简单的俄罗斯方块游戏

    本文实例为大家分享了Python实现俄罗斯方块游戏的具体代码,供大家参考,具体内容如下 玩法:童年经典,普通模式没啥意思,小时候我们都是玩加速的. 源码分享: import os import sys import random from modules import * from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * '''定义俄罗斯方块游戏类''' class TetrisG

  • Matlab实现别踩白块小游戏的示例代码

    目录 游戏效果 游戏说明 完整代码 pianoKeys.m(主函数) getMusic.m(用于获取音乐数据) 游戏效果 游戏说明 ‘A’,‘S’,‘D’,F’按键代表四条通路(点击S开始),按错按钮或黑块接触底限均为失败. 完整代码 分两个m文件,应放在同一文件夹 pianoKeys.m(主函数) function pianoKeys %======================%======== [v1,notes,fs]=getMusic;%读取音乐 %=================

  • 基于Matlab制作一款简单的龙舟小游戏

    效果图: 没找到合适的背景就自己画了个,大家如果有更好看的可以换一下... 步骤 1 创建Axes及图片导入 窗口创建: Mainfig=figure('units','pixels','position',[50 100 760 400],... 'Numbertitle','off','menubar','none','resize','off',... 'name','dragonBoat'); axes('parent',Mainfig,'position',[0 0 1 1],...

  • 如何利用Matlab制作一款真正的拼图小游戏

    效果: 简单原理介绍: 1构造0,1矩阵作为每片拼图的透明度,可以构造出不规则形状的拼图(image函数有alphaData属性可以设置) jigsawMask=zeros(101*5,101*5); jigsawMask(102:404,102:404)=1; [xMesh,yMesh]=meshgrid(1:101*5,1:101*5); dis1=sqrt((xMesh-51).^2+(yMesh-253).^2); dis2=sqrt((xMesh-505+50).^2+(yMesh-2

  • javascript+css实现俄罗斯方块小游戏

    俄罗斯方块,一个很有趣的一个小游戏,此次基于html+css+javaScript实现,包含在一个方块落地后自动生成方块.操控方块的移动以及方块变形等. 部分代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>俄罗斯方块 - 经典版V10</title> <link rel="stylesheet" href=

  • Java实现俄罗斯方块小游戏源码

    本文实例为大家分享了Java实现俄罗斯方块小游戏的具体代码,供大家参考,具体内容如下 一.最终效果 二.功能需求 1. 在二维平面里面用各种随机产生的方块堆积木,每满一行消去一行,当达到顶部时,游戏结束.2. 通过方向键来控制方块转动,左移,右移和直落.3. 方块下落统一设置蓝色,接触底部变粉色.4. 计算分数,分数是由方块的类型决定的,每堆积一个方块就把分数累加到总分中.5. 游戏有开始.重新开始.降低提高级数(速度).暂停.退出 三.程序实现 这个是最基础的方块素材 package 俄罗斯方

  • MATLAB实现五子棋游戏(双人对战、可悔棋)

    本文实例为大家分享了MATLAB实现五子棋游戏的具体代码,供大家参考,具体内容如下 程序介绍: 1.此游戏只可用于双人对战. 2.棋盘颜色.棋盘格数.棋子颜色等参数均可自由设置 3.鼠标点击非棋盘区域可悔棋. 一.游戏界面 二.主程序及函数 1.主程序 %Author:LeiZhen %Date:2018-03-12 %此程序只下五子棋,并判断胜负关系 clear all; clc %定义颜色 Color_QiPanBack=[135,206,255]; Color_ChessLine=[100

  • c++实现俄罗斯方块游戏代码

    俄罗斯方块c++ 1.创建项目2.总共需要创建两个文件,一个main.cpp,一个是elsfk2.h.本人使用的编译器是vs2019. 3.在项目的源文件夹下创建一个文件夹image 4.把下面两张图片重命名好放进刚创建的文件夹 elsfk.jpg elsfk_block.jpg 5.把下列代码分别复制到对应文件中 ----------------------------------------------------------------------------------- 以下是main

  • 基于Matlab实现俄罗斯方块游戏

    我最早写的一个matlab小游戏 写的可能不够简洁,但还有可玩性, 先发上来,以后可能改进或出教程. 大家自己探索吧(外挂是哪个按键,更改颜色是哪个按键) 游戏效果 完整代码 function elos hold on axis equal axis(0.5+[0,10,0,20]) set(gca,'xtick',[],'ytick',[],'xcolor','w','ycolor','w') set(gca,'color','k') %%%%%%%%%%% %%%%%%%%%% %%%%%%

  • 基于C#实现俄罗斯方块游戏

    最近在看C#,写了一个很水的方块游戏练手. 代码: namespace game { class Square { public Square() { state = 0; positionY = 0; positionX = 0; } public Square(int InitShapeCnt, int InitState) { state = InitState; positionY = 0; positionX = 0; InitShape(InitShapeCnt); } public

  • 基于Matlab实现抖音小游戏苹果蛇

    最近抖音上苹果蛇小游戏大火,为了证明MATLAB无所不能,咋能不跟风做一个?于是就有了这一篇. 还是提一句这个小游戏开始玩的心路历程: 第1-5关:?这不就是有重力的贪吃蛇,有任何难度嘛?? 第6关:嗯...这个小技巧还是有点意思的 第30关:???这绕来绕去的是人出的题目?? 第90关:… …疯了疯了已经疯了 废话不多说看一下MATLAB版的完整代码: 为了方便修改,关卡地图就摆在m文件里,总共写了八关,但是只有代码没有素材包还是运行不了,因此请从文末获取完整压缩包. function app

  • 基于Matlab制作伪3D第一视角迷宫小游戏

    目录 游戏效果 游戏原理说明 第一代程序计算交点方法 第二代程序计算交点方法 距离转换为线段长度 完整代码 游戏效果 使用键盘上方向键↑向前移动 使用键盘左右方向键调整← →朝向 游戏原理说明 原理很简单,如效果图所示,主要就是以角色视角方向发射大量的直线模拟视线,并计算直线与墙壁交点,获取每一条视线方向下,角色到墙壁的距离,然后根据近大远小的原理绘制不同长度的竖向直线模拟墙壁. 第一代程序计算交点方法 第一代程序是使用的polyshape对象(二维多边形对象)制作墙壁,polyshape对象重

  • Python使用pygame模块编写俄罗斯方块游戏的代码实例

    文章先介绍了关于俄罗斯方块游戏的几个术语. 边框--由10*20个空格组成,方块就落在这里面. 盒子--组成方块的其中小方块,是组成方块的基本单元. 方块--从边框顶掉下的东西,游戏者可以翻转和改变位置.每个方块由4个盒子组成. 形状--不同类型的方块.这里形状的名字被叫做T, S, Z ,J, L, I , O.如下图所示: 模版--用一个列表存放形状被翻转后的所有可能样式.全部存放在变量里,变量名字如S_SHAPE_TEMPLATE or J_SHAPE_TEMPLATE 着陆--当一个方块

  • 一个MIDP俄罗斯方块游戏的设计和实现

    文章来源:csdn 作者:陈万飞 作者简介 陈万飞,男,中南大学数软系学士,曾任北京长城软件高级程序员,系统分析师.有较为丰富的j2se,j2ee开发经验.目前致力于j2me研究工作.可通过chen_cwf@163.net与他联系 摘要 本文给出了一个基于MIDP1.0的俄罗斯方块游戏的设计方案,并给出全部实现源代码.该游戏的最大特色是屏幕自适应,无论各种手机,PDA的屏幕大小如何,该游戏总是能获得最佳的显示效果.游戏在J2me wireless toolkit 2.1的4种模拟器上测试通过.

  • python 基于pygame实现俄罗斯方块

    一.简单说明 80.90后的小伙伴都玩过"俄罗斯方块",那种"叱咤风云"场景 偶尔闪现在脑海 真的是太爽了:如果没有来得及玩过的同学,这次可以真正的自己做一个了 本实例用的是Python3(当然了Python3.5 3.6 3.7....都行 )+ pygame实现的 运行之前需要安装pygame模块,安装命令如下 pip install pygame -i https://mirrors.aliyun.com/pypi/simple/ 二.运行效果 三.完整代码

  • 用Python编写一个简单的俄罗斯方块游戏的教程

    俄罗斯方块游戏,使用Python实现,总共有350+行代码,实现了俄罗斯方块游戏的基本功能,同时会记录所花费时间,消去的总行数,所得的总分,还包括一个排行榜,可以查看最高记录. 排行榜中包含一系列的统计功能,如单位时间消去的行数,单位时间得分等. 附源码: from Tkinter import * from tkMessageBox import * import random import time #俄罗斯方块界面的高度 HEIGHT = 18 #俄罗斯方块界面的宽度 WIDTH = 10

  • JavaScript实现俄罗斯方块游戏过程分析及源码分享

    观摩一下<编程之美>:"程序虽然很难写,却很美妙.要想把程序写好,需要写好一定的基础知识,包括编程语言.数据结构与算法.程序写得好,需要缜密的逻辑思维能力和良好的梳理基础,而且熟悉编程环境和编程工具." 学了几年的计算机,你有没有爱上编程.话说,没有尝试自己写过一个游戏,算不上热爱编程. 俄罗斯方块曾经造成的轰动与造成的经济价值可以说是游戏史上的一件大事,它看似简单但却变化无穷,令人上瘾.相信大多数同学,曾经为它痴迷得茶不思饭不想. 游戏规则 1.一个用于摆放小型正方形的平

随机推荐