File "/home/ludovic/Bureau/tricolor.py", line 169, in <module> playgame() File…
- User
File "/home/ludovic/Bureau/tricolor.py", line 169, in play_game() File "/home/ludovic/Bureau/tricolor.py", line 144, in play_game result = pierre_feuille_ciseaux() TypeError: pierre_feuille_ciseaux() missing 2 required positional arguments: 'player1' and 'player2' import pygame import sys import random
pygame.init()
Taille de la fenêtre
WIDTH = 800 HEIGHT = 800
Taille des cases et grille
CELL_SIZE = 40 GRID_SIZE = WIDTH // CELL_SIZE
Couleurs
WHITE = (255, 255, 255) BLACK = (0, 0, 0)
Joueurs
player_colors = [(255, 0, 0), (0, 0, 255)]
Grille
grid = []
def initialize_grid(): global grid grid = [[None] * GRID_SIZE for _ in range(GRID_SIZE)]
def draw_pion(screen, x, y, color): position = (x * CELL_SIZE + CELL_SIZE // 2, y * CELL_SIZE + CELL_SIZE // 2) pygame.draw.circle(screen, color, position, CELL_SIZE // 2 - 2)
def draw_grid(screen): for y in range(GRID_SIZE): for x in range(GRID_SIZE): rect = pygame.Rect(x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE) pygame.draw.rect(screen, BLACK, rect, 1)
codeif grid[y][x] is not None: color = pygame.Color(player_colors[grid[y][x]]) draw_pion(screen, x, y, color)def place_pion(player, x, y): global grid if grid[y][x] is None: grid[y][x] = player return True return False
def expand_pions(player): global grid new_positions = []
codefor y in range(GRID_SIZE): for x in range(GRID_SIZE): if grid[y][x] == player: for dy in (-1, 0, 1): for dx in (-1, 0, 1): ny, nx = y + dy, x + dx if 0 <= nx < GRID_SIZE and 0 <= ny < GRID_SIZE and grid[ny][nx] is None: new_positions.append((nx, ny)) for position in new_positions: grid[position[1]][position[0]] = playerdef check_neighbors(x, y, player): global grid neighbors = [ (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1), ]
codefor nx, ny in neighbors: if 0 <= nx < GRID_SIZE and 0 <= ny < GRID_SIZE and grid[ny][nx] is not None and grid[ny][nx] != player: return True return False - Assistant
- User
ne pas utiliser pass et break
- Assistant
- User
- Assistant
Pour que la fonction pierre-feuille-ciseaux se fasse automatiquement lors de l'appuie sur espace, vous pouvez déplacer le bloc de code associé à cette fonction dans la section de l'événement . Voici le code de la fonction avec les modifications nécessaires:
- User
la fonction pierre_feuille_ciseaux ne sactive que si il y a cote a cote des couleurs differente
- Assistant
- User
- Assistant