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 make Monopoly Mini Game

2025-03-01 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 make Monopoly Mini Game". In daily operation, I believe many people have doubts about how to use Matlab to make Monopoly 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 make Monopoly Mini Game". Next, please follow the editor to study!

Everyone has played Monopoly, go to the location of the building can buy land, the second lap to the bought land can be upgraded, others need to pay tolls after passing, each time after the starting point will get a certain amount of capital, the game in the end is not bankrupt is the winner, here I use MATLAB to make a MATLAB version of Monopoly Mini Game:

1. Custom avatar and name

Click the plus sign in the box to change the avatar, and click on the text area to change the nickname:

Of course, even if you do not change the avatar and click start, the avatar and name will be assigned automatically:

two。 Buy land, charge, go bankrupt

You can buy land when you pass for the first time:

B: purchase price, T: toll, the last digit is the real estate grade.

If you walk through again, you can upgrade:

Others are required to pay a toll when they walk past a property that has been purchased:

When a player is in debt, the asset is emptied and the debt is shown to exit the game:

3. Partial code display

Main files a total of 10 m files, of which monopoly_main.m is the function entry, run the program to start the game! :

The monopoly.mlappinstall file is the APP installation package. Click the install APP button below and select the file to install it in the APP column:

It is worth mentioning that the avatar preset of this program is also drawn with MATLAB:

Part of the code shows:

Gui_init.mfunction [monFig,monAx,diceAx,diceTool,selfTool,monMenuS] = gui_initmonFig=uifigure;monFig.Position= [10 50 1000]; monFig.NumberTitle='off';monFig.MenuBar='none';monFig.Resize='off';monFig.Name='monopoly';monAx=uiaxes (monFig); monAx.PlotBoxAspectRatio= [1 1]; monAx.Position= [380 10 600 600];% monAx.Box='on';monAx.XLim= [0 100]; monAx.YLim= [0 100];% monAx.Color= [0.9] MonAx.XColor= [0.95]; monAx.YColor= [0.95]; monAx.Toolbar.Visible='off';selfPl=uipanel (monFig); selfPl.Title='';selfPl.Position= [10 10 370 600]; diceAx=uiaxes (selfPl); diceAx.Position= [0 450 145]; diceAx.XLim= [0 10]; diceAx.YLim= [0 10]; diceAx.Color= [0.98 0.98]; diceAx.XColor= [0.95]; diceAx.YColor= [0.95] DiceAx.Toolbar.Visible='off' Hold (diceAx,'on') plot (diceAx, [2Power8], [1pj1]) plot (diceAx, [2lc8], [9], 'plot (diceAx, [1jue 1], [2Mei8],' plot (diceAx, [9], [2j8]) plot (diceAx,8+cos (0 + (0:pi/ (2): pi/2)) 8+sin (0 + (0:pi/ (2x10): pi/2)), plot (diceAx,2+cos (0:pi/ (2x10): pi/2), 8+sin (pi/2+ (0:pi/ (2x10): pi/2)) plot (diceAx,2+cos (0:pi/ (2y10): pi/2), 2+sin (pi+ (0:pi/ (2x10): pi/2)) 2) plot (diceAx,8+cos (- pi/2+ (0:pi/ (2k10): pi/2)), 2+sin (- pi/2+ (0:pi/ (2p10): pi/2)), 'KJV (diceAx,'off') diceTool.Btn=uibutton (monFig) DiceTool.Btn.Text=' roll dice'; diceTool.Btn.BackgroundColor= [0.31 0.58 0.80]; diceTool.Btn.FontColor= [11]; diceTool.Btn.FontWeight='bold';diceTool.Btn.Position= [180 480 180 40]; diceTool.Btn.FontSize=18;diceTool.Lbl1=uilabel (monFig); diceTool.Lbl1.Text=' remaining players:'; diceTool.Lbl1.FontSize=18;diceTool.Lbl1.FontColor= [185 184 150]. / 500 position tool. DiceTool.Lbl2=uilabel (monFig); diceTool.Lbl2.Text=' current round:'; diceTool.Lbl2.FontSize=18;diceTool.Lbl2.FontColor= [185184 150]. / 500 leading diceTool.Lbl2.FontWeightWeightWeightWeightWeightWeightWeightWeightWeightWeightWeightWeightWeightWeightWeightWeightWeightWeightFormula, for (I); for Img = uiimage (monFig); selfTool. (['player',num2str (I)]). Img.Position= [30 400-(iMel 1) * 11060] SelfTool. (['player',num2str (I)]) .Img.ImageSource=' picture\ player0.png'; selfTool. ([' player',num2str (I)]) .Img.UserData = I; selfTool. (['player',num2str (I)]) .Ta = uitextarea (monFig); selfTool. ([' player',num2str (I)]). Ta.Position= [100402-(iMusi) * 1107023] SelfTool. (['player',num2str (I)]) .Ta.Value=' Please enter the nickname'; selfTool. (['player',num2str (I)]) .Ta.UserData = I; selfTool. ([' player',num2str (I)]) .Ta2 = uitextarea (monFig); selfTool. (['player',num2str (I)]). Ta2.Position= [180 433-(I player',num2str 1) * 110 180 25]; selfTool. ([' player',num2str (I)]) .Ta2.Value ='' SelfTool. (['player',num2str (I)]). Ta2.Enable='off'; selfTool. ([' player',num2str (I)]) .Btn = uibutton (monFig); selfTool. (['player',num2str (I)]). Btn.Position= [100435-(iMuth1) * 1107023]; selfTool. ([' player',num2str (I)]. Btn.Text=' purchase property' SelfTool. (['player',num2str (I)]). Btn.BackgroundColor= [0.31 0.58 0.80]; selfTool. ([' player',num2str (I)]). Btn.FontColor= [111]; selfTool. (['player',num2str (I)]). Btn.FontWeight='bold'; selfTool. ([' player',num2str (I)]) .Btn.UserData = I; selfTool. (['player',num2str (I)]) .lb = uilistbox (monFig) SelfTool. (['player',num2str (I)]). Lb.Position= [180355-(iMuth1) * 11018078]; selfTool. ([' player',num2str (I)]) .Lb.Items = {'real estate one (empty)', 'real estate two (empty)', 'real estate three (empty)','. .'}; selfTool. (['player',num2str (I)]) .Txt = uilabel (monFig); selfTool. ([' player',num2str (I)]). Txt.Position= [30 370-(I player',num2str 1) * 110 140 30]; selfTool. (['player',num2str (I)]. Txt.Text=' funds: 0'; selfTool. (['player',num2str (I)]). Txt.FontColor= [185150]. / 500 SelfTool. (['player',num2str (I)]). Txt.FontWeight='bold'; selfTool. ([' player',num2str (I)]). Txt.FontSize=14;endmonMenu=uimenu (monFig); monMenu.Text=' start the game'; monMenuS.m2=uimenu (monMenu); monMenuS.m2.Text=' duo'; monMenuS.m3=uimenu (monMenu); monMenuS.m3.Text=' trio'; monMenuS.m4=uimenu (monMenu); monMenuS.m4.Text=' four' Endself_init.mfunction self=self_init (n) for item1 self 4 self. (['player',num2str (I)]) .property = 5000; self. ([' player',num2str (I)]) .pos = 0; self. (['player',num2str (I)]). Real_estate= {}; self. ([' player',num2str (I)]) .estateNum = 0; if I > n self. (['player',num2str (I)]). Else self. (['player',num2str (I)]) .gameover = 0; end self. ([' player',num2str (I)]). Name= ['player', num2str (I)]; endend4. Modify record

1. On the problem that the size of the matrix does not match when you have purchased multiple real estate and upgraded a real estate.

Solution: owenerPos=owenerList (:, 2) = = n near line 113of the monopoly_main function

Change to: owenerPos=owenerList (:, 1) = = self. (['player',num2str (n)]) .pos

two。 It is pointed out by netizens [do not know what to call] that if the version is 2021a, the uiaxes will automatically display below the uipanel so that the dice cannot be displayed. The change is to change the parent class of the uiaxes from uifigure to uipanel, and change the Position attribute to display it in the appropriate location. The detailed changes are as follows:

Place the code near lines 20-25 of the gui_init.m file:

SelfPl=uipanel (monFig); selfPl.Title='';selfPl.Position= [10 10 370600]; diceAx=uiaxes (monFig); diceAx.Position= [15460145145]

Change to:

SelfPl=uipanel (monFig); selfPl.Title='';selfPl.Position= [10 10 370 600]; diceAx=uiaxes (selfPl); diceAx.Position= [0 450 145]

3. It is pointed out by netizens [m0room57054690] that the problem of random numbers generated by the program for the first time after packaging can be added to the program with random number seeds changing according to time. This part of the code is as follows:

TempTime=clock (); second=round (tempTime (6) + 60*tempTime (5) + 24*60*tempTime (4)); rng (second) diceNum=randi (6). At this point, the study on "how to use Matlab to make Monopoly Mini Game" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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