-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounterButton.py
More file actions
48 lines (40 loc) · 1.66 KB
/
counterButton.py
File metadata and controls
48 lines (40 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pygame
from constants import *
pygame.init()
class CounterButton:
"""
A class representing a circular button in pygame, used for moving a game piece.
Attributes:
- _window: The pygame window where the button is drawn.
- _x (int): X-coordinate of the center of the button.
- _y (int): Y-coordinate of the center of the button.
- _radius (int): Radius of the circular button.
- _cell : Represents the game cell associated with this button
- _colour (tuple): RGB color of the button.
- _text (str): Label for the button (default: "Move").
- rect (pygame.Rect): A rectangle surrounding the circular button for event detection.
- circle (pygame.draw.circle): The actual circular button drawn on the screen.
"""
def __init__(self, window, x, y, radius, cell, colour):
self._window = window
self._x = x
self._y = y
self._radius = radius
self._cell = cell
self._colour = colour
self._text = "Move" # Default text label
# Define a small, grey square rectangle around the button, for collision detection
self.rect = pygame.Rect(x - 14, y - 14, 28, 28)
pygame.draw.rect(window, DARK_GREY, self.rect, 2)
# Draws the outline of the circular button with the colour of the player
self.circle = pygame.draw.circle(self._window, self._colour, (x, y), 14, 3)
def isClicked(self):
"""
Checks if the button is clicked.
"""
return self._cell
def getText(self):
"""
Retrieves the text associated with the button.
"""
return self._text