Skip to content

Conversation

@A-DBN
Copy link

@A-DBN A-DBN commented Oct 20, 2024

Added a Maze game, where you have to memorize the trail and reproduce it.

With small changes you can make a whiteboard and draw. I can do it quickly if you want

Copy link

@Baduit Baduit left a comment

Choose a reason for hiding this comment

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

Overall LGTM :) , I'm just nitpicking in the comment

maze.py Outdated
}

class Player:
def __init__(self, start_x, start_y):
Copy link

Choose a reason for hiding this comment

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

Using a dataclass with a post_init function to initialize values that depend on others would be better I think
It would look like this

from dataclasses import dataclass, field
from typing import List, Tuple

@dataclass
class Player:
    start_x: int
    start_y: int
    trail_directions: List[Tuple[int, int]] = field(default_factory=list)
    trail: List[Tuple[int, int]] = field(default_factory=list)
    x: int = field(init=False)
    y: int = field(init=False)

    def __post_init__(self):
        self.x = self.start_x
        self.y = self.start_y
       self.trail.append((self.x, self.y))

maze.py Outdated
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
Copy link

Choose a reason for hiding this comment

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

I think using match case would be slightly better here

@A-DBN
Copy link
Author

A-DBN commented Oct 21, 2024

Thanks for the feedbacks, always used python for small projects so I've never really learned properly. Gonna work on it

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.

2 participants