1
00:00:05,360 --> 00:00:11,020
ok so moving on with our blackjack program I've made a bit of a typo on line 24 it should read

2
00:00:11,020 --> 00:00:17,950
embedded frame to hold the card images ok so moving on line 31 we are about

3
00:00:17,950 --> 00:00:24,460
to do the player card frame now so we will just
type a comment about that so....

4
00:00:24,460 --> 00:00:35,650
.....

5
00:00:37,500 --> 00:00:45,220
.......

6
00:00:46,500 --> 00:00:55,880
......

7
00:00:55,880 --> 00:01:02,550
...so hopefully
you're following along with a lot of

8
00:01:02,550 --> 00:01:06,090
this TKinter code now because we have
discussed a pretty well all of this in

9
00:01:06,090 --> 00:01:10,550
previous videos so I just a bit more of
a complex interface we've created before

10
00:01:10,550 --> 00:01:19,330
alright so next is the buttons so lets add a button frame so...

11
00:01:19,330 --> 00:01:43,280
.....

12
00:01:43,280 --> 00:01:52,680
......

13
00:01:52,680 --> 00:02:02,750
....

14
00:02:03,580 --> 00:02:10,330
......

15
00:02:10,330 --> 00:02:23,480
.....

16
00:02:24,730 --> 00:02:35,450
....so that's
the basic code done so the main windows

17
00:02:35,450 --> 00:02:39,640
got three widgets the label at the top
to display the result and two frames one

18
00:02:39,640 --> 00:02:42,280
below the other and I'll just bring up our
little

19
00:02:42,280 --> 00:02:47,620
image again ok so here it is on the
screen again what I'm talking so the moment

20
00:02:47,620 --> 00:02:52,220
as I said its got 3 widgets a label at
the top to display the result and it's

21
00:02:52,220 --> 00:02:56,580
also got two frames one below the other
the top most of the two frames is gonna

22
00:02:56,580 --> 00:03:00,320
contain the cards as you can see on the
screen there and as well as the scores for the

23
00:03:00,320 --> 00:03:04,990
dealer and player and the one below that
will hold the buttons as you can see right down the

24
00:03:04,990 --> 00:03:10,010
bottom the card frame itself contained
two other frames went one for the dealer

25
00:03:10,010 --> 00:03:14,050
and one for the player as well as the
labels to hold the name as well as the score

26
00:03:14,050 --> 00:03:18,950
so the card frame contains as I said another
two frames that will hold the cards and by

27
00:03:18,950 --> 00:03:22,760
putting the card images into separate
frames starting a new game is easier

28
00:03:22,760 --> 00:03:26,890
because we just have to destroy the
entire frame rather than trying to find

29
00:03:26,890 --> 00:03:31,780
out each of the card in it and destroy them
separately so this will make more sense

30
00:03:31,780 --> 00:03:37,110
when we come to do it so let's move onto
loading the card images so the file names of

31
00:03:37,110 --> 00:03:41,160
the individual images are quite well
formed and made up of the card's value

32
00:03:41,160 --> 00:03:44,550
when sweep followed by an underscore
so we can have a look at that we can

33
00:03:44,550 --> 00:03:47,770
go into here and have a look now

34
00:03:47,770 --> 00:03:51,890
so you can see that's the card number and underscore and then the sweep so

35
00:03:51,890 --> 00:03:56,000
it means that we can pragmatically load these
in pretty easily so for the cards from

36
00:03:56,000 --> 00:03:57,220
1 to 10

37
00:03:57,220 --> 00:04:00,570
we can actually load that with a simple
loop to load them all in

38
00:04:01,090 --> 00:04:04,110
now the face card images can be
retrieved using a second loop that runs

39
00:04:04,110 --> 00:04:08,380
through a list of names these ones down here jack king queen etc

40
00:04:08,380 --> 00:04:11,610
and by wrapping all that in
another loop that runs through the list

41
00:04:11,610 --> 00:04:16,079
of sweep names all 52 card images can be
loaded and this is something that the

42
00:04:16,079 --> 00:04:19,540
program will only have to do once but
I'm still going to create a function to

43
00:04:19,540 --> 00:04:23,780
do it by placing this code in its
own function the main program is going to be far

44
00:04:23,780 --> 00:04:28,190
less cluttered and more readable as a
result so let's go ahead and do that i'm

45
00:04:28,190 --> 00:04:33,310
gonna come up here and start on line 9 and
make bit of a space and put our

46
00:04:33,310 --> 00:04:40,140
function in their so we are going to call this load images so.....

47
00:04:40,140 --> 00:04:51,760
.....

48
00:04:51,760 --> 00:04:57,730
...because these will be ultimately be matching what's the what's
in the file name so....

49
00:04:57,730 --> 00:05:09,040
.....

50
00:05:15,240 --> 00:05:22,650
and remember earlier I mentioned about to
the TK version 8.6 is needed to use PNG

51
00:05:22,650 --> 00:05:31,720
files we're gonna put a test in here so...

52
00:05:31,720 --> 00:05:51,650
.....

53
00:05:51,650 --> 00:05:52,840
...so now we need to create our first loop so.....

54
00:05:52,840 --> 00:06:17,880
.....

55
00:06:18,970 --> 00:06:28,930
...remembering our range finishes one number

56
00:06:28,930 --> 00:06:38,490
earlier so we starting it at 1 11 and we put....which is the subfolder remembering that

57
00:06:38,490 --> 00:06:42,210
we add as sub folder to store the card files in or the came out of the

58
00:06:42,210 --> 00:06:46,600
zip file like that and were going to use.....

59
00:06:47,380 --> 00:07:20,340
.....

60
00:07:20,340 --> 00:07:21,420
......

61
00:07:21,420 --> 00:07:26,380
.....so that's going to be
the name that we need but now we need to retrieve it

62
00:07:26,380 --> 00:07:37,880
so do....and the name is the name

63
00:07:37,880 --> 00:07:44,230
that we've created on line 23 and then
we need to save it so....

64
00:07:44,230 --> 00:07:55,540
....and then finished off we've

65
00:07:55,540 --> 00:08:05,340
done that first bit of the loop we'll let hat loop finish and
then we do next the face cards......so from

66
00:08:05,340 --> 00:08:14,230
their we are going to put.....and you remember face cards on line 12 jack king and queen so we need to

67
00:08:14,230 --> 00:08:20,630
also get those so......and the same thing with

68
00:08:20,630 --> 00:08:30,350
the replacement field.......

69
00:08:30,350 --> 00:08:35,500
.....

70
00:08:37,280 --> 00:08:42,350
...so we got the right type off image
depending on the version of tkinter and

71
00:08:42,350 --> 00:08:51,980
then the same deal.....

72
00:08:51,980 --> 00:08:59,980
......

73
00:09:01,410 --> 00:09:04,610
.....

74
00:09:04,610 --> 00:09:11,170
..so we've now got our load images function written and
that should now be able to retrieve all

75
00:09:11,170 --> 00:09:15,490
those images we need for our game into
memory and just to note their that if you extracted

76
00:09:15,490 --> 00:09:19,440
the images to a different folder than what I
did make sure you do change this first

77
00:09:19,440 --> 00:09:23,390
part here cards / because that is going to be
looking at the current folder wherever that

78
00:09:23,390 --> 00:09:29,770
is for the sub folder called cards and whatever the name of the
file is so make sure you do change that if you

79
00:09:29,770 --> 00:09:34,610
put it in somewhere else so you need to
change both their on line 23 and also

80
00:09:34,610 --> 00:09:40,360
on line 29 so the card list should after this contain a
list of tuples each tuples storing

81
00:09:40,360 --> 00:09:45,500
the value and image each for one of the 52 cards
and the images have been loaded into

82
00:09:45,500 --> 00:09:49,960
Tkinter photo image objects which are
fairly basic but do allow images to be

83
00:09:49,960 --> 00:09:54,560
displayed easily that's what we need
to do here and what we're going to do is

84
00:09:54,560 --> 00:09:58,040
right on the bottom add some code to
just to test that this actually works s

85
00:09:58,040 --> 00:10:01,040
lets try doing so add some code so put....

86
00:10:02,910 --> 00:10:10,070
......

87
00:10:10,070 --> 00:10:18,040
...and will print cards to see what it actually happens and will just add our

88
00:10:18,040 --> 00:10:30,130
main loop so....and we got an error here so what have I done their I didn't put a colon their so

89
00:10:30,130 --> 00:10:36,050
put a colon and its pretty good and its complaining about 2 lines their so we'll add another line their to humour that so its

90
00:10:36,050 --> 00:10:47,610
actually happy and this other error is probably relating to tkinter camel case that probably want an extra space in their as well probably a good idea to fix those while we can you can't fix this

91
00:10:47,610 --> 00:10:51,860
first one up because that's got to do with
Python 2 so we'll leave that at that so

92
00:10:51,860 --> 00:10:56,060
if we run this now we should be able to get something it won't be very
exciting but we can at least demonstrate

93
00:10:56,060 --> 00:11:03,700
that things are actually working and if we tab over to our interface its obviously not working yet

94
00:11:03,700 --> 00:11:07,830
because we haven't added the cards
so close it down but we should be able to confirm

95
00:11:07,830 --> 00:11:12,500
that we got our various objects in here and
you can see this multiple objects that

96
00:11:12,500 --> 00:11:17,000
are the loaded so assuming it has work we'll just have to print out

97
00:11:17,000 --> 00:11:20,700
the cards or display them =to
confirm that they've been loaded but it

98
00:11:20,700 --> 00:11:26,200
seems to have loaded into the list
which is good so a new deck of cars can

99
00:11:26,200 --> 00:11:29,870
be created from the cards list now we imported them then we can shuffle them using

100
00:11:29,870 --> 00:11:33,520
the shuffle function from the
random module that we imported remember

101
00:11:33,520 --> 00:11:36,770
we did that in the previous video so the
program will also need to store the

102
00:11:36,770 --> 00:11:40,560
cards dealt to each player so before we
start creating the functions to make all

103
00:11:40,560 --> 00:11:41,520
of this work

104
00:11:41,520 --> 00:11:45,900
I'm going to initialize a dealer hand player hand list we might do that and might

105
00:11:45,900 --> 00:11:51,430
finish of this video and continue on to the next one so after here we can type.....

106
00:11:51,430 --> 00:12:04,920
.....

107
00:12:05,640 --> 00:12:15,390
....

108
00:12:15,390 --> 00:12:20,490
...its gonna sort of shuffle them in a random order which is
obviously what we want we don't our cards coming

109
00:12:20,490 --> 00:12:24,380
out in any sort of order the whole idea
is that we don't know what the next card is coming

110
00:12:24,380 --> 00:12:27,380
it's entirely random we want to create the lists to store

111
00:12:30,050 --> 00:12:47,770
dealers and players hand so...so just

112
00:12:47,770 --> 00:12:53,660
before I finish this video just a couple
of other things to note on line 73 I

113
00:12:53,660 --> 00:12:57,800
used the list function to create a
new list from the cards and if I've done

114
00:12:57,800 --> 00:13:02,460
something different for example if I hadn't change that code and made this instead

115
00:13:02,460 --> 00:13:09,710
commenting that out and make that....which is another way of doing it

116
00:13:09,710 --> 00:13:13,670
deck would then be exactly the same list
as cards so that's not necessarily a

117
00:13:13,670 --> 00:13:17,220
problem when just shuffling but as the
cards are dealt they may be removed from the

118
00:13:17,220 --> 00:13:20,900
list which could cause problems so every
game will then have fewer and fewer cards

119
00:13:20,900 --> 00:13:23,950
until their are none left to create new
decks from so we definitely don't want to do it

120
00:13:23,950 --> 00:13:28,250
that way we want to create a new
and separate list which is the way we've done on

121
00:13:28,250 --> 00:13:32,580
lines 73 so I'm going to finish the
video here now in the next video we're

122
00:13:32,580 --> 00:13:37,830
gonna go ahead and write some code to
deal the card we are gonna deal cards to the

123
00:13:37,830 --> 00:13:43,090
players each time the button is click so we need a
function called deal_card

124
00:13:43,090 --> 00:13:44,710
and we'll work on that in the next video

