1 00:00:00,250 --> 00:00:04,130 We've got each card being represented and exactly three characters. 2 00:00:04,130 --> 00:00:06,430 Now let's get back to our debug print function and 3 00:00:06,430 --> 00:00:09,290 see if we can handle printing that first line. 4 00:00:09,290 --> 00:00:12,350 Let's start by creating a variable to hold our print string for 5 00:00:12,350 --> 00:00:16,490 the first line, of our first line. 6 00:00:16,490 --> 00:00:21,190 Then since the first thing on this line is the top waste file card. 7 00:00:21,190 --> 00:00:23,910 Let set this equal to a string And 8 00:00:23,910 --> 00:00:29,300 inside that string let's put dollar sign bracket, and let's do waste pile. 9 00:00:29,300 --> 00:00:29,860 last. 10 00:00:31,380 --> 00:00:34,560 But we can't forget that the waste pile can be empty. 11 00:00:34,560 --> 00:00:38,220 So let's only use the last card if there is a last card. 12 00:00:40,490 --> 00:00:42,310 If, waste pile. 13 00:00:42,310 --> 00:00:44,460 size is greater than zero. 14 00:00:45,490 --> 00:00:46,850 And if there is not a last card. 15 00:00:48,130 --> 00:00:51,000 Let's just print three underscores to show an empty pile. 16 00:00:52,410 --> 00:00:57,320 On the next line let's use the pad end function again to add spaces to our 17 00:00:57,320 --> 00:01:00,890 first line to get it ready for adding in the foundation piles. 18 00:01:00,890 --> 00:01:04,060 The first foundation pile starts on the fourth cell. 19 00:01:04,060 --> 00:01:06,620 So we need to add padding to our first line 20 00:01:06,620 --> 00:01:09,370 until it's the length of the first three cells. 21 00:01:09,370 --> 00:01:12,450 And since each cell is six characters long 22 00:01:12,450 --> 00:01:17,910 we need our first line to be 18 characters long before we start the foundations. 23 00:01:17,910 --> 00:01:25,160 So let's type firstLine = firstLine.padEnd and pass in 18. 24 00:01:25,160 --> 00:01:27,420 Now that we've got that covered, 25 00:01:27,420 --> 00:01:31,020 let's move on to adding our foundation piles to our string. 26 00:01:31,020 --> 00:01:33,685 The first step is to loop through each foundation pile. 27 00:01:33,685 --> 00:01:41,040 FoundationPiles.foreach then inside the loop let's add to our first line. 28 00:01:42,070 --> 00:01:48,109 FirstLine plus equals and to make it easy let's copy what we did for the wastePile. 29 00:01:52,727 --> 00:01:58,340 And then just replace waste pile with it which is the foundation pile not cards. 30 00:02:01,850 --> 00:02:06,040 And ultimately on the next line, let's add three spaces to the end of our 31 00:02:06,040 --> 00:02:10,690 first line property as the space between the foundation piles. 32 00:02:10,690 --> 00:02:13,750 And finally, at the bottom of the debug print method, 33 00:02:13,750 --> 00:02:15,186 let's print out the first line. 34 00:02:15,186 --> 00:02:20,830 S-O-U-T, tab, first line. 35 00:02:20,830 --> 00:02:22,879 Then let's run the app and see what we get. 36 00:02:26,578 --> 00:02:28,500 Well, I guess that's a good thing. 37 00:02:28,500 --> 00:02:31,590 It's kind of boring, but it looks like it should, 38 00:02:31,590 --> 00:02:35,220 especially considering at this point, we've only just set up the board. 39 00:02:35,220 --> 00:02:38,130 Dont worry, things will get a bit more exciting around here 40 00:02:38,130 --> 00:02:40,540 once we finish printing the tab row piles. 41 00:02:40,540 --> 00:02:44,820 Remember, for the tab row piles, we'll be looping through 13 rows and 42 00:02:44,820 --> 00:02:48,610 then inside each row, we'll be looping through the tab row piles. 43 00:02:48,610 --> 00:02:53,190 But before we can get to the tab row piles, we need to add our space. 44 00:02:53,190 --> 00:02:55,540 So in the next line, let's add an empty print statement. 45 00:02:57,290 --> 00:03:01,595 Then let's create a loop to loop through all 13 possible rows. 46 00:03:01,595 --> 00:03:07,978 for i in 0..12. 47 00:03:07,978 --> 00:03:10,460 And inside this loop, 48 00:03:10,460 --> 00:03:15,070 let's start by creating a variable to represent the string for this row. 49 00:03:15,070 --> 00:03:17,960 Var row equals empty string. 50 00:03:17,960 --> 00:03:20,015 Then lets a loop through our tableaupiles. 51 00:03:20,015 --> 00:03:23,360 Tableaupiles.forEach. 52 00:03:23,360 --> 00:03:26,646 And for each pile, we need to add on to our row variable. 53 00:03:26,646 --> 00:03:31,000 So row +=, but before we start adding, 54 00:03:31,000 --> 00:03:35,530 we need to know if this pile even has a card at index i. 55 00:03:35,530 --> 00:03:38,700 Luckily, there's an easy way to accomplish this. 56 00:03:38,700 --> 00:03:43,840 We can just check if the number of cards in that pile is greater than i. 57 00:03:43,840 --> 00:03:49,717 So let's type if (it.cards.size > i) and 58 00:03:49,717 --> 00:03:54,085 if it is then let's return a string 59 00:03:54,085 --> 00:03:59,071 representation of the card at index i. 60 00:04:02,617 --> 00:04:07,678 And inside the brackets, it.cards index i. 61 00:04:07,678 --> 00:04:12,134 And if there is no card at index i, let's just add three spaces. 62 00:04:16,174 --> 00:04:20,160 Then on the next line, let's not forget about the three spaces of padding. 63 00:04:24,117 --> 00:04:31,436 And finally right below our Tablo piles loop, Let's print out our row. 64 00:04:37,652 --> 00:04:38,478 Then let's run the app. 65 00:04:45,505 --> 00:04:46,710 And awesome. 66 00:04:46,710 --> 00:04:49,320 That's exactly what our board should look like and And 67 00:04:49,320 --> 00:04:51,750 we can easily see the whole thing. 68 00:04:51,750 --> 00:04:55,790 This is definitely going to make writing tests a lot more fun. 69 00:04:55,790 --> 00:04:57,210 So, let's get right to it. 70 00:04:57,210 --> 00:05:00,380 At this point we'd like to write some kind of test 71 00:05:00,380 --> 00:05:04,290 to help us know that everything is working but before we can write the test, 72 00:05:04,290 --> 00:05:09,290 we need to do a little more exploring about how we interact with our game model. 73 00:05:09,290 --> 00:05:10,180 For starters, 74 00:05:10,180 --> 00:05:14,710 let's see if we can tap the deck to turn a card over into the waste pile. 75 00:05:14,710 --> 00:05:20,670 Over in our app, our kt file, let's add a line after the call to reset game, 76 00:05:20,670 --> 00:05:24,580 and now we need to call the on deck tap method in our presenter. 77 00:05:24,580 --> 00:05:27,190 But instead of creating a new presenter object. 78 00:05:27,190 --> 00:05:31,360 Let's just change our presenter to be a singleton just like our model. 79 00:05:31,360 --> 00:05:34,280 So we'll replace class with object. 80 00:05:34,280 --> 00:05:37,960 After all we're only ever going to have one presenter. 81 00:05:37,960 --> 00:05:46,104 Next back in the app file, let's call GamePresenter.onDeckTap, 82 00:05:46,104 --> 00:05:54,010 then let's run the app again, and there we go we've got a card in the waste pile. 83 00:05:54,010 --> 00:05:57,170 Also, notice that we didn't get a null pointer exception. 84 00:05:58,330 --> 00:06:02,435 Over in the game presenter class, we definitely tried to call 85 00:06:02,435 --> 00:06:07,220 view.update on a null object. 86 00:06:07,220 --> 00:06:11,950 But thanks to the safe call operator, instead of a null pointer exception, 87 00:06:11,950 --> 00:06:14,930 we just got null for the whole statement. 88 00:06:14,930 --> 00:06:18,110 And so nothing happened which is pretty cool and 89 00:06:18,110 --> 00:06:21,130 the next video will test our app and see where we stand.