Advertisement
Guest User

new

a guest
Jul 27th, 2024
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.30 KB | None | 0 0
  1. import pygame
  2. import sys
  3.  
  4. # Initialize Pygame
  5. pygame.init()
  6.  
  7. # Constants
  8. SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600
  9. BOARD_ROWS, BOARD_COLS = 4, 8
  10. CELL_SIZE = 60
  11. PADDING = 20
  12. SEEDS_PER_HOLE = 4
  13.  
  14. # Colors
  15. BG_COLOR = (245, 222, 179)
  16. BOARD_COLOR = (139, 69, 19)
  17. SEED_COLOR = (255, 255, 255)
  18.  
  19. # Create the screen
  20. screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
  21. pygame.display.set_caption("Igisoro")
  22.  
  23. # Board class
  24. class Board:
  25.     def __init__(self):
  26.         self.holes = [[SEEDS_PER_HOLE for _ in range(BOARD_COLS)] for _ in range(BOARD_ROWS)]
  27.  
  28.     def draw(self):
  29.         for row in range(BOARD_ROWS):
  30.             for col in range(BOARD_COLS):
  31.                 x = PADDING + col * CELL_SIZE
  32.                 y = PADDING + row * CELL_SIZE
  33.                 pygame.draw.rect(screen, BOARD_COLOR, (x, y, CELL_SIZE, CELL_SIZE))
  34.                 seeds = self.holes[row][col]
  35.                 font = pygame.font.Font(None, 36)
  36.                 text = font.render(str(seeds), True, SEED_COLOR)
  37.                 text_rect = text.get_rect(center=(x + CELL_SIZE // 2, y + CELL_SIZE // 2))
  38.                 screen.blit(text, text_rect)
  39.  
  40.     def sow(self, row, col):
  41.         seeds_to_sow = self.holes[row][col]
  42.         self.holes[row][col] = 0
  43.         current_row, current_col = row, col
  44.         while seeds_to_sow > 0:
  45.             current_col += 1
  46.             if current_col == BOARD_COLS:
  47.                 current_col = 0
  48.                 current_row = (current_row + 1) % BOARD_ROWS
  49.             if current_row != row or current_col != col:
  50.                 self.holes[current_row][current_col] += 1
  51.                 seeds_to_sow -= 1
  52.  
  53. # Main function
  54. def main():
  55.     board = Board()
  56.     clock = pygame.time.Clock()
  57.     running = True
  58.  
  59.     while running:
  60.         for event in pygame.event.get():
  61.             if event.type == pygame.QUIT:
  62.                 running = False
  63.             elif event.type == pygame.MOUSEBUTTONDOWN:
  64.                 mouse_x, mouse_y = event.pos
  65.                 row = (mouse_y - PADDING) // CELL_SIZE
  66.                 col = (mouse_x - PADDING) // CELL_SIZE
  67.                 if 0 <= row < BOARD_ROWS and 0 <= col < BOARD_COLS:
  68.                     board.sow(row, col)
  69.  
  70.         screen.fill(BG_COLOR)
  71.         board.draw()
  72.         pygame.display.flip()
  73.         clock.tick(30)
  74.  
  75.     pygame.quit()
  76.     sys.exit()
  77.  
  78. if __name__ == "__main__":
  79.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement