Advertisement
Guest User

MatLab Gui

a guest
May 1st, 2013
2,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 6.37 KB | None | 0 0
  1. function varargout = WarGui(varargin)
  2. % WARGUI MATLAB code for WarGui.fig
  3. %      WARGUI, by itself, creates a new WARGUI or raises the existing
  4. %      singleton*.
  5. %
  6. %      H = WARGUI returns the handle to a new WARGUI or the handle to
  7. %      the existing singleton*.
  8. %
  9. %      WARGUI('CALLBACK',hObject,eventData,handles,...) calls the local
  10. %      function named CALLBACK in WARGUI.M with the given input arguments.
  11. %
  12. %      WARGUI('Property','Value',...) creates a new WARGUI or raises the
  13. %      existing singleton*.  Starting from the left, property value pairs are
  14. %      applied to the GUI before WarGui_OpeningFcn gets called.  An
  15. %      unrecognized property name or invalid value makes property application
  16. %      stop.  All inputs are passed to WarGui_OpeningFcn via varargin.
  17. %
  18. %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  19. %      instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES
  22.  
  23. % Edit the above text to modify the response to help WarGui
  24.  
  25. % Last Modified by GUIDE v2.5 01-May-2013 16:40:33
  26.  
  27. % Begin initialization code - DO NOT EDIT
  28. gui_Singleton = 1;
  29. gui_State = struct('gui_Name',       mfilename, ...
  30.                    'gui_Singleton',  gui_Singleton, ...
  31.                    'gui_OpeningFcn', @WarGui_OpeningFcn, ...
  32.                    'gui_OutputFcn',  @WarGui_OutputFcn, ...
  33.                    'gui_LayoutFcn',  [] , ...
  34.                    'gui_Callback',   []);
  35. if nargin && ischar(varargin{1})
  36.     gui_State.gui_Callback = str2func(varargin{1});
  37. end
  38.  
  39. if nargout
  40.     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  41. else
  42.     gui_mainfcn(gui_State, varargin{:});
  43. end
  44. % End initialization code - DO NOT EDIT
  45.  
  46.  
  47. % --- Executes just before WarGui is made visible.
  48. function WarGui_OpeningFcn(hObject, eventdata, handles, varargin)
  49. % This function has no output args, see OutputFcn.
  50. % hObject    handle to figure
  51. % eventdata  reserved - to be defined in a future version of MATLAB
  52. % handles    structure with handles and user data (see GUIDATA)
  53. % varargin   command line arguments to WarGui (see VARARGIN)
  54.  
  55. % Choose default command line output for WarGui
  56. handles.output = hObject;
  57. %sets the Default Images
  58. global back
  59. back=imread('cards/back','jpg');
  60. imshow(back,'Parent',handles.p2deck);
  61. imshow(back,'Parent',handles.p1deck);
  62.  
  63. % Update handles structure
  64. guidata(hObject, handles);
  65.  
  66. % UIWAIT makes WarGui wait for user response (see UIRESUME)
  67. % uiwait(handles.figure1);
  68.  
  69.  
  70. % --- Outputs from this function are returned to the command line.
  71. function varargout = WarGui_OutputFcn(hObject, eventdata, handles)
  72. % varargout  cell array for returning output args (see VARARGOUT);
  73. % hObject    handle to figure
  74. % eventdata  reserved - to be defined in a future version of MATLAB
  75. % handles    structure with handles and user data (see GUIDATA)
  76.  
  77. % Get default command line output from handles structure
  78. varargout{1} = handles.output;
  79.  
  80.  
  81. % --- Executes on button press in turnButton.
  82. function turnButton_Callback(hObject, eventdata, handles)
  83. % hObject    handle to turnButton (see GCBO)
  84. % eventdata  reserved - to be defined in a future version of MATLAB
  85. % handles    structure with handles and user data (see GUIDATA)
  86. global table
  87. %calls the play turn methos, and updates the cards
  88. playTurn(table)
  89. card=getPic(table,0);
  90. p2card=imread(card,'jpg');
  91. card=getPic(table,1);
  92. p1card=imread(card,'jpg');
  93. imshow(p1card,'Parent',handles.p1Battle)
  94. imshow(p2card,'Parent',handles.p2Battle)
  95. %checks for a game over condition.
  96. %changes the buttons if war must be declared.
  97. if gameOver(table)
  98.     finishGame(table)
  99.     set(handles.p1Score,'String',getPlayerScore(table,1))
  100.     set(handles.p2Score,'String',getPlayerScore(table,2))
  101. else
  102.    set(handles.turnButton,'visible','off')
  103.    set(handles.warButton,'visible','on')
  104. end
  105.  
  106.  
  107.  
  108. % --- Executes on button press in warButton.
  109. function warButton_Callback(hObject, eventdata, handles)
  110. % hObject    handle to warButton (see GCBO)
  111. % eventdata  reserved - to be defined in a future version of MATLAB
  112. % handles    structure with handles and user data (see GUIDATA)
  113. global table
  114. global back
  115. set(handles.warButton,'visible','off')%warButton made not visible to avoid player clicking more than once
  116. pause on
  117. %declares war with pauses to mimic the actual game.
  118. %updates with the pauses.
  119. declareWar(table)
  120.  
  121. pause(1)
  122. imshow(back,'Parent',handles.p2war1);
  123. imshow(back,'Parent',handles.p1war1);
  124.  
  125. pause(1)
  126. imshow(back,'Parent',handles.p2war2);
  127. imshow(back,'Parent',handles.p1war2);
  128.  
  129. pause(1)
  130. imshow(back,'Parent',handles.p2war3);
  131. imshow(back,'Parent',handles.p1war3);
  132. pause(1)
  133. %the actual fighting cards are placed face up.
  134.  
  135. card=getPic(table,0);
  136. p2card=imread(card,'jpg');
  137. card=getPic(table,1);
  138. p1card=imread(card,'jpg');
  139. imshow(p1card,'Parent',handles.p1Battle)
  140. imshow(p2card,'Parent',handles.p2Battle)
  141. pause(1)
  142. %checks the game over.
  143. if gameOver(table)
  144.     finishGame(table)    
  145.     set(handles.p1Score,'String',getPlayerScore(table,1))
  146.     set(handles.p2Score,'String',getPlayerScore(table,2))
  147.     %shows the cards in the war
  148.     card=imread(getPic(table,2),'jpg');
  149.     imshow(card,'Parent',handles.p2war1);
  150.     card=imread(getPic(table,4),'jpg');
  151.     imshow(card,'Parent',handles.p2war2);
  152.     card=imread(getPic(table,6),'jpg');
  153.     imshow(card,'Parent',handles.p2war3);
  154.    
  155.     card=imread(getPic(table,3),'jpg');
  156.     imshow(card,'Parent',handles.p1war1);
  157.     card=imread(getPic(table,5),'jpg');
  158.     imshow(card,'Parent',handles.p1war2);
  159.     card=imread(getPic(table,7),'jpg');
  160.     imshow(card,'Parent',handles.p1war3);
  161.     pause(2)
  162.  
  163.     cla(handles.p1war1)
  164.     cla(handles.p1war2)
  165.     cla(handles.p1war3)
  166.     cla(handles.p2war1)
  167.     cla(handles.p2war2)
  168.     cla(handles.p2war3)
  169.     %gets ready for regular play
  170.     set(handles.turnButton,'visible','on')
  171. else%if there needs to be a second war.
  172.    set(handles.warButton,'visible','on')
  173. end
  174.    
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185. % --- Executes on button press in Start.
  186. function Start_Callback(hObject, eventdata, handles)
  187. % hObject    handle to Start (see GCBO)
  188. % eventdata  reserved - to be defined in a future version of MATLAB
  189. % handles    structure with handles and user data (see GUIDATA)
  190. global table
  191. set(handles.Start,'visible','off')
  192. set(handles.turnButton,'visible','on')
  193. table=playTable;
  194. set(handles.p1Score,'String',getPlayerScore(table,1))
  195. set(handles.p2Score,'String',getPlayerScore(table,2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement