Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Matlab to write a simple version of Lianliankan Mini Game

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use Matlab to compile a simple version of Lianliankan Mini Game". In daily operation, I believe many people have doubts about how to use Matlab to compile a simple version of Lianliankan Mini Game. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to use Matlab to prepare a simple version of Lianliankan Mini Game". Next, please follow the editor to study!

Screenshot of the game

Game assembly instructions

Our variable path inputs the relative or absolute path of the image packet

Here we have no problem with path=' pictures directly because the folder name is "picture".

The folder is the picture material, its name does not have any requirements, the shape had better be square, but if not, it is not a problem, the program will automatically stretch it into a square.

What we are asking here is to read into the jpg format, if you want to read both png,jpg. The simplest thing is to read it directly twice.

Complete code

Function ConnectingGame% Lianliankan Picture Import = path=' Picture'; picInformation=dir (fullfile (path,'*.jpg')); N=length (picInformation); for iLianliankan N picList. (['pic',num2str (I)]) = Imread ([path,'\', picInformation (I) .name]); end% global variable = global selectedPos clickPosglobal redLinePntsglobal picMatselectedPos= []; redLinePnts= [];% Picture Matrix Generation = function createMat (~, ~) tempMat=zeros (8pier6); while any (any (tempMat==0)) zeosPos=find (tempMat==0); temprand=rand (1) tempMat==0 (zeosPos); [~, tempSort] = sort (temprand); tempNum=zeosPos (tempSort (1:2)) TempMat (tempNum) = randi (N); end picMat=zeros (10Lab 8); picMat (2Vera 9Magazine 7) = tempMat; endcreateMat ()% main frame generation = = MainFig=figure ('units','pixels','position', [750250 (950250) * 0.5 (750250) * 0.5], 'Numbertitle','off','menubar','none','resize','off',... 'name','ConnectingGame | by slandarer'); axes (' parent',MainFig,'position', [0 011],... XLim', [40 10-100 10-40],... YLim', [40, 8, 100, 8, 5, 40]. Color', [0.95, 0.95]. 'NextPlot','add',... 'layer','bottom',... 'Visible','on',... 'YDir','reverse',... 'XTick', [],... 'YTick', []); uh2=uimenu (' label',' help'); uimenu (uh2,'label',' start over', 'callback',@restartGame) for iLife2 Vane 9 for juni2 label',' 7 drawPicHdl (iLab j) = image ([(iMustl 1) * 100pr iLive100] + (iMuk 1) * 5, [(JMAT 1) * 100th jacquard 100] + (JMAE 1) * 5. PicList. (['pic',num2str (picMat (iMagnej)]),' tag', [num2str (I), num2str (j)],... 'ButtonDownFcn',@clickOnPic); endend% restart function = function restartGame (~, ~) createMat () for ii=2:9 for jj=2:7 set (drawPicHdl (ii,jj),' CData',picList. (['pic',num2str (picMat (ii,jj)])) endend end% main function = function clickOnPic (object,~) redLinePnts= [] ClickPos= [str2num (object.Tag (1)), str2num (object.Tag (2))]; if isempty (selectedPos), selectedPos=clickPos End if ~ all (selectedPos==clickPos)%-condition1=0;condition2=0 Switch 1 case any (selectedPos (1) = = clickPos (1)) condition1=abs (selectedPos (2)-clickPos (2)) = = 1; tempVector1=sort ([selectedPos (2), clickPos (2)]) + [1-1]; tempSum=sum (clickPos (1), tempVector1 (1): tempVector1 (2) Condition2= (tempSum==0) & ~ isempty (picMat (clickPos (1), tempVector1 (1): tempVector1 (2)); case any (selectedPos (2) = = clickPos (2)) condition1=abs (selectedPos (1)-clickPos (1)) = = 1; tempVector1=sort ([selectedPos (1), clickPos (1)]) + [1-1] TempSum=sum (picMat (tempVector1 (1): tempVector1 (2), clickPos (2)); condition2= (tempSum==0) & ~ isempty (picMat (clickPos (1), tempVector1 (1): tempVector1 (2); end if (condition1 | | condition2) & & picMat (clickPos (1), clickPos (2)) = picMat (selectedPos (1), selectedPos (2)) redLinePnts= [selectedPos;clickPos] End%-if isempty ( RedLinePnts) tempNode= [selectedPos (1) ClickPos (2)] TempVector1= [selectedPos (2) + 1]. * (clickPos (2) > selectedPos (2)) +. [clickPos (2), selectedPos (2)-1]. * (clickPos (2) selectedPos (1)) +. [clickPos (1) + 1 clickPos selected Pos (1)]. * (clickPos (1) POS (2)) +. [selectedPos (2), clickPos (2)-1]. * (selectedPos (2) clickPos (1)) +. [selectedPos (1) + 1 selectedPos (1)]. * (selectedPos (1) selectedPos (1)) + [ii,selectedPos (1)-1]. * (iiclickPos (1)) + [ii,clickPos (1)-1]. * (iiselectedPos (2)) + [jj,selectedPos (2)-1]. * (jjclickPos (2)) + [jj,clickPos (2)-1].

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report