Vous êtes sur la page 1sur 4

functionvarargout=Rock_paper_scissors_GUI(varargin)

%ROCK_PAPER_SCISSORS_GUIMATLABcodeforRock_paper_scissors_GUI.fig
%ROCK_PAPER_SCISSORS_GUI,byitself,createsanewROCK_PAPER_SCISSORS_GUI
orraisestheexisting
%singleton*.
%
%H=ROCK_PAPER_SCISSORS_GUIreturnsthehandletoanew
ROCK_PAPER_SCISSORS_GUIorthehandleto
%theexistingsingleton*.
%
%ROCK_PAPER_SCISSORS_GUI('CALLBACK',hObject,eventData,handles,...)calls
thelocal
%functionnamedCALLBACKinROCK_PAPER_SCISSORS_GUI.Mwiththegiveninput
arguments.
%
%ROCK_PAPER_SCISSORS_GUI('Property','Value',...)createsanew
ROCK_PAPER_SCISSORS_GUIorraisesthe
%existingsingleton*.Startingfromtheleft,propertyvaluepairsare
%appliedtotheGUIbeforeRock_paper_scissors_GUI_OpeningFcngetscalled.
An
%unrecognizedpropertynameorinvalidvaluemakespropertyapplication
%stop.AllinputsarepassedtoRock_paper_scissors_GUI_OpeningFcnvia
varargin.
%
%*SeeGUIOptionsonGUIDE'sToolsmenu.Choose"GUIallowsonlyone
%instancetorun(singleton)".
%
%Seealso:GUIDE,GUIDATA,GUIHANDLES
%EdittheabovetexttomodifytheresponsetohelpRock_paper_scissors_GUI
%LastModifiedbyGUIDEv2.515Aug201421:44:45
%BegininitializationcodeDONOTEDIT
gui_Singleton=1;
gui_State=struct('gui_Name',mfilename,...
'gui_Singleton',gui_Singleton,...
'gui_OpeningFcn',@Rock_paper_scissors_GUI_OpeningFcn,...
'gui_OutputFcn',@Rock_paper_scissors_GUI_OutputFcn,...
'gui_LayoutFcn',[],...
'gui_Callback',[]);
ifnargin&&ischar(varargin{1})
gui_State.gui_Callback=str2func(varargin{1});
end
ifnargout
[varargout{1:nargout}]=gui_mainfcn(gui_State,varargin{:});
else
gui_mainfcn(gui_State,varargin{:});
end
%EndinitializationcodeDONOTEDIT

%ExecutesjustbeforeRock_paper_scissors_GUIismadevisible.
functionRock_paper_scissors_GUI_OpeningFcn(hObject,eventdata,handles,
varargin)
%Thisfunctionhasnooutputargs,seeOutputFcn.
%hObjecthandletofigure
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%varargincommandlineargumentstoRock_paper_scissors_GUI(seeVARARGIN)
%ChoosedefaultcommandlineoutputforRock_paper_scissors_GUI
handles.output=hObject;
%Updatehandlesstructure
guidata(hObject,handles);
%UIWAITmakesRock_paper_scissors_GUIwaitforuserresponse(seeUIRESUME)
%uiwait(handles.ComputerChoice);

%Outputsfromthisfunctionarereturnedtothecommandline.
functionvarargout=Rock_paper_scissors_GUI_OutputFcn(hObject,eventdata,
handles)
%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);
%hObjecthandletofigure
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
%Getdefaultcommandlineoutputfromhandlesstructure
varargout{1}=handles.output;
functionrandom_rps=rps()
%Thisprogramwillgeneraterandomnumbersandplacethemincertain
%meaningrepresentation
r=rand(1,1)*99;
ifr>=0&&r<=33
random_rps=1;
elseifr>33&&r<=66
random_rps=2;
else
random_rps=3;
end
functionuser_vs_computer=play(user_choice,random_rps)
game=10*user_choice+random_rps;

%{
user
loose:12,23,31
tie:11,22,33
win:13,21,32
%}
switchgame
case{12,23,31}
user_vs_computer=0;
case{13,21,32}
user_vs_computer=1;
otherwise
user_vs_computer=2;
end
functiondisplayResults(user_choice,handles)
game_opt={'Rock','Paper','Sissors'};
result_opt={'loose','win','tie'};

random_rps=rps();
user_vs_computer=play(user_choice,random_rps);

set(handles.txtComputerChoice,'String',game_opt{random_rps});
set(handles.txtgame,'String',result_opt{user_vs_computer+1});

%Executesonbuttonpressinbtnrock.
functionbtnrock_Callback(hObject,eventdata,handles)
%hObjecthandletobtnrock(seeGCBO)
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
user_choice=1;
displayResults(user_choice,handles);
%Executesonbuttonpressinbtnpaper.
functionbtnpaper_Callback(hObject,eventdata,handles)
%hObjecthandletobtnpaper(seeGCBO)
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
user_choice=2;
displayResults(user_choice,handles);

%Executesonbuttonpressinbtnscissors.
functionbtnscissors_Callback(hObject,eventdata,handles)
%hObjecthandletobtnscissors(seeGCBO)
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
user_choice=3;
displayResults(user_choice,handles);
%Executesonbuttonpressinbtnclear.
functionbtnclear_Callback(hObject,eventdata,handles)
%hObjecthandletobtnclear(seeGCBO)
%eventdatareservedtobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
set(handles.txtComputerChoice,'String','');
set(handles.txtgame,'String','');

Vous aimerez peut-être aussi