function poker(action)
% GUI version of classic video poker game
if nargin == 0
action = 'create';
end
%#########################################
if strcmp(action,'create')
poke;
for x = 1:5
set(findobj('tag',['pokr_hold',num2str(x)]),'BackgroundColor',[0.7 0.7 0]);
set(findobj('tag',['pokr_card',num2str(x)]),'BackgroundColor',[0.8 0.4 0.4]);
end
set(findobj('tag','pokr_bt'),'Userdata',[0.8 0.4 0.4]); % Store card bkgd color
set(findobj('tag','pokr_balance'),'String','100');
set(findobj('tag','pokr_bet'),'String','10');
end
%#########################################
if isempty(findobj('tag','pokr')) % if program is closed down while running
return;
end
%#########################################
if strcmp(action,'quit')
close(findobj('tag','pokr')); % Close down the GUI if EXIT button clicked
close all;
return;
end
%#########################################
if strcmp(action,'start_over')
for x = 1:5
set(findobj('tag',['pokr_hold',num2str(x)]),'BackgroundColor',[0.7 0.7 0]);
set(findobj('tag',['pokr_card',num2str(x)]),'BackgroundColor',[0.8 0.4 0.4]);
set(findobj('tag',['pokr_card',num2str(x)]),'String','');
end
set(findobj('tag','pokr_balance'),'String','100');
set(findobj('tag','pokr_bet'),'String','10');
set(findobj('tag','pokr_deal'),'Userdata','1');
set(findobj('tag','pokr_result'),'String','Game Result Appears Here');
end
%#########################################
if strcmp(action,'deal')
% randomly select five cards from 52 possibilities
cardnum = [];
suit = {};
value = {};
numvalue = {};
if get(findobj('tag','pokr_deal'),'Userdata') == '1'
for b = 1:5
cardnum{b} = rand(1);
if cardnum{b} > .9808
suit{b} = 'Spades';
value{b} = 'Ace';
numvalue{b} = 14;
elseif cardnum{b} > .9616
suit{b} = 'Spades';
value{b} = 'King';
numvalue{b} = 13;
elseif cardnum{b} > .9424
suit{b} = 'Spades';
value{b} = 'Queen';
numvalue{b} = 12;
elseif cardnum{b} > .9232
suit{b} = 'Spades';
value{b} = 'Jack';
numvalue{b} = 11;
elseif cardnum{b} > .9040
suit{b} = 'Spades';
value{b} = 'Ten';
numvalue{b} = 10;
elseif cardnum{b} > .8848
suit{b} = 'Spades';
value{b} = 'Nine';
numvalue{b} = 9;
elseif cardnum{b} > .8656
suit{b} = 'Spades';
value{b} = 'Eight';
numvalue{b} = 8;
elseif cardnum{b} > .8464
suit{b} = 'Spades';
value{b} = 'Seven';
numvalue{b} = 7;
elseif cardnum{b} > .8272
suit{b} = 'Spades';
value{b} = 'Six';
numvalue{b} = 6;
elseif cardnum{b} > .8080
suit{b} = 'Spades';
value{b} = 'Five';
numvalue{b} = 5;
elseif cardnum{b} > .7888
suit{b} = 'Spades';
value{b} = 'Four';
numvalue{b} = 4;
elseif cardnum{b} > .7696
suit{b} = 'Spades';
value{b} = 'Three';
numvalue{b} = 3;
elseif cardnum{b} > .7504
suit{b} = 'Spades';
value{b} = 'Two';
numvalue{b} = 2;
elseif cardnum{b} > .7308
suit{b} = 'Hearts';
value{b} = 'Ace';
numvalue{b} = 14;
elseif cardnum{b} > .7116
suit{b} = 'Hearts';
value{b} = 'King';
numvalue{b} = 13;
elseif cardnum{b} > .6924
suit{b} = 'Hearts';
value{b} = 'Queen';
numvalue{b} = 12;
elseif cardnum{b} > .6732
suit{b} = 'Hearts';
value{b} = 'Jack';
numvalue{b} = 11;
elseif cardnum{b} > .6540
suit{b} = 'Hearts';
value{b} = 'Ten';
numvalue{b} = 10;
elseif cardnum{b} > .6348
suit{b} = 'Hearts';
value{b} = 'Nine';
numvalue{b} = 9;
elseif cardnum{b} > .6156
suit{b} = 'Hearts';
value{b} = 'Eight';
numvalue{b} = 8;
elseif cardnum{b} > .5964
suit{b} = 'Hearts';
value{b} = 'Seven';
numvalue{b} = 7;
elseif cardnum{b} > .5772
suit{b} = 'Hearts';
value{b} = 'Six';
numvalue{b} = 6;
elseif cardnum{b} > .5580
suit{b} = 'Hearts';
value{b} = 'Five';
numvalue{b} = 5;
elseif cardnum{b} > .5388
suit{b} = 'Hearts';
value{b} = 'Four';
numvalue{b} = 4;
elseif cardnum{b} > .5196
suit{b} = 'Hearts';
value{b} = 'Three';
numvalue{b} = 3;
elseif cardnum{b} > .5004
suit{b} = 'Hearts';
value{b} = 'Two';
numvalue{b} = 2;
elseif cardnum{b} > .4812
suit{b} = 'Clubs';
value{b} = 'Ace';
numvalue{b} = 14;
elseif cardnum{b} > .4620
suit{b} = 'Clubs';
value{b} = 'King';
numvalue{b} = 13;
elseif cardnum{b} > .4428
suit{b} = 'Clubs';
value{b} = 'Queen';
numvalue{b} = 12;
elseif cardnum{b} > .4236
suit{b} = 'Clubs';
value{b} = 'Jack';
numvalue{b} = 11;
elseif cardnum{b} > .4044
suit{b} = 'Clubs';
value{b} = 'Ten';
numvalue{b} = 10;
elseif cardnum{b} > .3852
suit{b} = 'Clubs';
value{b} = 'Nine';
numvalue{b} = 9;
elseif cardnum{b} > .3660
suit{b} = 'Clubs';
value{b} = 'Eight';
numvalue{b} = 8;
elseif cardnum{b} > .3468
suit{b} = 'Clubs';
value{b} = 'Seven';
numvalue{b} = 7;
elseif cardnum{b} > .3276
suit{b} = 'Clubs';
value{b} = 'Six';
numvalue{b} = 6;
elseif cardnum{b} > .3084
suit{b} = 'Clubs';
value{b} = 'Five';
numvalue{b} = 5;
elseif cardnum{b} > .2892
suit{b} = 'Clubs';
value{b} = 'Four';
numvalue{b} = 4;
elseif cardnum{b} > .2700
suit{b} = 'Clubs';
value{b} = 'Three';
numvalue{b} = 3;
elseif cardnum{b} > .2508
suit{b} = 'Clubs';
value{b} = 'Two';
numvalue{b} = 2;
elseif cardnum{b} > .2316
suit{b} = 'Diamonds';
value{b} = 'Ace';
numvalue{b} = 14;
elseif cardnum{b} > .2124
suit{b} = 'Diamonds';
value{b} = 'King';
numvalue{b} = 13;
elseif cardnum{b} > .1932
suit{b} = 'Diamonds';
value{b} = 'Queen';
numvalue{b} = 12;
elseif cardnum{b} > .1740
suit{b} = 'Diamonds';
value{b} = 'Jack';
numvalue{b} = 11;
elseif cardnum{b} > .1548
suit{b} = 'Diamonds';
value{b} = 'Ten';
numvalue{b} = 10;
elseif cardnum{b} > .1356
suit{b} = 'Diamonds';
value{b} = 'Nine';
numvalue{b} = 9;
elseif cardnum{b} > .1164
suit{b} = 'Diamonds';
value{b} = 'Eight';
numvalue{b} = 8;
elseif cardnum{b} > .0972
suit{b} = 'Diamonds';
value{b} = 'Seven';
numvalue{b} = 7;
elseif cardnum{b} > .0780
suit{b} = 'Diamonds';
value{b} = 'Six';
numvalue{b} = 6;
elseif cardnum{b} > .0588
suit{b} = 'Diamonds';
value{b} = 'Five';
numvalue{b} = 5;
elseif cardnum{b} > .0396
suit{b} = 'Diamonds';
value{b} = 'Four';
numvalue{b} = 4;
elseif cardnum{b} > .0204
suit{b} = 'Diamonds';
value{b} = 'Three';
numvalue{b} = 3;
else
suit{b} = 'Diamonds';
value{b} = 'Two';
numvalue{b} = 2;
end
% Deal out all five cards
set(findobj('tag',['pokr_card',num2str(b)]),'BackgroundColor',[1 1 1]);
set(findobj('tag',['pokr_hold',num2str(b)]),'BackgroundColor',[0.7 0.7 0]);
if numvalue{b} > 10
if strcmp(suit{b},'Diamonds') == 1
set(findobj('tag',['pokr_card',num2str(b)]),'String',{value{b} '' 'of' '' suit{b} '' ' /\ ' ' / \ ' ' / \ ' ' \ / ' ' \ / ' ' \/ '});
set(findobj('tag',['pokr_card',num2str(b)]),'ForegroundColor',[1 0 0]);
elseif strcmp(suit{b},'Hearts') == 1
set(findobj('tag',['pokr_card',num2str(b)]),'String',{value{b} '' 'of' '' suit{b} '' ' ~~ ~~ ' ' ( \/ ) ' ' \ / ' ' \ / ' ' \/ '});
set(findobj('tag',['pokr_card',num2str(b)]),'ForegroundColor',[1 0 0]);
elseif strcmp(suit{b},'Clubs') == 1
set(findobj('tag'
MATLAB: What section is program and what section is GUI
help
Best Answer