Skip to content

Commit

Permalink
Add smiley face on top of the board
Browse files Browse the repository at this point in the history
  • Loading branch information
Chubercik committed Mar 14, 2022
1 parent d762393 commit 18ac1e9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Binary file modified pysweeper.exe
Binary file not shown.
6 changes: 5 additions & 1 deletion pysweeper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sys import exit

from utilities import Board, Button, pygame, screen, sec_to_time
from utilities import Board, Button, Smiley, pygame, screen, sec_to_time


class Pysweeper:
Expand All @@ -12,6 +12,9 @@ def __init__(self, width: int, height: int, bombs: int) -> None:
self._flags = 0
self._question_marks = 0
self._board = Board(width, height, bombs)
self._smiley = Smiley(x=(self._board._left_offset - 32
+ 32*self._width//2),
y=(self._board._top_offset - 64))
self._time = 0

def run(self) -> None:
Expand All @@ -33,6 +36,7 @@ def run(self) -> None:
screen.fill((255, 255, 255))

self._board.draw()
self._smiley.draw(screen)

mouse_pos = pygame.mouse.get_pos()
mouse_x = (mouse_pos[0] - self._board._left_offset) // 32
Expand Down
53 changes: 53 additions & 0 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,59 @@ def reveal(self, x: int, y: int) -> None:
self.reveal(x + i, y + j)


class Smiley:
def __init__(self, x: int, y: int) -> None:
self._x = x
self._y = y
self._is_in_awe = False
self._is_dead = False
self._is_cool = False
self._sprite = None

def draw(self, screen: pygame.Surface) -> None:
if self._is_in_awe:
self._sprite = sprites["smiley_wow"]
elif self._is_dead:
self._sprite = sprites["smiley_rip"]
elif self._is_cool:
self._sprite = sprites["smiley_yeah"]
else:
self._sprite = sprites["smiley"]
self._sprite = pygame.transform.scale(self._sprite, (64, 64))
screen.blit(self._sprite, (self._x, self._y))

def set_in_awe(self) -> None:
self._is_in_awe = True
self._is_dead = False
self._is_cool = False

def set_dead(self) -> None:
self._is_in_awe = False
self._is_dead = True
self._is_cool = False

def set_cool(self) -> None:
self._is_in_awe = False
self._is_dead = False
self._is_cool = True

def is_in_awe(self) -> bool:
return self._is_in_awe

def is_dead(self) -> bool:
return self._is_dead

def is_cool(self) -> bool:
return self._is_cool

def set_position(self, x: int, y: int) -> None:
self._x = x
self._y = y

def get_position(self) -> Tuple[int]:
return (self._x, self._y)


class Button:
def __init__(self, x: int, y: int,
width: int, height: int,
Expand Down

0 comments on commit 18ac1e9

Please sign in to comment.