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.

choose4.m
%choose4.m
%choose4 is a GUI that lets you input what four cards you've chosen and the
%starter card, and then scores the hand for you.

B = figure; %Open a new figure window.
set(B,...
    'Menubar','none',...
    'NumberTitle','off',...
    'Name','Choose 4 Cards',...
    'Position',[413   480   160   300]);

%% Panel for choosing your cards
faces = {'A' '2' '3' '4' '5' '6' '7' '8' '9' '10' 'J' 'Q' 'K'};
suits = {'clubs' 'diamonds' 'hearts' 'spades'};

%For this GUI, I created a clever way of designing it. During the design of
%a GUI, it's always a pain when you realize that you want to add or remove
%a button from the list. By creating variables to describe the position of
%uicontrol objects, the process of making this GUI was very fast.

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)

%Now it's on to creating the buttons. They are all very similar.
Btext0 = uicontrol(...
    'Style','text',...
    'Position',[5 11*gap1 150 15],...
    'String', 'Whose hand is this?',...
    'Parent',B,...
    'Fontweight','bold',...
    'BackgroundColor',[0.8 0.8 0.8],...
    'HorizontalAlignment','left');
Bplayer = uicontrol(...
    'Style','popupmenu',...
    'Position',[5 10*gap1 150 15],...
    'String', {get(player1,'name') get(player2,'name')});

Bcrib = uicontrol(...
    'Style','checkbox',...
    'Position',[5 9*gap1 150 15],...
    'String','Crib?',...
    'Parent',B,...
    'Fontweight','bold',...
    'BackgroundColor', [ .8 .8 .8],...
    'HorizontalAlignment','left');

Btext1 = uicontrol(...
    'Style','text',...
    'Position',[5 8*gap1 150 15],...
    'String','What is your hand?',...
    'Parent',B,...
    'FontWeight','bold',...
    'BackgroundColor',[0.8 0.8 0.8],...
    'HorizontalAlignment','left');

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

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

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

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

Btext2 = uicontrol(...
    'Style','text',...
    'Parent',B,...
    'String','What is the starter card?',...
    'Position',[margin1 2.7*gap1 150 15],...
    'BackgroundColor',[0.8 0.8 0.8],...
    'FontWeight','bold',...
    'HorizontalAlignment','left');

BchooseStarterFace = uicontrol(...
    'Style','popupmenu',...
    'String',faces,...
    'Parent',B,...
    'Position',[margin1 2*gap1 xSize1 ySize1]);
BchooseStarterSuit = uicontrol(...
    'Style','popupmenu',...
    'String',suits,...
    'Parent',B,...
    'Position',[margin2 2*gap1 xSize2 ySize2]);
Btext3 = uicontrol(...
    'Style','text',...
    'Parent',B,...
    'String','Click SCORE to calculate!',...
    'HorizontalAlignment','left',...
    'Position',[5 gap1 160 15],...
    'FontWeight','bold',...
    'BackgroundColor',[.8 .8 .8]);

Bcalc = uicontrol(...
    'Style','text',...
    'String','click SCORE',...
    'Position',[5 5 100 15],...
    'Parent',B);

Bscore = uicontrol(...
    'Style','pushbutton',...
    'String','SCORE',...
    'Position',[110 3 50 20],...
    'BackgroundColor',[0.8 0.8 0.8],...
    'Callback','choose4Callback');

Contact us at files@mathworks.com