1 00:00:01,160 --> 00:00:06,710 We've created our instance attributes and our set cards method. 2 00:00:06,710 --> 00:00:09,190 Next, let's tackle creating the grid. 3 00:00:10,570 --> 00:00:15,630 In order to create our grid, I think creating the rows in their own 4 00:00:15,630 --> 00:00:20,490 separate method will help keep things a bit cleaner and clear. 5 00:00:20,490 --> 00:00:22,845 Create a method called create_row. 6 00:00:37,303 --> 00:00:41,200 We'll pass in the row number so we know which row to create. 7 00:00:44,730 --> 00:00:47,940 For example, if one is passed in, 8 00:00:47,940 --> 00:00:52,690 then we will need to find all the cards with one in their location. 9 00:00:55,000 --> 00:00:57,850 We'll need an empty list where we can append 10 00:00:57,850 --> 00:01:02,250 either cards if they have been guessed or empty spaces. 11 00:01:03,400 --> 00:01:08,214 Let's loop through the columns so we can find the matching locations for this row. 12 00:01:15,033 --> 00:01:17,820 Now we'll need to loop through our cards 13 00:01:23,653 --> 00:01:27,800 to find the ones that are located in this row. 14 00:01:27,800 --> 00:01:31,897 If card.location equals, 15 00:01:35,521 --> 00:01:42,285 The current column and the row number, if they are, 16 00:01:42,285 --> 00:01:46,656 we need to check to see if they've been matched. 17 00:01:46,656 --> 00:01:52,965 If card.matched, if so, 18 00:01:52,965 --> 00:01:56,140 then we need to append the word to our row. 19 00:01:57,705 --> 00:02:05,345 row.append, string of the card, just to make sure the word gets appended. 20 00:02:07,070 --> 00:02:13,600 If not, then we need to append empty spaces that are the same size as our word. 21 00:02:13,600 --> 00:02:17,240 So three spaces. 22 00:02:20,630 --> 00:02:22,623 One, two, three. 23 00:02:24,564 --> 00:02:28,078 This helps keep our grid nice and neat. 24 00:02:28,078 --> 00:02:31,856 Finally, we'll need to return the row. 25 00:02:36,001 --> 00:02:37,357 Let's test this out. 26 00:02:43,166 --> 00:02:48,205 You can see I've already called the create_row method for 27 00:02:48,205 --> 00:02:51,034 each row that we have in our grid. 28 00:02:51,034 --> 00:02:55,606 And I also grabbed the first few cards in our cards list and 29 00:02:55,606 --> 00:02:59,820 switch their matched attribute to true. 30 00:02:59,820 --> 00:03:03,935 This way we can make sure we're also going to see the words as they're matched. 31 00:03:12,552 --> 00:03:15,109 Great, it's looking like a grid already. 32 00:03:20,944 --> 00:03:25,527 Okay, so now let's jump into our create grid method that 33 00:03:25,527 --> 00:03:30,308 we'll use our create row to create the grid in the console. 34 00:03:38,332 --> 00:03:40,158 We can call it create_grid. 35 00:03:46,482 --> 00:03:50,660 Now, the first thing that needs to get printed out is our header. 36 00:03:50,660 --> 00:03:54,310 Let's create a template using comments to show what this will look like. 37 00:04:19,987 --> 00:04:25,678 Okay, so we can use join to print out our header with spaces and 38 00:04:25,678 --> 00:04:29,020 pipes in between each one. 39 00:04:29,020 --> 00:04:31,723 Now that we know what it should look like, 40 00:04:31,723 --> 00:04:34,827 we're going to use join to put it all together. 41 00:04:40,324 --> 00:04:42,548 Going to start with the beginning. 42 00:04:46,783 --> 00:04:50,060 And we should have a space for the row number. 43 00:04:51,070 --> 00:04:53,862 Our pipe and then two spaces. 44 00:04:55,201 --> 00:05:00,154 This is because our column names are a single letter while our words 45 00:05:00,154 --> 00:05:04,683 are three letters. Then we're 46 00:05:04,683 --> 00:05:09,205 going to add all of our columns using join, so 47 00:05:09,205 --> 00:05:16,720 we're gonna join with a double space, space space, pipe, space space. 48 00:05:16,720 --> 00:05:20,550 Again, this is because our columns are single letter 49 00:05:20,550 --> 00:05:23,460 while the words are going to be three letters. 50 00:05:23,460 --> 00:05:30,590 This will help keep it nice and neat, .join(self.columns). 51 00:05:32,772 --> 00:05:37,782 And then, we need our ending pipe, 52 00:05:37,782 --> 00:05:41,800 plus space, space, pipe. 53 00:05:41,800 --> 00:05:43,730 Now since it's our header, and 54 00:05:43,730 --> 00:05:46,630 it's the beginning of our game grid, we need to print it out. 55 00:05:49,240 --> 00:05:53,181 Let's scroll down to the bottom and call the function. 56 00:05:59,281 --> 00:06:00,930 Great, that looks nice. 57 00:06:09,844 --> 00:06:15,168 Now it's time to create the rows, we'll need to loop through a range, 58 00:06:15,168 --> 00:06:18,800 that will start at one and end at four. 59 00:06:18,800 --> 00:06:20,953 We did this before, up in the _init_ method. 60 00:06:29,251 --> 00:06:32,260 Now we can start our print row variable. 61 00:06:35,820 --> 00:06:39,560 This will be the row that will be printed to our console. 62 00:06:39,560 --> 00:06:43,680 The row should start with our row number, 63 00:06:46,699 --> 00:06:49,180 A pipe, and then one space. 64 00:06:50,210 --> 00:06:55,380 Then we'll need to call our row method and pass in the row we're currently on. 65 00:06:55,380 --> 00:06:57,739 Let's save that to a variable called get_row. 66 00:07:05,591 --> 00:07:10,209 Now we can add to our print row by joining all of our words or spaces, 67 00:07:10,209 --> 00:07:12,780 just like we did in the header above. 68 00:07:14,590 --> 00:07:16,888 Print_row +=. 69 00:07:19,704 --> 00:07:25,121 Then we'll need a space, pipe, 70 00:07:25,121 --> 00:07:30,543 space, .join, our get_row. 71 00:07:33,601 --> 00:07:37,880 And then finish it off with a space, pipe. 72 00:07:40,330 --> 00:07:41,981 Finally print out the row. 73 00:07:45,788 --> 00:07:49,800 Now we can run the file and see what our grid looks like in the console. 74 00:07:54,020 --> 00:07:55,800 Great, that looks really nice. 75 00:07:56,880 --> 00:08:03,807 Test this out further by changing some of the cards matched attribute, to true. 76 00:08:09,905 --> 00:08:14,871 Game.cards, first one 77 00:08:14,871 --> 00:08:18,894 .matched = True. 78 00:08:18,894 --> 00:08:22,886 I'm gonna copy this, paste, paste, paste. 79 00:08:26,732 --> 00:08:30,073 This will be, three, two, one, okay. 80 00:08:30,073 --> 00:08:37,320 Now when we run the file again, I should see the words inside of our grid. 81 00:08:40,084 --> 00:08:41,749 Awesome.