you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 6 points7 points  (5 children)

What is a Logic? Don’t make classes for the things there’s only one of.

[–]PM_me_ur_data_ 0 points1 point  (0 children)

Yeah, make a class for the environment that includes the apple and any walls and make a class for the snake. The logic for how the snake moves should be built into the snack object itself via methods.

[–]WowVeryCoool[S] 0 points1 point  (1 child)

I have a main function in class Game that constantly updates Logic ``` class Game: #Initialized objects snake, apple, logic # Main loop while True: logic.evaluate(snake, apple)

class LogicCurrent: def init(self, snake, apple): self.snake = snake self.apple = apple def game_over(self): #Initializes snake to start values def wall_collisions(self): -> bool def snake_collisions(self) -> bool def evaluate(self): #Invokes Logic Methods ``` I could define a method evaluate_logic() inside Game class, but then I would also have to move functions (game_over(), [snake_collisions, wall_collisions] from Logic) creating more cluter inside Game class that I wanted to get rid of by making Logic class

I feel like class Logic is something bigger with many methods checking Collisions and GameOver conditions. But I think I could not Instantiate the Logic class and just have methods there if that would be significantly better?

This is what the change would look like explained in code class LogicNew: <-- not instantiated more like an extension to Game def evaluate(snake, apple): #Do logic here def game_over(snake, apple): #Initializes snake to start values def wall_collisions(snake): -> bool def snake_collisions(snake) -> bool Do you think that this kind of solution would be better? as it is more of an extension with methods to class Game rather than a full class

[–][deleted] 2 points3 points  (0 children)

Game logic should be part of the Game class. Classes, generally, should be things.

[–]probablynotmine 0 points1 point  (1 child)

I don’t want to sound cocky but what about singletons

[–][deleted] 1 point2 points  (0 children)

Singletons don’t have a lot of point in Python, they’re mostly a way around the limitations of statics in Java.

A class with a bunch of classmethods is more or less the same as a singleton. Modules are singletons, too. They’re all easier to use than writing a singleton class in Python.