Пример #1
0
def pause_game(pause_key):
    """
    Pause the game, show a pause menu and handle its options.
    """
    current_time = time()
    current_timer = get_timer()

    pause_rectangle_coords, zones_coords = display_pause()
    pause_rectangle_width = pause_rectangle_coords[2] - pause_rectangle_coords[
        0]
    pause_rectangle_height = pause_rectangle_coords[
        3] - pause_rectangle_coords[1]

    unpaused = False
    while not unpaused:

        event = donne_evenement()
        type_ev = type_evenement(event)

        if type_ev == "ClicGauche":
            click_x = clic_x(event)
            click_y = clic_y(event)

            for x1, y1, x2, y2, txt in zones_coords:
                if click_x >= x1 and click_x <= x2 and click_y >= y1 and click_y <= y2:
                    if txt == "quitter":
                        ferme_fenetre()
                        exit(0)
                    elif txt == "contrôles":
                        display_controls()
                        attente_clic()
                        efface_tout()
                        display_game(timer=current_timer + 1)
                        display_pause()
                    else:
                        make_save()
                        display_save_success(pause_rectangle_coords,
                                             pause_rectangle_width,
                                             pause_rectangle_height)

                elif not (click_x >= pause_rectangle_coords[0]
                          and click_x <= pause_rectangle_coords[2]
                          and click_y >= pause_rectangle_coords[1]
                          and click_y <= pause_rectangle_coords[3]):
                    unpaused = True
        elif type_ev == "Touche":
            if touche(event).lower() == pause_key:
                unpaused = True

        mise_a_jour()
    adjust_timer(gs.start_time, current_time)
Пример #2
0
def display_game_end(victory):
	"""
	Display a victory message in the middle of the screen if the victory parameter is set to True. Otherwise, display a defeat message.
	"""
	efface_tout()
	if victory:
		image(0, 0, "./res/img/misc/success_background.png", ancrage = "nw")
		color = "green"
		game_state = "gagné"
	else:
		color = "red"
		game_state = "perdu"
	texte(gs.window_width / 2, gs.window_height / 2, f"Vous avez {game_state} !", ancrage = "center", taille = 34, couleur = color)
	mise_a_jour()
	attente_clic()
Пример #3
0
def players_selection_menu():
    """
    Display and handle the players count selection screen.
    """
    clicked = False
    zones_coords = display_players_selection_menu()
    while not clicked:
        click_x, click_y, _ = attente_clic()
        for i, (x1, y1, x2, y2) in enumerate(zones_coords):
            if click_x >= x1 and click_x <= x2 and click_y >= y1 and click_y <= y2:
                efface_tout()

                gs.players_count = i + 1
                k.get_keys()

                display_controls()
                attente_clic()
                clicked = True
Пример #4
0
def display_controls():
	"""
	Display the right game controls screen according to the players count.
	"""
	pc = gs.players_count
	window_width = gs.window_width
	window_height = gs.window_height

	efface_tout()

	printables = get_printables_actions()

	texte(window_width / 2, window_height / 8, "CONTROLES", ancrage = "center", taille = 28)

	common_controls = []
	for char in {"g", "b", "escape"}:
		common_controls.append(f"- {char} : {printables[get_action(char)]}")
	
	texte(window_width / 2, window_height / 8 * 2.5, "\n".join(common_controls), ancrage = "center", taille = 20)

	if pc == 1:
		player_keys = [("e", "v", "x", "n")]
	elif pc == 2:
		player_keys = [("a", "z", "e", "q"), ("o", "p", "i", "l", "m")]
	else:
		player_keys = [("a", "z", "q"), ("x", "c", "v"), ("o", "p", "m", "l")]

	for j in range(1, pc + 1):
		texte(gs.window_width / (pc + 1) * j, gs.window_height / 6 * 3, f"Joueur {j}", ancrage = "center", taille = 26)
	
	players_actions = []

	for chars in player_keys:
		players_actions.append([])
		for char in chars:
			players_actions[-1].append(f"- {char} : {printables[get_action(char)]}")

	for j, actions in enumerate(players_actions):
		txt = "\n".join(actions)
		texte(gs.window_width / (pc + 1) * (j + 1), gs.window_height / 6 * 4, txt, ancrage = "center", taille = 20)

	texte(window_width / 2, window_height / 6 * 5.2, "A noter que le switch est utilisé pour changer de pion sélectionné, de vortex sélectionné ou de tuile à téléporter.", ancrage = "center", taille = 18)
	texte(window_width / 2, window_height / 6 * 5.5, "Cliquez n'importe où dans la fenêtre pour continuer.", ancrage = "center", taille = 14)
	mise_a_jour()
Пример #5
0
def display_save_loading_menu():
	"""
	Display the menu that allow to choose between starting a new game or loading a previously saved game. Return a list of coordinates as tuples that represent the clickable areas of the menu.
	"""
	efface_tout()
	image(gs.window_width / 2, gs.window_height / 3, "./res/img/misc/magic-maze.png", ancrage = "center")
	zones_coords = []

	for i, txt in enumerate(("Nouvelle partie", "Charger la sauvegarde")):
		x = gs.window_width / 3 * (i + 1)
		y = gs.window_height / 3 * 2.2
		text_width = longueur_texte(txt)
		text_height = hauteur_texte()

		texte(x, y, txt, ancrage = "center")
		zones_coords.append((x - text_width / 2 - 20, y - text_height / 2 - 20, x + text_width / 2 + 20, y + text_height / 2 + 20))
		rectangle(zones_coords[i][0], zones_coords[i][1], zones_coords[i][2], zones_coords[i][3], epaisseur = 2)
	mise_a_jour()
	return zones_coords
Пример #6
0
def display_players_selection_menu():
	"""
	Display the menu that allow to choose the number of players that will play together. Return a list of coordinates as tuples that represent the clickable areas of the menu.
	"""
	efface_tout()
	image(gs.window_width / 2, gs.window_height / 3, "./res/img/misc/magic-maze.png", ancrage = "center")
	zones_coords = []

	for i in range(1, 4):
		if i > 1:
			text = f"{i} joueurs"
		else:
			text = "solo"
		text_width = longueur_texte(text)
		text_height = hauteur_texte()

		x = gs.window_width / 4 * i
		y = gs.window_height / 3 * 2.2
		texte(x, y, text, ancrage = "center")

		zones_coords.append((x - text_width / 2 - 20, y - text_height / 2 - 20, x + text_width / 2 + 20, y + text_height / 2 + 20))
		rectangle(zones_coords[i - 1][0], zones_coords[i - 1][1], zones_coords[i - 1][2], zones_coords[i - 1][3], epaisseur = 2)
	mise_a_jour()
	return zones_coords
Пример #7
0
def display_game(timer = None):
	"""
	Display the whole game to the screen.
	"""
	board = gs.board
	pawns = gs.pawns
	walls = gs.walls

	rows_count = len(board)
	assert rows_count >= 2, "the specified board does not have enough rows"

	columns_count = len(board[0])
	assert columns_count >= 2, "the specified board does not have enough columns"

	for color in pawns:
		assert pawns[color][0] < rows_count and pawns[color][0] >= -1 and pawns[color][1] < columns_count and pawns[color][1] >= -1, f"{color} position is out of range"

	efface_tout()

	cell_width = gs.cell_width
	cell_height = gs.cell_height

	for i in range(rows_count):
		for j in range(columns_count):
			display_cell((i, j))

			if i > 0 and ((i - 1, j), (i, j)) in walls or ((i, j), (i - 1, j)) in walls:
				rectangle(j * cell_width, i * cell_height - 2, j * cell_width + cell_width, i * cell_height + 2, remplissage = "grey")
			if j > 0 and ((i, j - 1), (i, j)) in walls or ((i, j), (i, j - 1)) in walls:
				rectangle(j * cell_width - 2, i * cell_height, j * cell_width + 2, i * cell_height + cell_height, remplissage = "grey")

	display_escalators()
	display_players()
	display_side_panel(timer)
	
	mise_a_jour()