Skip to content

Commit

Permalink
Started screen
Browse files Browse the repository at this point in the history
  • Loading branch information
stlucasgarcia committed Nov 13, 2020
1 parent e11035f commit 2a54626
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
6 changes: 3 additions & 3 deletions ending_screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def _createUI(self, kwargs):
def scores(self) -> bool:
snd_win = pg.mixer.Sound("data/sounds/win_effect.mp3")
pg.mixer.Sound.play(snd_win)
pg.mixer.Sound.set_volume(snd_win, 0.1)
pg.mixer.Sound.set_volume(snd_win, 0.25)
pg.time.wait(1000)

snd = pg.mixer.Sound("data/soundtracks/score.mp3")
pg.mixer.Sound.play(snd, -1)
pg.mixer.Sound.set_volume(snd, 0.05)
pg.mixer.Sound.set_volume(snd, 0.25)

pg.mouse.set_visible(True)

Expand Down Expand Up @@ -198,7 +198,7 @@ def _show_lb(self):
def run(self):
snd = pg.mixer.Sound(f"data/soundtracks/leaderboard.mp3")
pg.mixer.Sound.play(snd, -1)
pg.mixer.Sound.set_volume(snd, 0.05)
pg.mixer.Sound.set_volume(snd, 0.35)

is_running = True
clock = pg.time.Clock()
Expand Down
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def game_run():

play_again = False
name1, name2 = None, None

score1, score2 = 0, 0

while isRunning:
pg.mouse.set_visible(False)

Expand Down Expand Up @@ -77,7 +80,9 @@ def game_run():
pg.mouse.set_visible(False)

MainScreen_object = MainScreen(screen, is_controller)
play_again = MainScreen_object.main_screen(usernames=[name1, name2])
play_again = MainScreen_object.main_screen(
score1, score2, usernames=[name1, name2]
)


def re_exec():
Expand Down
40 changes: 33 additions & 7 deletions main_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
self.chip_2 = self.config.chip_2
self.ai_chip = 2

def main_screen(self, usernames: list, option="AI"):
def main_screen(self, score1: int, score2: int, usernames: list, option="AI"):
control = Controller()
utilities = UtilitiesMain(self.screen)

Expand Down Expand Up @@ -64,6 +64,7 @@ def main_screen(self, usernames: list, option="AI"):

pg.mixer.music.play(loops=-1)
pg.mixer.music.set_volume(self.volume)

while not close_loop:
start_time = utilities.draw_board(matrix, start_time, clock, usernames)

Expand All @@ -83,14 +84,20 @@ def main_screen(self, usernames: list, option="AI"):
x = event.pos[0]
y = event.pos[1]

print(x, y)
# print(x, y)

if event.type == pg.MOUSEBUTTONDOWN:
save_chip = chip

column = utilities.location_X(pg.mouse.get_pos()[0])
if column != 0:
play_again, player_turn, chip = utilities.playersTurn(
(
play_again,
player_turn,
chip,
score1,
score2,
) = utilities.playersTurn(
column,
matrix,
player_turn,
Expand All @@ -99,6 +106,8 @@ def main_screen(self, usernames: list, option="AI"):
usernames,
start_time,
clock,
score1,
score2,
option,
)

Expand All @@ -114,7 +123,13 @@ def main_screen(self, usernames: list, option="AI"):

column = utilities.location_X(control.get_x_pos(event))
if column != 0:
play_again, player_turn, chip = utilities.playersTurn(
(
play_again,
player_turn,
chip,
score1,
score2,
) = utilities.playersTurn(
column,
matrix,
player_turn,
Expand All @@ -123,6 +138,8 @@ def main_screen(self, usernames: list, option="AI"):
usernames,
start_time,
clock,
score1,
score2,
option,
)

Expand Down Expand Up @@ -152,11 +169,20 @@ def main_screen(self, usernames: list, option="AI"):
utilities.drop_piece(matrix, row, column, self.ai_chip)

if utilities.is_victory(matrix, self.ai_chip):
utilities.draw_board(matrix, start_time, clock, usernames)
print(score2, player_turn)
print(score1, player_turn)
score2 += 1
print(score2, player_turn)

start_time = utilities.draw_board(
matrix, start_time, clock, usernames
)

pg.display.update()

pg.time.wait(500)
pg.time.wait(1500)

data = {usernames[0]: 10, usernames[1]: 5}
data = {usernames[0]: score1, usernames[1]: score2}

ending = EndingScreen(
self.screen,
Expand Down
18 changes: 14 additions & 4 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ def playersTurn(
usernames,
start_time,
clock,
score1,
score2,
option="AI",
):
turn = player_turn
Expand All @@ -271,12 +273,20 @@ def playersTurn(
self.drop_piece(matrix, row, column, turn)

if self.is_victory(matrix, turn) or self.is_tie(matrix):
print(score1, turn)
print(score2, turn)
score1 += 1 if turn % 2 == 0 else score1
print(score1, turn)
score2 += 1 if turn % 2 == 1 else score2
print(score2, turn)

self.draw_board(matrix, start_time, clock, usernames)
start_time = self.draw_board(matrix, start_time, clock, usernames)

pg.time.wait(500)
pg.display.update()

data = {usernames[0]: 10, usernames[1]: 5}
pg.time.wait(1500)

data = {usernames[0]: score1, usernames[1]: score2}

ending = EndingScreen(
self.screen,
Expand All @@ -290,7 +300,7 @@ def playersTurn(

play_again = ending.scores()

return play_again, turn, chip
return play_again, turn, chip, score1, score2

def evaluate_window(self, window, chip):
score = 0
Expand Down

0 comments on commit 2a54626

Please sign in to comment.