1 00:00:00,000 --> 00:00:04,742 [MUSIC] 2 00:00:04,742 --> 00:00:07,360 Great job putting together that deck class. 3 00:00:07,360 --> 00:00:10,740 I know it's a lot to throw at you, but you're doing fantastic. 4 00:00:10,740 --> 00:00:15,410 We've created a fully functional deck that we can shuffle and even draw from. 5 00:00:15,410 --> 00:00:17,350 But before we can use our deck, 6 00:00:17,350 --> 00:00:22,120 we'll need to create a few other objects to help us model a game of solitaire. 7 00:00:22,120 --> 00:00:25,720 So let's take a minute to talk about what objects we need and 8 00:00:25,720 --> 00:00:28,360 how all the pieces will fit together. 9 00:00:28,360 --> 00:00:31,370 We've already modeled a card class and the debt. 10 00:00:31,370 --> 00:00:34,630 So, looking at the layout of solitaire, it looks like we still need 11 00:00:34,630 --> 00:00:40,130 to make objects for the waste piles, the foundation piles, and the tableau piles. 12 00:00:40,130 --> 00:00:43,990 We're also going to need an object to help us manage the game itself. 13 00:00:43,990 --> 00:00:46,910 This object will be responsible for setting up the game and 14 00:00:46,910 --> 00:00:50,600 handling any actions we take, kind of like a dealer at a casino. 15 00:00:50,600 --> 00:00:54,350 Put another way, this object is responsible for 16 00:00:54,350 --> 00:00:56,840 modeling our game of solitaire. 17 00:00:56,840 --> 00:00:58,800 It will make up the model layer of our app. 18 00:00:59,970 --> 00:01:04,040 Along with the model layer, we'll also have a view layer, and a presenter layer. 19 00:01:04,040 --> 00:01:08,110 The view layer will just be a simple interface with one function 20 00:01:08,110 --> 00:01:09,850 to update the view. 21 00:01:09,850 --> 00:01:13,690 On the other hand, the presenter layer will act as a middleman 22 00:01:13,690 --> 00:01:16,160 between our model and view layers. 23 00:01:16,160 --> 00:01:18,390 Whenever we take an action on our view, 24 00:01:18,390 --> 00:01:23,300 like clicking on a card in the tableau we'll call a method on our presenter. 25 00:01:23,300 --> 00:01:26,040 This method will then update our model and 26 00:01:26,040 --> 00:01:30,790 once that's done, it'll update our view to reflect any changes made to the model. 27 00:01:30,790 --> 00:01:35,070 All right, now that we've got that under control, let's zoom back out and 28 00:01:35,070 --> 00:01:37,090 take a look at the big picture. 29 00:01:37,090 --> 00:01:41,000 We started with our card class which we used to create our deck. 30 00:01:41,000 --> 00:01:45,160 Our deck will then be used by our model along with our waste pile, 31 00:01:45,160 --> 00:01:50,210 foundation piles and tableau piles to correctly model a game of solitaire. 32 00:01:50,210 --> 00:01:53,190 The model then goes through our middle man, the presenter and 33 00:01:53,190 --> 00:01:54,800 connects to the view. 34 00:01:54,800 --> 00:01:57,660 And that's pretty much entirely how the app works. 35 00:01:57,660 --> 00:02:00,060 It's gonna take a bit to get through all this so 36 00:02:00,060 --> 00:02:04,290 don't be afraid if it doesn't 100% make sense just yet but 37 00:02:04,290 --> 00:02:08,830 for now we're gonna keep on trucking by creating a class for a model. 38 00:02:08,830 --> 00:02:12,401 So let's create a new colon class named game model. 39 00:02:18,182 --> 00:02:23,760 Then and sat our model we need to create properties for each of our game objects. 40 00:02:23,760 --> 00:02:30,870 Let's start with the deck by typing val deck equals deck. 41 00:02:30,870 --> 00:02:33,060 Up next is the waste pile. 42 00:02:33,060 --> 00:02:35,870 But before we start creating a waste pile object. 43 00:02:35,870 --> 00:02:39,640 Let's take a second to think about how we use the waste pile. 44 00:02:39,640 --> 00:02:43,530 In solitaire, there's three things that can happen to our waste pile. 45 00:02:43,530 --> 00:02:47,920 First off, when we tap the deck, we add a card to the waste pile. 46 00:02:47,920 --> 00:02:52,770 Secondly, when we tap the waste pile, assuming there's a valid play available 47 00:02:52,770 --> 00:02:55,810 we remove a card from the waste pile and play it. 48 00:02:55,810 --> 00:02:58,260 Lastly, when we're all out of options, 49 00:02:58,260 --> 00:03:01,530 we can tap the waste pile to shuffle it back into the deck. 50 00:03:01,530 --> 00:03:06,220 So our three waste pile actions are add a card, remove a card, and 51 00:03:06,220 --> 00:03:08,110 remove all the cards. 52 00:03:08,110 --> 00:03:12,920 Lucky for us, this functionality already exists in the form of the list object. 53 00:03:12,920 --> 00:03:15,310 So instead of creating a whole new class just for 54 00:03:15,310 --> 00:03:18,062 our waste pile let's just make it a mutable list. 55 00:03:18,062 --> 00:03:22,767 val wastePile which is gonna 56 00:03:22,767 --> 00:03:26,890 be a MutableList of cards. 57 00:03:26,890 --> 00:03:33,019 And since the wastePile starts empty let's set it equal to a MutableList of nothing. 58 00:03:33,019 --> 00:03:36,530 MutableList of and leave it empty. 59 00:03:36,530 --> 00:03:40,120 Nice, now that we've conquered the wastePile next step 60 00:03:40,120 --> 00:03:43,090 is creating a property to hold our foundation piles. 61 00:03:43,090 --> 00:03:47,600 But before we can do that we'll need to create our foundation pile object 62 00:03:47,600 --> 00:03:48,930 which we'll do in the next video. 63 00:03:50,040 --> 00:03:53,630 But before we get to the game, I need to tell you about an awesome resource for 64 00:03:53,630 --> 00:03:57,070 learning Kotlin on and that is the Kotlin cones. 65 00:03:57,070 --> 00:04:01,200 Basically there's 42 code challenges provided by the good people at 66 00:04:01,200 --> 00:04:03,300 to help you learn Kotlin. 67 00:04:03,300 --> 00:04:06,710 So while there aren't any code challenges in this course, if you're looking for 68 00:04:06,710 --> 00:04:10,510 extra practice, look no further than the Kotlin cones. 69 00:04:10,510 --> 00:04:13,610 I provided a link in the teacher's notes of every video. 70 00:04:13,610 --> 00:04:16,350 So even if you don't need any extra practice yet, 71 00:04:16,350 --> 00:04:20,020 if you want some extra practice later you'll know where to find it. 72 00:04:20,020 --> 00:04:22,430 With that said, let's move on to programming the game.