add time mine explosion detection and game over screen
This commit is contained in:
parent
af238a6ed6
commit
cc7c556d0c
36
main.py
36
main.py
@ -6,11 +6,15 @@ import random
|
||||
# other files of this project
|
||||
import project_constants as const
|
||||
import minefield as mf
|
||||
from mine_models.time_mine import TimeMine
|
||||
|
||||
import searching_algorithms.a_star as a_star
|
||||
|
||||
from display_assets import blit_graphics
|
||||
from project_constants import HIGHLIGHT, INPUT_ROW, INPUT_COLUMN, RANDOM_BUTTON, OK_BUTTON
|
||||
from ui.ui_components_list import UiComponentsList
|
||||
from ui.text_box import TextBox
|
||||
from ui.button import Button
|
||||
|
||||
|
||||
def main():
|
||||
@ -33,6 +37,7 @@ def main():
|
||||
# setting flags for program
|
||||
running = True
|
||||
in_menu = True
|
||||
is_game_over = False
|
||||
|
||||
# creating list storing all ui components
|
||||
ui_components_list = UiComponentsList([INPUT_ROW, INPUT_COLUMN, RANDOM_BUTTON, OK_BUTTON])
|
||||
@ -108,7 +113,7 @@ def main():
|
||||
# ==== GAME LOOP ==== #
|
||||
# =================== #
|
||||
|
||||
while running and not in_menu:
|
||||
while running and not in_menu and not is_game_over:
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
@ -156,6 +161,35 @@ def main():
|
||||
component.set_flags(is_active=True)
|
||||
|
||||
in_game_timer += delta_time
|
||||
for x in minefield.matrix:
|
||||
for y in x:
|
||||
if y.mine is not None:
|
||||
if isinstance(y.mine, TimeMine):
|
||||
if y.mine.timer == 0:
|
||||
is_game_over = True
|
||||
|
||||
while running and is_game_over:
|
||||
clock.tick(const.V_FPS)
|
||||
const.SCREEN.fill((255, 255, 255))
|
||||
tb = TextBox(position=(150, 200),dimensions= (500, 100),text="Game Over")
|
||||
cont = Button(position=(350, 350),dimensions= (100, 50),text="Try again")
|
||||
close = Button(position=(350, 450), dimensions=(100, 50), text="Close")
|
||||
ev =pygame.event.get()
|
||||
if close.is_clicked(pygame.mouse.get_pos(),ev):
|
||||
running=False
|
||||
if cont.is_clicked(pygame.mouse.get_pos(),ev):
|
||||
minefield = mf.Minefield(const.MAP_RANDOM_10x10)
|
||||
agent = minefield.agent
|
||||
in_menu = True
|
||||
is_game_over = False
|
||||
for component in ui_components_list.selectable_ui_components:
|
||||
component.set_flags(is_active=True)
|
||||
cont.draw(const.SCREEN,pygame.mouse.get_pos())
|
||||
close.draw(const.SCREEN,pygame.mouse.get_pos())
|
||||
tb.draw(const.SCREEN)
|
||||
pygame.display.flip()
|
||||
|
||||
#is_game_over = False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user