diff --git a/assets/sprites/mine2.png b/assets/sprites/mine2.png new file mode 100644 index 0000000..ce39b42 Binary files /dev/null and b/assets/sprites/mine2.png differ diff --git a/assets/sprites/mine3.png b/assets/sprites/mine3.png new file mode 100644 index 0000000..f30ea6b Binary files /dev/null and b/assets/sprites/mine3.png differ diff --git a/assets/sprites/mine4.png b/assets/sprites/mine4.png new file mode 100644 index 0000000..0bd1c7d Binary files /dev/null and b/assets/sprites/mine4.png differ diff --git a/classes/minesweeper.py b/classes/minesweeper.py index 5144865..a97f27e 100644 --- a/classes/minesweeper.py +++ b/classes/minesweeper.py @@ -10,20 +10,45 @@ class Mine: position_y:int size:int image:pygame.surface.Surface + image_text:pygame.surface.Surface + timer_text:pygame.surface.Surface + timer_event:pygame.USEREVENT + font:pygame.font.Font difficulty:int = 1 weight:float = 1.0 + explosion_timer:int = 100 - def __init__(self,position_x, position_y, size): + def __init__(self,position_x, position_y, size, difficulty=1, weight=1.0, timer=100): self.position_x=position_x self.position_y=position_y self.size=size - self.image = pygame.image.load("assets/sprites/mine_fun_sized.png") + self.weight = weight + self.explosion_timer = timer + self.difficulty = difficulty + if self.difficulty == 2: + self.image = pygame.image.load("assets/sprites/mine2.png") + elif self.difficulty == 3: + self.image = pygame.image.load("assets/sprites/mine3.png") + elif self.difficulty == 4: + self.image = pygame.image.load("assets/sprites/mine4.png") + else: + self.image = pygame.image.load("assets/sprites/mine_fun_sized.png") self.image = pygame.transform.scale(self.image, (self.size, self.size)) + self.font = pygame.font.SysFont('Comic Sans MS', int(self.size*0.4)) + self.image_text = self.font.render(str(self.weight), False, (0, 0, 0)) + self.timer_text = self.font.render(str(self.explosion_timer), False, (255, 0, 0)) + timer_interval = 1000 + self.timer_event = pygame.USEREVENT + 1 + pygame.time.set_timer(self.timer_event , timer_interval) def draw(self, window): + self.timer_text = self.font.render(str(self.explosion_timer), False, (255, 0, 0)) position_on_screen = (self.size*self.position_x, self.size*self.position_y) window.blit(self.image, position_on_screen) + window.blit(self.image_text, (position_on_screen[0]+self.size/4, position_on_screen[1]+self.size/2)) + window.blit(self.timer_text, (position_on_screen[0]+self.size/4, position_on_screen[1]-self.size/8)) + class Cliff: position_x:int @@ -137,7 +162,10 @@ class Map: ok = False break if ok and randrange(10)==0 and not (i<2 and j<3): - mine = Mine(j, i, self.tile_size) + difficulty = randrange(0,4)+1 + weight = randrange(10, 31)/10 + timer = randrange(100, 200) + mine = Mine(j, i, self.tile_size, difficulty, weight, timer) self.mines.append(mine) def draw_tiles(self): diff --git a/main.py b/main.py index 4fd4b49..e94769c 100644 --- a/main.py +++ b/main.py @@ -16,6 +16,8 @@ MUSIC = False # ustalenie FPS FPS = 60 +#włączenie tekstu +pygame.font.init() def main(): if MUSIC: @@ -70,6 +72,9 @@ def main(): if event.type == pygame.QUIT: game_loop = False pygame.quit() + elif event.type in [i.timer_event for i in map.mines]: + for i in map.mines: + i.explosion_timer-=1 if __name__ == "__main__":