-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreasure.py
45 lines (37 loc) · 1.41 KB
/
Treasure.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
40
41
42
43
44
45
import pygame
from Board import Board
from Board import Color
class Treasure:
def __init__(self, type, x, y, value):
self.type = type # 0 for gold, 1 for precious stones
self.open = False
self.posX = x
self.posY = y
self.value = value
self.color = Color.GOLD if self.type == 0 else Color.STONE
self.font = Board.get_instance().treasures_font
pygame.init()
# return True if the chest is open, False otherwise
def isOpen(self):
return self.open
#open the Chest
def openChest(self) :
print("ouverture du coffre")
self.open = True
self.color = Color.LIGHT_RED if self.getType() == 1 else Color.LIGHT_YELLOW
#return the type of treasure in the Chest
def getType(self):
return self.type
# return the quantity of treasure
def getValue(self):
return self.value
#set the quantity of treasure to 0
def resetValue(self):
self.value = 0
def draw(self, screen, cell_size):
text = str(self.value)
text_surface = self.font.render(text, True, Color.GREEN if self.open else Color.BLACK if self.type == 0 else Color.WHITE)
text_rect = text_surface.get_rect()
rect = pygame.draw.rect(screen, self.color, (self.posY * cell_size, self.posX * cell_size, cell_size, cell_size))
text_rect.center = rect.center
screen.blit(text_surface, text_rect)