function varargout = xo(varargin)
% XO M-file for xo.fig
% XO, by itself, creates a new XO or raises the existing
% singleton*.
%
% H = XO returns the handle to a new XO or the handle to
% the existing singleton*.
%
% XO('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in XO.M with the given input arguments.
%
% XO('Property','Value',...) creates a new XO or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before xo_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to xo_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help xo
% Last Modified by GUIDE v2.5 22-Nov-2007 10:28:15
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @xo_OpeningFcn, ...
'gui_OutputFcn', @xo_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 xo is made visible.
function xo_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 xo (see VARARGIN)
% Choose default command line output for xo
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
global b
b=0;
global oplayer
oplayer=0;
global xplayer;
xplayer=0;
% UIWAIT makes xo wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = xo_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
varargout{1} = handles.output;
% --- 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)
global b;
global oplayer;
global xplayer;
if isempty(get(handles.p1,'string'))
if b==1
set(handles.p1,'string','O')
if (strcmp(get(handles.p1,'string'),get(handles.p2,'string')) && strcmp(get(handles.p1,'string'),get(handles.p3,'string')))||...
(strcmp(get(handles.p1,'string'),get(handles.p4,'string')) && strcmp(get(handles.p1,'string'),get(handles.p7,'string')))||...
(strcmp(get(handles.p1,'string'),get(handles.p5,'string')) && strcmp(get(handles.p1,'string'),get(handles.p9,'string')))
oplayer=oplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player O won')
end
end
if b==2
set(handles.p1,'string','X')
if (strcmp(get(handles.p1,'string'),get(handles.p2,'string')) && strcmp(get(handles.p1,'string'),get(handles.p3,'string')))||...
(strcmp(get(handles.p1,'string'),get(handles.p4,'string')) && strcmp(get(handles.p1,'string'),get(handles.p7,'string')))||...
(strcmp(get(handles.p1,'string'),get(handles.p5,'string')) && strcmp(get(handles.p1,'string'),get(handles.p9,'string')))
xplayer=xplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player X won')
end
end
if b==1
b=2;
elseif b==2
b=1;
end
end
% --- 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)
global b
global oplayer
global xplayer
if isempty(get(handles.p2,'string'))
if b==1
set(handles.p2,'string','O')
if (strcmp(get(handles.p2,'string'),get(handles.p1,'string')) && strcmp(get(handles.p2,'string'),get(handles.p3,'string')))||...
(strcmp(get(handles.p2,'string'),get(handles.p5,'string')) && strcmp(get(handles.p2,'string'),get(handles.p8,'string')))
oplayer=oplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player O won')
end
end
if b==2
set(handles.p2,'string','X')
if (strcmp(get(handles.p2,'string'),get(handles.p1,'string')) && strcmp(get(handles.p2,'string'),get(handles.p3,'string')))||...
(strcmp(get(handles.p2,'string'),get(handles.p5,'string')) && strcmp(get(handles.p2,'string'),get(handles.p8,'string')))
xplayer=xplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player X won')
b=1;
end
end
if b==1
b=2;
elseif b==2
b=1;
end
end
% --- 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)
global b
global oplayer
global xplayer
if isempty(get(handles.p3,'string'))
if b==1
set(handles.p3,'string','O')
if (strcmp(get(handles.p3,'string'),get(handles.p2,'string')) && strcmp(get(handles.p3,'string'),get(handles.p1,'string')))||...
(strcmp(get(handles.p3,'string'),get(handles.p6,'string')) && strcmp(get(handles.p3,'string'),get(handles.p9,'string')))||...
(strcmp(get(handles.p3,'string'),get(handles.p5,'string')) && strcmp(get(handles.p3,'string'),get(handles.p7,'string')))
oplayer=oplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player O won')
end
end
if b==2
set(handles.p3,'string','X')
if (strcmp(get(handles.p3,'string'),get(handles.p2,'string')) && strcmp(get(handles.p3,'string'),get(handles.p1,'string')))||...
(strcmp(get(handles.p3,'string'),get(handles.p6,'string')) && strcmp(get(handles.p3,'string'),get(handles.p9,'string')))||...
(strcmp(get(handles.p3,'string'),get(handles.p5,'string')) && strcmp(get(handles.p3,'string'),get(handles.p7,'string')))
xplayer=xplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player X won')
end
end
if b==1
b=2;
elseif b==2
b=1;
end
end
% --- 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)
global b
global oplayer
global xplayer
if isempty(get(handles.p4,'string'))
if b==1
set(handles.p4,'string','O')
if (strcmp(get(handles.p4,'string'),get(handles.p1,'string')) && strcmp(get(handles.p4,'string'),get(handles.p7,'string')))||...
(strcmp(get(handles.p4,'string'),get(handles.p5,'string')) && strcmp(get(handles.p4,'string'),get(handles.p6,'string')))
oplayer=oplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player O won')
end
end
if b==2
set(handles.p4,'string','X')
if (strcmp(get(handles.p4,'string'),get(handles.p1,'string')) && strcmp(get(handles.p4,'string'),get(handles.p7,'string')))||...
(strcmp(get(handles.p4,'string'),get(handles.p5,'string')) && strcmp(get(handles.p4,'string'),get(handles.p6,'string')))
xplayer=xplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player X won')
end
end
if b==1
b=2;
elseif b==2
b=1;
end
end
% --- 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)
global b
global oplayer
global xplayer
if isempty(get(handles.p5,'string'))
if b==1
set(handles.p5,'string','O')
if (strcmp(get(handles.p5,'string'),get(handles.p4,'string')) && strcmp(get(handles.p5,'string'),get(handles.p6,'string')))||...
(strcmp(get(handles.p5,'string'),get(handles.p2,'string')) && strcmp(get(handles.p5,'string'),get(handles.p8,'string')))||...
(strcmp(get(handles.p5,'string'),get(handles.p1,'string')) && strcmp(get(handles.p5,'string'),get(handles.p9,'string')))||...
(strcmp(get(handles.p5,'string'),get(handles.p3,'string')) && strcmp(get(handles.p5,'string'),get(handles.p7,'string')))
oplayer=oplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player O won')
end
end
if b==2
set(handles.p5,'string','X')
if (strcmp(get(handles.p5,'string'),get(handles.p4,'string')) && strcmp(get(handles.p5,'string'),get(handles.p6,'string')))||...
(strcmp(get(handles.p5,'string'),get(handles.p2,'string')) && strcmp(get(handles.p5,'string'),get(handles.p8,'string')))||...
(strcmp(get(handles.p5,'string'),get(handles.p1,'string')) && strcmp(get(handles.p5,'string'),get(handles.p9,'string')))||...
(strcmp(get(handles.p5,'string'),get(handles.p3,'string')) && strcmp(get(handles.p5,'string'),get(handles.p7,'string')))
xplayer=xplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player X won')
end
end
if b==1
b=2;
elseif b==2
b=1;
end
end
% --- 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)
global b
global oplayer
global xplayer
if isempty(get(handles.p6,'string'))
if b==1
set(handles.p6,'string','O')
if (strcmp(get(handles.p6,'string'),get(handles.p5,'string')) && strcmp(get(handles.p6,'string'),get(handles.p4,'string')))||...
(strcmp(get(handles.p6,'string'),get(handles.p3,'string')) && strcmp(get(handles.p6,'string'),get(handles.p9,'string')))
oplayer=oplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player O won')
end
end
if b==2
set(handles.p6,'string','X')
if (strcmp(get(handles.p6,'string'),get(handles.p5,'string')) && strcmp(get(handles.p6,'string'),get(handles.p4,'string')))||...
(strcmp(get(handles.p6,'string'),get(handles.p3,'string')) && strcmp(get(handles.p6,'string'),get(handles.p9,'string')))
xplayer=xplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player X won')
end
end
if b==1
b=2;
elseif b==2
b=1;
end
end
% --- 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)
global b
global oplayer
global xplayer
if isempty(get(handles.p7,'string'))
if b==1
set(handles.p7,'string','O')
if (strcmp(get(handles.p7,'string'),get(handles.p4,'string')) && strcmp(get(handles.p7,'string'),get(handles.p1,'string')))||...
(strcmp(get(handles.p7,'string'),get(handles.p8,'string')) && strcmp(get(handles.p7,'string'),get(handles.p9,'string')))||...
(strcmp(get(handles.p7,'string'),get(handles.p5,'string')) && strcmp(get(handles.p7,'string'),get(handles.p3,'string')))
oplayer=oplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player O won')
end
end
if b==2
set(handles.p7,'string','X')
if (strcmp(get(handles.p7,'string'),get(handles.p4,'string')) && strcmp(get(handles.p7,'string'),get(handles.p1,'string')))||...
(strcmp(get(handles.p7,'string'),get(handles.p8,'string')) && strcmp(get(handles.p7,'string'),get(handles.p9,'string')))||...
(strcmp(get(handles.p7,'string'),get(handles.p5,'string')) && strcmp(get(handles.p7,'string'),get(handles.p3,'string')))
xplayer=xplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player X won')
end
end
if b==1
b=2;
elseif b==2
b=1;
end
end
% --- 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)
global b
global oplayer
global xplayer
if isempty(get(handles.p8,'string'))
if b==1
set(handles.p8,'string','O')
if (strcmp(get(handles.p8,'string'),get(handles.p7,'string')) && strcmp(get(handles.p8,'string'),get(handles.p9,'string')))||...
(strcmp(get(handles.p8,'string'),get(handles.p5,'string')) && strcmp(get(handles.p8,'string'),get(handles.p2,'string')))
oplayer=oplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player O won')
end
end
if b==2
set(handles.p8,'string','X')
if (strcmp(get(handles.p8,'string'),get(handles.p7,'string')) && strcmp(get(handles.p8,'string'),get(handles.p9,'string')))||...
(strcmp(get(handles.p8,'string'),get(handles.p5,'string')) && strcmp(get(handles.p8,'string'),get(handles.p2,'string')))
msgbox('player X won')
end
end
if b==1
b=2;
elseif b==2
b=1;
end
end
% --- 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)
global b
global oplayer
global xplayer
if isempty(get(handles.p9,'string'))
if b==1
set(handles.p9,'string','O')
if (strcmp(get(handles.p9,'string'),get(handles.p8,'string')) && strcmp(get(handles.p9,'string'),get(handles.p7,'string')))||...
(strcmp(get(handles.p9,'string'),get(handles.p6,'string')) && strcmp(get(handles.p9,'string'),get(handles.p3,'string')))||...
(strcmp(get(handles.p9,'string'),get(handles.p5,'string')) && strcmp(get(handles.p9,'string'),get(handles.p1,'string')))
oplayer=oplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player O won')
end
end
if b==2
set(handles.p9,'string','X')
if (strcmp(get(handles.p9,'string'),get(handles.p8,'string')) && strcmp(get(handles.p9,'string'),get(handles.p7,'string')))||...
(strcmp(get(handles.p9,'string'),get(handles.p6,'string')) && strcmp(get(handles.p9,'string'),get(handles.p3,'string')))||...
(strcmp(get(handles.p9,'string'),get(handles.p5,'string')) && strcmp(get(handles.p9,'string'),get(handles.p1,'string')))
xplayer=xplayer+1;
set(handles.edit1,'string',oplayer);
set(handles.edit2,'string',xplayer);
msgbox('player X won')
end
end
if b==1
b=2;
elseif b==2
b=1;
end
end
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.p1,'string','')
set(handles.p2,'string','')
set(handles.p3,'string','')
set(handles.p4,'string','')
set(handles.p5,'string','')
set(handles.p6,'string','')
set(handles.p7,'string','')
set(handles.p8,'string','')
set(handles.p9,'string','')
% --- Executes on button press in rs.
function rs_Callback(hObject, eventdata, handles)
% hObject handle to rs (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global b
global oplayer
oplayer=0;
global xplayer;
xplayer=0;
b=0;
set(handles.edit2,'string',oplayer);
set(handles.edit1,'string',xplayer);
set(handles.pu1,'visible','on');
set(handles.pu2,'visible','on');
set(handles.text4,'visible','on');
set(handles.p1,'string','')
set(handles.p2,'string','')
set(handles.p3,'string','')
set(handles.p4,'string','')
set(handles.p5,'string','')
set(handles.p6,'string','')
set(handles.p7,'string','')
set(handles.p8,'string','')
set(handles.p9,'string','')
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in pu1.
function pu1_Callback(hObject, eventdata, handles)
% hObject handle to pu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global b
b=1;
set(handles.pu1,'visible','off');
set(handles.pu2,'visible','off');
set(handles.text4,'visible','off');
set(handles.p1,'string','')
set(handles.p2,'string','')
set(handles.p3,'string','')
set(handles.p4,'string','')
set(handles.p5,'string','')
set(handles.p6,'string','')
set(handles.p7,'string','')
set(handles.p8,'string','')
set(handles.p9,'string','')
% --- Executes on button press in pu2.
function pu2_Callback(hObject, eventdata, handles)
% hObject handle to pu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global b
b=2;
set(handles.pu1,'visible','off');
set(handles.pu2,'visible','off');
set(handles.text4,'visible','off');
set(handles.p1,'string','')
set(handles.p2,'string','')
set(handles.p3,'string','')
set(handles.p4,'string','')
set(handles.p5,'string','')
set(handles.p6,'string','')
set(handles.p7,'string','')
set(handles.p8,'string','')
set(handles.p9,'string','')