www.gusucode.com > 九宫图游戏源码程序 > 九宫图游戏源码程序/九宫图游戏/game.m
function varargout = game(varargin) % GAME MATLAB code for game.fig % GAME, by itself, creates a new GAME or raises the existing % singleton*. % % H = GAME returns the handle to a new GAME or the handle to % the existing singleton*. % % GAME('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GAME.M with the given input arguments. % % GAME('Property','Value',...) creates a new GAME or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before game_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to game_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help game % Last Modified by GUIDE v2.5 25-Mar-2014 11:07:34 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @game_OpeningFcn, ... 'gui_OutputFcn', @game_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before game is made visible. function game_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to game (see VARARGIN) % Choose default command line output for game handles.output = hObject; guidata(hObject, handles); % UIWAIT makes game wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = game_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure if ishandle(hObject) varargout{1} = handles.output; %close game; end % --- Executes on button press in exit. function exit_Callback(hObject, eventdata, handles) % hObject handle to exit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global stop stop=1; % --- Executes on key press with focus on figure1 or any of its controls. function figure1_WindowKeyPressFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata structure with the following fields (see FIGURE) % Key: name of the key that was pressed, in lower case % Character: character interpretation of the key(s) that was pressed % Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed % handles structure with handles and user data (see GUIDATA) global key key=eventdata.Key; % --- Executes on button press in reset. function reset_Callback(hObject, eventdata, handles) % hObject handle to reset (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global board board=reset_function(handles,board); % --- Executes on button press in p1. function p1_Callback(hObject, eventdata, handles) % hObject handle to p1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p2. function p2_Callback(hObject, eventdata, handles) % hObject handle to p2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p3. function p3_Callback(hObject, eventdata, handles) % hObject handle to p3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p4. function p4_Callback(hObject, eventdata, handles) % hObject handle to p4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p5. function p5_Callback(hObject, eventdata, handles) % hObject handle to p5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p6. function p6_Callback(hObject, eventdata, handles) % hObject handle to p6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p7. function p7_Callback(hObject, eventdata, handles) % hObject handle to p7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p8. function p8_Callback(hObject, eventdata, handles) % hObject handle to p8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p9. function p9_Callback(hObject, eventdata, handles) % hObject handle to p9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p11. function p11_Callback(hObject, eventdata, handles) % hObject handle to p11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p12. function p12_Callback(hObject, eventdata, handles) % hObject handle to p12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p13. function p13_Callback(hObject, eventdata, handles) % hObject handle to p13 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p14. function p14_Callback(hObject, eventdata, handles) % hObject handle to p14 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p15. function p15_Callback(hObject, eventdata, handles) % hObject handle to p15 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p16. function p16_Callback(hObject, eventdata, handles) % hObject handle to p16 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes when user attempts to close figure1. function figure1_CloseRequestFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: delete(hObject) closes the figure global stop stop=1; delete(hObject) % --- Executes on key press with focus on figure1 and none of its controls. function figure1_KeyPressFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata structure with the following fields (see FIGURE) % Key: name of the key that was pressed, in lower case % Character: character interpretation of the key(s) that was pressed % Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in p10. function p10_Callback(hObject, eventdata, handles) % hObject handle to p10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function rows_Callback(hObject, eventdata, handles) % hObject handle to rows (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of rows as text % str2double(get(hObject,'String')) returns contents of rows as a double % --- Executes during object creation, after setting all properties. function rows_CreateFcn(hObject, eventdata, handles) % hObject handle to rows (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function columns_Callback(hObject, eventdata, handles) % hObject handle to columns (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of columns as text % str2double(get(hObject,'String')) returns contents of columns as a double % --- Executes during object creation, after setting all properties. function columns_CreateFcn(hObject, eventdata, handles) % hObject handle to columns (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in start. function start_Callback(hObject, eventdata, handles) % hObject handle to start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global board stop key result points run; stop=0; key='carrow'; board=zeros(str2num(get(handles.rows,'String')),str2num(get(handles.columns,'String'))); endpoint=str2num(get(handles.endtile,'String')); points=0; result=0; run=0; set(handles.points,'Visible','on'); set(handles.result,'Visible','on'); set(handles.reset,'Visible','on'); set(handles.exit,'Visible','on'); set(handles.run,'Visible','on'); set(handles.rows,'Visible','off'); set(handles.rowslabel,'Visible','off'); set(handles.columns,'Visible','off'); set(handles.columnslabel,'Visible','off'); set(handles.start,'Visible','off'); set(handles.endtile,'Visible','off'); set(handles.endtilelabel,'Visible','off'); handles=create_board(handles,board); guidata(hObject, handles); board=reset_function(handles,board); guidata(hObject, handles); while stop==0 set(gcf,'Visible','on'); if run==1 moves=['u','l','r','d']; key=moves(randi([1 length(moves)])); end if (key(1)=='l' || key(1)=='r' || key(1)=='u' || key(1)=='d') && result==0 [board,result,points]=nextboard(board,key(1),points,endpoint); key='carrow'; plotboard(handles,board,result,points); drawnow; end end if ishandle(hObject) close game; end function endtile_Callback(hObject, eventdata, handles) % hObject handle to endtile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of endtile as text % str2double(get(hObject,'String')) returns contents of endtile as a double % --- Executes during object creation, after setting all properties. function endtile_CreateFcn(hObject, eventdata, handles) % hObject handle to endtile (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in run. function run_Callback(hObject, eventdata, handles) % hObject handle to run (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global run run=not(run);