Basically, I have a "game" which replicates the classic game of mastermind which takes the button and moves it to a specific part of the board in the button class, if it is clicked. Shown below:
class Button(Sequence):
def __init__(self, x, y, image):
super().__init__(len_code)
self.x = x
self.y = y
self.origin_x = x
self.origin_y = y
self.image = image
self.rect = self.image.get_rect()
self.rect.center = (x + (1 / 2 * x), y + (1 / 2 * y))
self.colours = ["red", "blue", "yellow", "green", "purple", "pink", "orange", "brown"]
self.clicked = False
self.pos = 0
def Draw(self, surface, colour, button_name, button_colours):
self.button_colours = button_colours
mouse_pos = pygame.mouse.get_pos()
if self.rect.collidepoint(mouse_pos):
if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:
self.clicked = True
if self.y == 645:
self.x = self.origin_x
self.y = self.origin_y
self.pos -= 1
else:
print(self.pos)
self.x = 36 + (self.pos * 58)
self.y = 645
self.rect.center = (self.x + (1 / 2 * self.x), self.y + (1 / 2 * self.y))
self.pos += 1
code.UpdateBoard(colour, False)
if pygame.mouse.get_pressed()[0] == 1 and self.clicked == True:
self.clicked = False
pygame.Surface.set_colorkey(self.image, [0, 0, 0])
surface.blit(self.image, (self.rect.x, self.rect.y))
which is self-explanatory for the intelligent people on here, but if you want to know, I have an x and y value and change those values if it clicked and change it back if it is clicked again. I would like to use this information in a list or something of the sort to check whether these colours match the code input by the end user.
Is it better to input it into a list first and then move it by taking the corresponding x and y values or just like in my code?
My code is at: https://replit.com/@Coops/Pygame-game#main.py thanks for reading this if you need anything clarified feel free to ask me and for any other suggestions on how to make my code better.