Code covered by the BSD License  

Highlights from
Cribbage Suite

image thumbnail
from Cribbage Suite by Bryan
Cribbage Suite is a GUI interface designed to help teach and play the game of cribbage.

choose6.m
%choose6.m
%choose6 is a GUI that allows you to input what 6 cards you were dealt.
%Then, by clicking on the "CHOOSE 4" button, the best combination of four
%cards will be chosen.


D = figure; %Open a new figure window.
set(D,...
    'Menubar','none',...
    'NumberTitle','off',...
    'Name','Choose 6 Cards',...
    'Position',[580   545   360   235]);

%% Panel for choosing your cards
Dpanel1 = uipanel(...
    'Parent',D,...
    'Position',[0 0 0.5 1],...
    'Title','Choose your 6 cards');
faces = {'A' '2' '3' '4' '5' '6' '7' '8' '9' '10' 'J' 'Q' 'K'};
suits = {'clubs' 'diamonds' 'hearts' 'spades'};
gap1 = 25; %This is the gap between button rows...figured i'd save some time this way.
xSize1 = 40; %Width of faces list
ySize1 = 15; %Height of faces list
xSize2 = 70; %Width of suits list
ySize2 = 15; %Height of suits list
margin1 = 5; %Distance from left edge of 1st column button to the left edge of the panel.
margin2 = margin1 + xSize1 + 5; %Distance for second button (suits)

Dtext1 = uicontrol(...
    'Style','text',...
    'Position',[5 8*gap1 170 15],...
    'String','What 6 cards were you dealt?',...
    'Parent',Dpanel1,...
    'FontWeight','bold',...
    'HorizontalAlignment','left');

DchooseFace1 = uicontrol(...
    'Style','popupmenu',...
    'String',faces,...
    'Parent',Dpanel1,...
    'Position',[margin1 7*gap1 xSize1 ySize1]);
DchooseSuit1 = uicontrol(...
    'Style','popupmenu',...
    'String',suits,...
    'Parent',Dpanel1,...
    'Position',[margin2 7*gap1 xSize2 ySize2]);

DchooseFace2 = uicontrol(...
    'Style','popupmenu',...
    'String',faces,...
    'Parent',Dpanel1,...
    'Position',[margin1 6*gap1 xSize1 ySize1]);
DchooseSuit2 = uicontrol(...
    'Style','popupmenu',...
    'String',suits,...
    'Parent',Dpanel1,...
    'Position',[margin2 6*gap1 xSize2 ySize2]);

DchooseFace3 = uicontrol(...
    'Style','popupmenu',...
    'String',faces,...
    'Parent',Dpanel1,...
    'Position',[margin1 5*gap1 xSize1 ySize1]);
DchooseSuit3 = uicontrol(...
    'Style','popupmenu',...
    'String',suits,...
    'Parent',Dpanel1,...
    'Position',[margin2 5*gap1 xSize2 ySize2]);

DchooseFace4 = uicontrol(...
    'Style','popupmenu',...
    'String',faces,...
    'Parent',Dpanel1,...
    'Position',[margin1 4*gap1 xSize1 ySize1]);
DchooseSuit4 = uicontrol(...
    'Style','popupmenu',...
    'String',suits,...
    'Parent',Dpanel1,...
    'Position',[margin2 4*gap1 xSize2 ySize2]);

DchooseFace5 = uicontrol(...
    'Style','popupmenu',...
    'String',faces,...
    'Parent',Dpanel1,...
    'Position',[margin1 3*gap1 xSize1 ySize1]);
DchooseSuit5 = uicontrol(...
    'Style','popupmenu',...
    'String',suits,...
    'Parent',Dpanel1,...
    'Position',[margin2 3*gap1 xSize2 ySize2]);

DchooseFace6 = uicontrol(...
    'Style','popupmenu',...
    'String',faces,...
    'Parent',Dpanel1,...
    'Position',[margin1 2*gap1 xSize1 ySize1]);
DchooseSuit6 = uicontrol(...
    'Style','popupmenu',...
    'String',suits,...
    'Parent',Dpanel1,...
    'Position',[margin2 2*gap1 xSize2 ySize2]);

Dtext2 = uicontrol(...
    'Style','text',...
    'Parent',Dpanel1,...
    'String','Click CHOOSE 4 to calculate!',...
    'HorizontalAlignment','left',...
    'Position',[5 gap1 160 15],...
    'FontWeight','bold');

Dcalc = uicontrol(...
    'Style','pushbutton',...
    'String','CHOOSE 4',...
    'Position',[100 3 70 20],...
    'Callback','choose6Callback',...
    'Parent',Dpanel1);

%% RIGHT PANEL: OUTPUT
%Initially, the right half of the GUI is blank; after the cards have been
%inputted, the answer is "revealed" on the right side.

Dpanel2 = uipanel(...
    'Parent',D,...
    'Position',[0.5 0 0.5 1],...
    'Title','Output');
Dans1 = uicontrol(...
    'Style','text',...
    'Parent',Dpanel2,...
    'Position',[5 6*gap1 150 15],...
    'Visible','off');
Dans2 = uicontrol(...
    'Style','text',...
    'Parent',Dpanel2,...
    'Position',[5 5*gap1 150 15],...
    'Visible','off');
Dans3 = uicontrol(...
    'Style','text',...
    'Parent',Dpanel2,...
    'Position',[5 4*gap1 150 15],...
    'Visible','off');
Dans4 = uicontrol(...
    'Style','text',...
    'Parent',Dpanel2,...
    'Position',[5 3*gap1 150 15],...
    'Visible','off');
Dtext3 = uicontrol(...
    'Style','text',...
    'Parent',Dpanel2,...
    'Position',[5 2*gap1 150 15],...
    'Visible','off');

Contact us at files@mathworks.com