Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gridlines to "next piece" #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

scotteifel
Copy link

Hey. I just did the tetris tutorial and it was great. I found a way to add a line of code which will add gridlines to the waiting piece.

@@ -247,6 +247,7 @@ def draw_next_shape(shape, surface):
for j, column in enumerate(row):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does enumerate do here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in this line it looks like the enumerate function searches a row in the shape array. This might look like ['..00..'].
As it looks at each element, if it sees a 0, it will fill that space in with a rectangle piece. If there is a ., it will continue to the next iteration. In this way one row of the shape can be drawn. Doing this over all of the rows will cause a shape to take form. The enumerate function is a convenient way to track the index of an item in an array while cycling through it. Here is a video example explaining the function. https://www.youtube.com/watch?v=-MZiQaNI0QA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants