⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staker.m

📁 MATLAB实现的3D炮兵小游戏
💻 M
📖 第 1 页 / 共 5 页
字号:

            case 'CURRENT',

              isBuying = false;
              value = get(hCurrent,'Value');
              bombList = get(hCurrent,'String');
              bombName = strtrim(strtok(bombList{value},'-'));
              bombIndex = find(strcmp({BOMB_DATA.name},bombName));
              bombText = {[bombName,':'],...
                          ['   ',BOMB_DATA(bombIndex).description]};
              set(hDescription,'String',textwrap(hDescription,bombText));
              price = (BOMB_DATA(bombIndex).cost)/2;
              set([hPrice hTotal],'String',num2money(price));
              value = customer.arsenal(bombIndex);
              if isfinite(value),
                set(hMultiplier,'Max',value,'String','1','Value',1);
                if (value > 1),
                  set([hMultiplier hUp],'Enable','on');
                else
                  set([hMultiplier hUp],'Enable','off');
                end
                set(hDown,'Enable','off');
                set(hBuyOrSell,'Enable','on','String','Sell');
              else
                set(hMultiplier,'Enable','off','String','1');
                set([hUp hDown],'Enable','off');
                set(hBuyOrSell,'Enable','off','String','Sell');
              end
              drawnow;

            case 'DOWN',

              value = get(hMultiplier,'Value')-1;
              set(hMultiplier,'String',num2str(value),'Value',value);
              set(hUp,'Enable','on');
              if (value == 1),
                set(hDown,'Enable','off');
              end
              set(hTotal,'String',num2money(value*price));
              drawnow;

            case {'EXIT','STAKER_SHOP'},

              save(customer.file,'-struct','customer','-mat');
              delete(hModal);
              drawnow;

            case 'HELP',

              display_help(hModal);

            case 'MULTIPLIER',

              value = str2double(get(hMultiplier,'String'));
              if isnan(value),
                value = get(hMultiplier,'Value');
                bomb_error(hModal,'invalidValue','multiplier');
              else
                maxValue = get(hMultiplier,'Max');
                value = max(min(round(value),maxValue),1);
                if (value == maxValue),
                  set(hUp,'Enable','off');
                end
                if (value == 1),
                  set(hDown,'Enable','off');
                end
              end
              set(hMultiplier,'String',num2str(value),'Value',value);
              set(hTotal,'String',num2money(value*price));
              drawnow;

            case 'UP',

              value = get(hMultiplier,'Value')+1;
              set(hMultiplier,'String',num2str(value),'Value',value);
              if (value == get(hMultiplier,'Max')),
                set(hUp,'Enable','off');
              end
              set(hDown,'Enable','on');
              set(hTotal,'String',num2money(value*price));
              drawnow;

          end

        end

      end

    end

    %----------------------------------------------------------------------
    function edit_preferences
    %
    %   Opens a modal window for editing preferences.
    %
    %----------------------------------------------------------------------

      % Initialize variables:

      oldPreferences = status.preferences;
      newPreferences = oldPreferences;

      % Create modal figure window:

      position = get(hMain,'Position');
      position = [position(1:2)+(position(3:4)-[450 445])./2 450 445];
      hModal = make_figure(position,'CloseRequestFcn',@callback_edit,...
                           'Name','Preferences',...
                           'Tag','STAKER_PREFERENCES',...
                           'WindowStyle','modal');

      % Create font preferences panel:

      make_panel(hModal,[1 361 450 85]);
      make_text(hModal,[11 421 100 15],'String','Font:');
      make_text(hModal,[11 401 130 15],'HorizontalAlignment','right',...
                'String','Font name =');
      hFontName = make_edit(hModal,[151 401 130 20],...
                            'Callback',@callback_edit,'String',fontName,...
                            'Tag','FONT_NAME');
      make_text(hModal,[11 371 130 15],'HorizontalAlignment','right',...
                'String','Font size =');
      hFontSize = make_edit(hModal,[151 371 50 20],...
                            'Callback',@callback_edit,...
                            'String',num2str(fontSize),'Tag','FONT_SIZE');
      make_text(hModal,[301 406 130 15],'String','sample:');
      hFont = make_text(hModal,[301 371 130 30],'FontWeight','normal',...
                        'String','Can you read this?');

      % Create color preferences panel:

      make_panel(hModal,[1 186 450 175]);
      make_text(hModal,[11 336 100 15],'String','Colors:');
      make_text(hModal,[11 316 130 15],'HorizontalAlignment','right',...
                'String','Text color =');
      hTextColor = make_edit(hModal,[151 316 130 20],...
                             'Callback',@callback_edit,...
                             'String',mat2str(textColor,2),...
                             'Tag','COLOR','UserData','textColor');
      make_text(hModal,[11 286 130 15],'HorizontalAlignment','right',...
                'String','Background color =');
      hBackColor = make_edit(hModal,[151 286 130 20],...
                             'Callback',@callback_edit,...
                             'String',mat2str(backColor,2),...
                             'Tag','COLOR','UserData','backColor');
      make_text(hModal,[11 256 130 15],'HorizontalAlignment','right',...
                'String','Panel color =');
      hPanelColor = make_edit(hModal,[151 256 130 20],...
                              'Callback',@callback_edit,...
                              'String',mat2str(panelColor,2),...
                              'Tag','COLOR','UserData','panelColor');
      make_text(hModal,[11 226 130 15],'HorizontalAlignment','right',...
                'String','Accent color =');
      hAccentColor = make_edit(hModal,[151 226 130 20],...
                               'Callback',@callback_edit,...
                               'String',mat2str(accentColor,2),...
                               'Tag','COLOR','UserData','accentColor');
      make_text(hModal,[11 196 130 15],'HorizontalAlignment','right',...
                'String','Slider color =');
      hSliderColor = make_edit(hModal,[151 196 130 20],...
                               'Callback',@callback_edit,...
                               'String',mat2str(sliderColor,2),...
                               'Tag','COLOR','UserData','sliderColor');
      make_text(hModal,[301 316 130 15],'String','sample:');
      hPanel = make_panel(hModal,[296 216 140 100]);
      hAccent = make_panel(hModal,[311 251 110 50],...
                           'BackgroundColor',accentColor);
      hText = make_text(hModal,[321 261 90 30],...
                        'BackgroundColor',backColor,...
                        'FontWeight','normal','String','Your text here');
      hSlider = make_slider(hModal,[306 226 120 10],'Max',10,...
                            'SliderStep',[0.1 0.3]);

      % Create camera preferences panel:

      make_panel(hModal,[1 101 450 85]);
      make_text(hModal,[11 161 100 15],'String','Camera:');
      make_text(hModal,[11 141 160 15],'HorizontalAlignment','right',...
                'String','Azimuth gain =');
      hAzimuth = make_edit(hModal,[181 141 60 20],...
                           'Callback',@callback_edit,...
                           'String',num2str(azimuthGain,'%0.4f'),...
                           'Tag','NUMERIC',...
                           'UserData',{'azimuthGain',0.0005,0.01});
      make_text(hModal,[11 111 160 15],'HorizontalAlignment','right',...
                'String','Elevation gain =');
      hElevation = make_edit(hModal,[181 111 60 20],...
                             'Callback',@callback_edit,...
                             'String',num2str(elevationGain,'%0.4f'),...
                             'Tag','NUMERIC',...
                             'UserData',{'elevationGain',0.0005,0.01});
      make_text(hModal,[251 141 120 15],'HorizontalAlignment','right',...
                'String','Rotation gain =');
      hRotation = make_edit(hModal,[381 141 60 20],...
                            'Callback',@callback_edit,...
                            'String',num2str(rotationGain,'%0.4f'),...
                            'Tag','NUMERIC',...
                            'UserData',{'rotationGain',0.0001,0.005});
      make_text(hModal,[251 111 120 15],'HorizontalAlignment','right',...
                'String','Zoom gain =');
      hZoom = make_edit(hModal,[381 111 60 20],...
                        'Callback',@callback_edit,...
                        'String',num2str(zoomGain,'%0.4f'),...
                        'Tag','NUMERIC',...
                        'UserData',{'zoomGain',0.001,0.01});

      % Create animation preferences panel:

      make_panel(hModal,[1 46 450 55]);
      make_text(hModal,[11 76 100 15],'String','Animation:');
      make_text(hModal,[11 56 160 15],'HorizontalAlignment','right',...
                'String','Trajectory step =');
      hTrajectory = make_edit(hModal,[181 56 60 20],...
                              'Callback',@callback_edit,...
                              'String',num2str(trajectoryStep,'%0.4f'),...
                              'Tag','NUMERIC',...
                              'UserData',{'trajectoryStep',0.001,2});
      make_text(hModal,[251 56 120 15],'HorizontalAlignment','right',...
                'String','Blast step =');
      hBlastStep = make_edit(hModal,[381 56 60 20],...
                             'Callback',@callback_edit,...
                             'String',num2str(blastStep,'%0.4f'),...
                             'Tag','NUMERIC',...
                             'UserData',{'blastStep',0.05,0.5});

      % Create button panel:

      make_panel(hModal,[1 1 450 45]);
      make_button(hModal,[11 11 50 25],'Callback',@callback_edit,...
                  'String','Help','Tag','HELP');
      make_button(hModal,[301 11 80 25],'Callback',@callback_edit,...
                  'String','Defaults','Tag','DEFAULTS');
      make_button(hModal,[391 11 50 25],'Callback',@callback_edit,...
                  'String','Done','Tag','DONE');

      % Wait for window to be closed:

      set(hModal,'Visible','on');
      drawnow;
      waitfor(hModal);

      %--------------------------------------------------------------------
      function callback_edit(source,event)
      %
      %   Callback function for preference editing uicontrols.
      %
      %--------------------------------------------------------------------

        switch get(source,'Tag'),

          case 'COLOR',

            value = str2rgb(get(source,'String'));
            fieldName = get(source,'UserData');
            switch fieldName,
              case 'textColor',
                sourceObject = {hText,'ForegroundColor'};
                sourceText = 'text color';
              case 'backColor',
                sourceObject = {hText,'BackgroundColor'};
                sourceText = 'background color';
              case 'panelColor',
                sourceObject = {hPanel,'BackgroundColor'};
                sourceText = 'panel color';
              case 'accentColor',
                sourceObject = {hAccent,'BackgroundColor'};
                sourceText = 'accent color';
              case 'sliderColor',
                sourceObject = {hSlider,'BackgroundColor'};
                sourceText = 'slider color';
            end
            if isnan(value),
              set(source,'String',mat2str(newPreferences.(fieldName),2));
              bomb_error(hModal,'invalidValue',sourceText);
            else
              set(source,'String',mat2str(value,2));
              set(sourceObject{:},value);
              newPreferences.(fieldName) = value;
              drawnow;
            end

          case 'DEFAULTS',

            newPreferences = default_preferences;
            set(hFontName,'String',newPreferences.fontName);
            set(hFontSize,'String',num2str(newPreferences.fontSize));
            set(hFont,'FontName',newPreferences.fontName,...
                'FontSize',newPreferences.fontSize);
            set(hTextColor,'String',mat2str(newPreferences.textColor,2));
            set(hBackColor,'String',mat2str(newPreferences.backColor,2));
            set(hPanelColor,'String',mat2str(newPreferences.panelColor,2));
            set(hAccentColor,...
                'String',mat2str(newPreferences.accentColor,2));
            set(hSliderColor,...
                'String',mat2str(newPreferences.sliderColor,2));
            set(hPanel,'BackgroundColor',newPreferences.panelColor);
            set(hAccent,'BackgroundColor',newPreferences.accentColor);
            set(hText,'ForegroundColor',newPreferences.textColor,...
                'BackgroundColor',newPreferences.backColor);
            set(hSlider,'BackgroundColor',newPreferences.sliderColor);
            set(hAzimuth,...
                'String',num2str(newPreferences.azimuthGain,'%0.4f'));
            set(hElevation,...
                'String',num2str(newPreferences.elevationGain,'%0.4f'));
            set(hRotation,...
                'String',num2str(newPreferences.rotationGain,'%0.4f'));
            set(hZoom,'String',num2str(newPreferences.zoomGain,'%0.4f'));
            set(hTrajectory,...
                'String',num2str(newPreferences.trajectoryStep,'%0.4f'));
            set(hBlastStep,...
                'String',num2str(newPreferences.blastStep,'%0.4f'));

          case {'DONE','STAKER_PREFERENCES'},

            delete(hModal);
            if (~isequal(oldPreferences,newPreferences)),
              delete(hGame);
              hGame = [];
              delete(hMain);
              drawnow;
              fontName = newPreferences.fontName;
              fontSize = newPreferences.fontSize;
              textColor = newPreferences.textColor;
              backColor = newPreferences.backColor;
              panelColor = newPreferences.panelColor;
              accentColor = newPreferences.accentColor;
              sliderColor = newPreferences.sliderColor;
              azimuthGain = newPreferences.azimuthGain;
              elevationGain = newPreferences.elevationGain;
              rotationGain = newPreferences.rotationGain;
              zoomGain = newPreferences.zoomGain;
              useLocalTime = newPreferences.useLocalTime;
              trajectoryStep = newPreferences.trajectoryStep;
              blastStep = newPreferences.blastStep;
              status.preferences = newPreferences;
              save(STATUS_FILE,'-struct','status','-mat');
              initialize_main;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -