Planning to Print2:53 with Ben Deitch
In this video we'll plan out how we're going to print out the entire game!
Instead of just showing us the top card on the deck, let's print out the entire game. 0:00 That way, if we hit any road blocks, it'll be easy to see what's wrong. 0:04 Let's first get rid of the extra space in our Card class. 0:08 And then back in our GameModel class, 0:12 let's start by clearing out the debug print function. 0:14 Within, let's take a look at how we're going to print out the game. 0:21 After we've called the resetGame function, the game should look something like this. 0:25 To print this, we'll start by turning it into a grid. 0:29 Each cell in this grid will be six characters long. 0:32 [SOUND] Three characters for the data. 0:35 [SOUND] And three characters for the spaces between each cell. 0:37 On the first line, we'll print the top card of the waste pile, 0:41 then will leave two cells empty and print the top card in each foundation. 0:44 Or if the foundation is empty, we'll print something else. 0:48 Next, we'll add some space before our Tableau piles by printing a blank line. 0:51 Then, we need to print our Tableau piles. 0:56 To do this, we're first going to change our grid to allocate 13 rows to 0:59 our Tableau piles, then we're going to loop through the rows and 1:04 if the Tableau pile has a card index, we print it. 1:08 Otherwise, we'll just print three spaces. 1:12 And once that's done, we'll know exactly what our game looks like. 1:15 So first things, first. 1:19 Before we get around to printing again. 1:20 Let's jump back to our card class and 1:22 make sure that each card will be exactly three characters long. 1:24 And I'll put this on a new line, so it's just a little bit easier to see. 1:29 Right now, we've got the cards value. 1:33 And then a space, and then the card suit. 1:37 But if the cards value is a ten, 1:41 then this is going to be four characters and our grid will look a little off. 1:44 To fix this, lets first split these out into two separate strings and 1:49 then add those two strings together. 1:53 So one string for the value. 1:59 One string for the suit. 2:01 And then add them together, so far we've just gotten rid of the space in between. 2:05 Next, after the first string, type .padEnd(2). 2:10 Pad in, 2:17 adds spaces to the end of our string until it reaches a specified length. 2:18 In our case, 2. 2:23 It's also an extension function on the string class. 2:25 So now, if we've got something like the six of clubs. 2:28 The six will get an extra space after it to make it two characters long. 2:31 And if we've got the ten of diamonds, 2:35 since ten is already two characters, it won't add anything. 2:37 Meaning, now our two string function always returns a three character string. 2:42 Perfect. 2:47 And the next video, will get back to where we left off with our debug print function. 2:49
You need to sign up for Treehouse in order to download course files.Sign up