MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/z2n49l/what_is_dry/
r/badcode • u/Spaceginner • Nov 23 '22
5 comments sorted by
3
btw, there are 1174 lines of this beatiful code
2
can someone explain this and how you would make an alternative?
Like I get we can just use a loop to check for that but how would you change the values?
4 u/Spaceginner Dec 03 '22 here is how (came up with this like in 15 minutes?):def loader(self, surface, number): level = self.levels[number] color = (0, 255, 0) cell_size = 30 for y_cell in range(len(level) - 1): for x_cell in range(len(level[str(y_cell)]) - 1): if level[str(y_cell)][str(x_cell)]: pygame.draw.rect(surface, color, (x_cell * cell_size, y_cell * cell_size, cell_size, cell_size))
4
here is how (came up with this like in 15 minutes?):
def loader(self, surface, number): level = self.levels[number] color = (0, 255, 0) cell_size = 30 for y_cell in range(len(level) - 1): for x_cell in range(len(level[str(y_cell)]) - 1): if level[str(y_cell)][str(x_cell)]: pygame.draw.rect(surface, color, (x_cell * cell_size, y_cell * cell_size, cell_size, cell_size))
Image Transcription: Code
def loader(self, surface, number): if self.levels[number]["0"]["0"]: pygame.draw.rect(surface, (0, 255, 0), (0, 0, 30, 30)) if self.levels[number]["0"]["1"]: pygame.draw.rect(surface, (0, 255, 0), (30, 0, 30, 30)) if self.levels[number]["0"]["2"]: pygame.draw.rect(surface, (0, 255, 0), (60, 0, 30, 30)) if self.levels[number]["0"]["3"]: pygame.draw.rect(surface, (0, 255, 0), (90, 0, 30, 30)) if self.levels[number]["0"]["4"]: pygame.draw.rect(surface, (0, 255, 0), (120, 0, 30, 30)) if self.levels[number]["0"]["5"]: pygame.draw.rect(surface, (0, 255, 0), (150, 0, 30, 30)) if self.levels[number]["0"]["6"]: pygame.draw.rect(surface, (0, 255, 0), (180, 0, 30, 30)) if self.levels[number]["0"]["7"]: pygame.draw.rect(surface, (0, 255, 0), (210, 0, 30, 30)) if self.levels[number]["0"]["8"]: pygame.draw.rect(surface, (0, 255, 0), (240, 0, 30, 30)) if self.levels[number]["0"]["9"]: pygame.draw.rect(surface, (0, 255, 0), (270, 0, 30, 30)) if self.levels[number]["0"]["10"]: pygame.draw.rect(surface, (0, 255, 0), (300, 0, 30, 30)) if self.levels[number]["0"]["11"]: pygame.draw.rect(surface, (0, 255, 0), (330, 0, 30, 30)) if self.levels[number]["0"]["12"]: pygame.draw.rect(surface, (0, 255, 0), (360, 0, 30, 30)) if self.levels[number]["0"]["13"]: pygame.draw.rect(surface, (0, 255, 0), (390, 0, 30, 30)) if self.levels[number]["0"]["14"]: pygame.draw.rect(surface, (0, 255, 0), (420, 0, 30, 30)) if self.levels[number]["0"]["15"]: pygame.draw.rect(surface, (0, 255, 0), (450, 0, 30, 30)) if self.levels[number]["0"]["16"]: pygame.draw.rect(surface, (0, 255, 0), (480, 0, 30, 30)) if self.levels[number]["0"]["17"]: pygame.draw.rect(surface, (0, 255, 0), (510, 0, 30, 30)) if self.levels[number]["0"]["18"]: pygame.draw.rect(surface, (0, 255, 0), (540, 0, 30, 30)) if self.levels[number]["0"]["19"]: pygame.draw.rect(surface, (0, 255, 0), (570, 0, 30, 30))
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
When the loops are sold out
3
u/Spaceginner Nov 23 '22
btw, there are 1174 lines of this beatiful code
2
u/Emotional_Sir_65110 Dec 03 '22
can someone explain this and how you would make an alternative?
Like I get we can just use a loop to check for that but how would you change the values?
2
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Nov 26 '22
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
2
u/LeMeRem Nov 26 '22
When the loops are sold out