function varargout = WarGui(varargin)
% WARGUI MATLAB code for WarGui.fig
% WARGUI, by itself, creates a new WARGUI or raises the existing
% singleton*.
%
% H = WARGUI returns the handle to a new WARGUI or the handle to
% the existing singleton*.
%
% WARGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in WARGUI.M with the given input arguments.
%
% WARGUI('Property','Value',...) creates a new WARGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before WarGui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to WarGui_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 WarGui
% Last Modified by GUIDE v2.5 01-May-2013 16:40:33
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @WarGui_OpeningFcn, ...
'gui_OutputFcn', @WarGui_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 WarGui is made visible.
function WarGui_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 WarGui (see VARARGIN)
% Choose default command line output for WarGui
handles.output = hObject;
%sets the Default Images
global back
back=imread('cards/back','jpg');
imshow(back,'Parent',handles.p2deck);
imshow(back,'Parent',handles.p1deck);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes WarGui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = WarGui_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 turnButton.
function turnButton_Callback(hObject, eventdata, handles)
% hObject handle to turnButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global table
%calls the play turn methos, and updates the cards
playTurn(table)
card=getPic(table,0);
p2card=imread(card,'jpg');
card=getPic(table,1);
p1card=imread(card,'jpg');
imshow(p1card,'Parent',handles.p1Battle)
imshow(p2card,'Parent',handles.p2Battle)
%checks for a game over condition.
%changes the buttons if war must be declared.
if gameOver(table)
finishGame(table)
set(handles.p1Score,'String',getPlayerScore(table,1))
set(handles.p2Score,'String',getPlayerScore(table,2))
else
set(handles.turnButton,'visible','off')
set(handles.warButton,'visible','on')
end
% --- Executes on button press in warButton.
function warButton_Callback(hObject, eventdata, handles)
% hObject handle to warButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global table
global back
set(handles.warButton,'visible','off')%warButton made not visible to avoid player clicking more than once
pause on
%declares war with pauses to mimic the actual game.
%updates with the pauses.
declareWar(table)
pause(1)
imshow(back,'Parent',handles.p2war1);
imshow(back,'Parent',handles.p1war1);
pause(1)
imshow(back,'Parent',handles.p2war2);
imshow(back,'Parent',handles.p1war2);
pause(1)
imshow(back,'Parent',handles.p2war3);
imshow(back,'Parent',handles.p1war3);
pause(1)
%the actual fighting cards are placed face up.
card=getPic(table,0);
p2card=imread(card,'jpg');
card=getPic(table,1);
p1card=imread(card,'jpg');
imshow(p1card,'Parent',handles.p1Battle)
imshow(p2card,'Parent',handles.p2Battle)
pause(1)
%checks the game over.
if gameOver(table)
finishGame(table)
set(handles.p1Score,'String',getPlayerScore(table,1))
set(handles.p2Score,'String',getPlayerScore(table,2))
%shows the cards in the war
card=imread(getPic(table,2),'jpg');
imshow(card,'Parent',handles.p2war1);
card=imread(getPic(table,4),'jpg');
imshow(card,'Parent',handles.p2war2);
card=imread(getPic(table,6),'jpg');
imshow(card,'Parent',handles.p2war3);
card=imread(getPic(table,3),'jpg');
imshow(card,'Parent',handles.p1war1);
card=imread(getPic(table,5),'jpg');
imshow(card,'Parent',handles.p1war2);
card=imread(getPic(table,7),'jpg');
imshow(card,'Parent',handles.p1war3);
pause(2)
cla(handles.p1war1)
cla(handles.p1war2)
cla(handles.p1war3)
cla(handles.p2war1)
cla(handles.p2war2)
cla(handles.p2war3)
%gets ready for regular play
set(handles.turnButton,'visible','on')
else%if there needs to be a second war.
set(handles.warButton,'visible','on')
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 table
set(handles.Start,'visible','off')
set(handles.turnButton,'visible','on')
table=playTable;
set(handles.p1Score,'String',getPlayerScore(table,1))
set(handles.p2Score,'String',getPlayerScore(table,2))