[MATLAB] GUI design a small game

foreword

I made an interactive game for my coursework, and I found it very interesting, so I posted an article to record and share it.


The result display:

How to play the cat game, click and touch the cat:
Please add a picture description

This means that the game continues, click again to touch the cat.
If such a picture appears, it means that you are eaten by the cat and the game fails.
Please add a picture description


GUI interface operation

Please add a picture descriptionFirst of all, if you only want to touch cats, then one coordinate area and one button will do
. The coordinate area is used to specify where cats and cats appear
Please add a picture description.

Then the next step
Right button -> View callback -> CreateFcn
Enter the following code in the function section of the button

num=unidrnd(2);%产生12随机数
if num==1
   image=imread('popcat2.png');
elseif num==2
   image=imread('popcat3.png');
end
 imshow(image);

For random number function usage, refer to this blog:
https://blog.csdn.net/ywx1832990/article/details/78724812?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165563480016782391873504%252 2%252C%2522scm%2522%253A %252220140713.130102334…%2522%257D&request_id=165563480016782391873504&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2 all sobaiduend ~ default-2-787 24812-null-null.142 v17 pc_search_result_control_group,157 v15 new_3&utm_term=matlab%E9%9A% 8F%E6%9C%BA%E6%95%B0&spm=1018.2226.3001.4187


Summarize:

Due to the watermark problem, I won’t post the picture
. You can find
the code by searching pop cats on the Internet. The code is very simple. It is to randomly output the set pictures through the generation of random numbers, and see how long cats can like you. Of course, it can also be Your paper man husband or wife (fog). In order to achieve the effect of the game (although it is for self-entertainment).
Maybe this is the romance of coders?

Guess you like

Origin blog.csdn.net/Wuyeyu2001/article/details/125360408