-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhit.m
41 lines (39 loc) · 1.18 KB
/
hit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function hit(app)
if (app.player1turn == 1)
app.numCardsDealt = app.numCardsDealt + 1;
app.Label.Text = num2str(str2double(app.Label.Text) + str2double(app.shuffledCards{app.numCardsDealt,2}));
%updates label value for Player 1 score
score1 = str2double(app.Label.Text);
if score1<21
app.player1turn = 1;
elseif score1 == 21
app.player1turn=0;
%fprintf("Blackjack!")
elseif score1>21
app.player1turn = 0;
% Enable player 2's buttons if player 1 busts
app.HitButton_2.Enable = 'on';
app.StandButton_2.Enable = 'on';
else
app.ErrorLabel.Visible = 'on';
end
end
if (app.player2turn == 1)
app.numCardsDealt = app.numCardsDealt + 1;
app.Label_2.Text = num2str(str2double(app.Label_2.Text) + str2double(app.shuffledCards{app.numCardsDealt,2}));
%updates player 2 score
score2 = str2num(app.Label_2.Text);
if score2<21
app.player2turn = 1;
elseif score2==21
app.player2turn=0;
dealerPlay(app)
%fprintf("Blackjack!")
elseif score2>21
app.player2turn = 0;
dealerPlay(app)
else
app.ErrorLabel.Visible = 'on';
end
end
end