




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第基于Matlab实现俄罗斯方块游戏先发上来,以后可能改进或出教程。
大家自己探索吧(外挂是哪个按键,更改颜色是哪个按键)
游戏效果
完整代码
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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 网络游戏版号申请合规代理服务详细合同模板
- 博物馆展览主题策划与视觉设计合同
- 新能源企业控制权诉讼代理及知识产权保护协议
- 网络安全合作协议修订补充
- 《初中生物《遗传与进化》课件》
- 《植物生长的奇迹:课件展示种子发芽的详细过程》
- 养老机构事务管理
- 如何做好保险销售课件
- 华为培训答辩演讲
- 药店顾客投诉处理培训课件
- GB/T 35199-2017土方机械轮胎式装载机技术条件
- GB/T 25840-2010规定电气设备部件(特别是接线端子)允许温升的导则
- GB/T 12008.7-2010塑料聚醚多元醇第7部分:黏度的测定
- 投行业务二o一五年度经营绩效考核办法
- 心内科实习生规培手册
- DB31T 685-2019 养老机构设施与服务要求
- 2021年苏州资产管理有限公司招聘笔试试题及答案解析
- 北票市沙金沟金矿地质调查总结
- 模具加工3数控加工_图文.ppt课件
- 河南省确山县三里河治理工程
- 基于PLC的温室大棚控制系统设计说明
评论
0/150
提交评论