-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube.py
39 lines (32 loc) · 1.17 KB
/
cube.py
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
import pygame
class Cube:
"""Class to manage cube object"""
def __init__(self, value, row, col, width, height):
"""Initialize cube object"""
self.value = value
self.temp = 0
self.row = row
self.col = col
self.width = width
self.height = height
self.selected = False
def draw_cube(self, window):
"""Draw the cube value"""
font = pygame.font.SysFont("comicsans", 40)
size = self.width / 9
x = self.col * size
y = self.row * size
if self.temp != 0 and self.value == 0:
text = font.render(str(self.temp), True, (128, 128, 128))
window.blit(text, (x+5, y+5))
elif self.value != 0:
text = font.render(str(self.value), True, (0, 0, 0))
window.blit(text, (x + (size/2 - text.get_width()/2), y + (size/2 - text.get_height()/2)))
if self.selected:
pygame.draw.rect(window, (0, 153, 255), (x, y, size, size), 3)
def set_value(self, value):
"""Set the official value"""
self.value = value
def set_temporary(self, value):
"""Set the temporary value"""
self.temp = value