基于Matlab實現(xiàn)俄羅斯方塊游戲_第1頁
基于Matlab實現(xiàn)俄羅斯方塊游戲_第2頁
基于Matlab實現(xiàn)俄羅斯方塊游戲_第3頁
基于Matlab實現(xiàn)俄羅斯方塊游戲_第4頁
基于Matlab實現(xiàn)俄羅斯方塊游戲_第5頁
已閱讀5頁,還剩12頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

第基于Matlab實現(xiàn)俄羅斯方塊游戲先發(fā)上來,以后可能改進或出教程。

大家自己探索吧(外掛是哪個按鍵,更改顏色是哪個按鍵)

游戲效果

完整代碼

functionelos

holdon

axisequal

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=[100;100;100;100];

b=[001;001;001;001];

g=[010;010;010;010];

c=[011;011;011;011];

w=[111;111;111;111];

h=[-50,-50,0,0,1;-49,-49,0,0,1;-48,-48,0,0,1;-47,-47,0,0,1];

wall1=[10;20;30;40;50;60;70;80;90;100];

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)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

functionelosgame(~,~)

talant=find(h

iflength(talant)==0

else

stop(game);

ButtonName1=questdlg('Gameover','whatdoyoumeantodo','restart','end','end');

ifButtonName1=='restart';

clf;

elos();

else

close;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

iflength(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;

s1=s1+dir;

s=s+direct;

control=length(intersect(dir+s1,wall1,'rows'));

ifcontrol==0;

else

h=[h;s];

wall1=[wall1;s1];

power=randi(7);

power2=randi(4);

ifpower==1;

sn=A1;

change=1;

ifpower==2;

sn=B1;

change=21;

ifpower==3;

sn=C1;

change=31;

ifpower==4;

sn=D1;

change=41;

ifpower==5;

sn=E1;

change=51;

ifpower==6;

sn=F1;

change=61;

ifpower==7;

sn=G1;

change=71;

ifpower2==1;

co=r;

ifpower2==2;

co=b;

ifpower2==3;

co=g;

ifpower2==4;

co=c;

ifwaigua==1;

s=[sn,co];

s1=sn;

tip=1;

ifwaigua==2;

s=[B1,co];

s1=B1;

tip=1;

change=21;

ifcolor==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))

ifcolor==2;

set(plott,'XData',h(:,1),'YData',h(:,2),'CData',[111])

set(plotelos,'XData',s(:,1),'YData',s(:,2),'CData',[111])

functionkey(~,event);

switchevent.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;

ifchange==21;

iflength(intersect(B2+pos,wall1,'rows'))==0;

iflength(intersect(B2+pos,wall2,'rows'))==0;

iflength(intersect(B2+pos,wall3,'rows'))==0;

s=[B2+pos,pa];

s1=B2+pos;

change=22;

ifchange==23;

iflength(intersect(B1+pos,wall1,'rows'))==0;

iflength(intersect(B1+pos,wall2,'rows'))==0;

iflength(intersect(B1+pos,wall3,'rows'))==0;

s=[B1+pos,pa];

s1=B1+pos;

change=20;

ifchange==31;

iflength(intersect(C2+pos,wall1,'rows'))==0;

iflength(intersect(C2+pos,wall2,'rows'))==0;

iflength(intersect(C2+pos,wall3,'rows'))==0;

s=[C2+pos,pa];

s1=C2+pos;

change=32;

ifchange==33;

iflength(intersect(C3+pos,wall1,'rows'))==0;

iflength(intersect(C3+pos,wall2,'rows'))==0;

iflength(intersect(C3+pos,wall3,'rows'))==0;

s=[C3+pos,pa];

s1=C3+pos;

change=34;

ifchange==35;

ifisempty(intersect(C4+pos,wall1,'rows'));

iflength(intersect(C4+pos,wall2,'rows'))==0;

iflength(intersect(C4+pos,wall3,'rows'))==0;

s=[C4+pos,pa];

s1=C4+pos;

change=36;

ifchange==37;

iflength(intersect(C1+pos,wall1,'rows'))==0;

iflength(intersect(C1+pos,wall2,'rows'))==0;

iflength(intersect(C1+pos,wall3,'rows'))==0;

s=[C1+pos,pa];

s1=C1+pos;

change=30;

ifchange==41;

iflength(intersect(D2+pos,wall1,'rows'))==0;

iflength(intersect(D2+pos,wall2,'rows'))==0;

iflength(intersect(D2+pos,wall3,'rows'))==0;

s=[D2+pos,pa];

s1=D2+pos;

change=42;

ifchange==43;

iflength(intersect(D3+pos,wall1,'rows'))==0;

iflength(intersect(D3+pos,wall2,'rows'))==0;

iflength(intersect(D3+pos,wall3,'rows'))==0;

s=[D3+pos,pa];

s1=D3+pos;

change=44;

ifchange==45;

iflength(intersect(D4+pos,wall1,'rows'))==0;

iflength(intersect(D4+pos,wall2,'rows'))==0;

iflength(intersect(D4+pos,wall3,'rows'))==0;

s=[D4+pos,pa];

s1=D4+pos;

change=46;

ifchange==47;

iflength(intersect(D1+pos,wall1,'rows'))==0;

iflength(intersect(D1+pos,wall2,'rows'))==0;

iflength(intersect(D1+pos,wall3,'rows'))==0;

s=[D1+pos,pa];

s1=D1+pos;

change=40;

ifchange==51;

iflength(intersect(E2+pos,wall1,'rows'))==0;

iflength(intersect(E2+pos,wall2,'rows'))==0;

iflength(intersect(E2+pos,wall3,'rows'))==0;

s=[E2+pos,pa];

s1=E2+pos;

change=52;

ifchange==53;

iflength(intersect(E3+pos,wall1,'rows'))==0;

iflength(intersect(E3+pos,wall2,'rows'))==0;

iflength(intersect(E3+pos,wall3,'rows'))==0;

s=[E3+pos,pa];

s1=E3+pos;

change=54;

ifchange==55;

iflength(intersect(E4+pos,wall1,'rows'))==0;

iflength(intersect(E4+pos,wall2,'rows'))==0;

iflength(intersect(E4+pos,wall3,'rows'))==0;

s=[E4+pos,pa];

s1=E4+pos;

change=56;

ifchange==57;

iflength(intersect(E1+pos,wall1,'rows'))==0;

iflength(intersect(E1+pos,wall2,'rows'))==0;

iflength(intersect(E1+pos,wall3,'rows'))==0;

s=[E1+pos,pa];

s1=E1+pos;

change=50;

ifchange==61;

iflength(intersect(F2+pos,wall1,'rows'))==0;

iflength(intersect(F2+pos,wall2,'rows'))==0;

iflength(intersect(F2+pos,wall3,'rows'))==0;

s=[F2+pos,pa];

s1=F2+pos;

change=62;

ifchange==63;

iflength(intersect(F3+pos,wall1,'rows'))==0;

iflength(intersect(F3+pos,wall2,'rows'))==0;

iflength(intersect(F3+pos,wall3,'rows'))==0;

s=[F3+pos,pa];

s1=F3+pos;

change=64;

ifchange==65;

iflength(intersect(F4+pos,wall1,'rows'))==0;

iflength(intersect(F4+pos,wall2,'rows'))==0;

iflength(intersect(F4+pos,wall3,'rows'))==0;

s=[F4+pos,pa];

s1=F4+pos;

change=66;

ifchange==67;

iflength(intersect(F1+pos,wall1,'rows'))==0;

iflength(intersect(F1+pos,wall2,'rows'))==0;

iflength(intersect(F1+pos,wall3,'rows'))==0;

s=[F1+pos,pa];

s1=F1+pos;

change=60;

if

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論