From 13312f0c258f0f645dca2c5e3fbf051b82a5e090 Mon Sep 17 00:00:00 2001 From: Bowske Date: Sat, 28 Mar 2020 12:02:27 +0100 Subject: [PATCH] start srodowiska --- .gitignore | 3 ++ game.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 3 files changed, 91 insertions(+) create mode 100644 .gitignore create mode 100644 game.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be213e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv/ +.vscode/ +.idea \ No newline at end of file diff --git a/game.py b/game.py new file mode 100644 index 0000000..528a56e --- /dev/null +++ b/game.py @@ -0,0 +1,87 @@ + +import pygame + +# Define some colors +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +GREEN = (0, 255, 0) +RED = (255, 0, 0) +BLUE = (0, 0, 255) + +# This sets the WIDTH and HEIGHT of each grid location +WIDTH = 60 +HEIGHT = 60 + +# This sets the margin between each cell +MARGIN = 5 + +# Create a 2 dimensional array. A two dimensional +# array is simply a list of lists. +grid = [] +for row in range(100): + # Add an empty array that will hold each cell + # in this row + grid.append([]) + for column in range(100): + grid[row].append(0) # Append a cell + +# Set row 1, cell 5 to one. (Remember rows and +# column numbers start at zero.) +grid[0][0] = 1 + +# Initialize pygame +pygame.init() + +# Set the HEIGHT and WIDTH of the screen +WINDOW_SIZE = [980, 980] +screen = pygame.display.set_mode(WINDOW_SIZE) + +# Set title of screen +pygame.display.set_caption("Inteligentna śmieciarka") + +# Loop until the user clicks the close button. +done = False + +# Used to manage how fast the screen updates +clock = pygame.time.Clock() + +# -------- Main Program Loop ----------- +while not done: + for event in pygame.event.get(): # User did something + if event.type == pygame.QUIT: # If user clicked close + done = True # Flag that we are done so we exit this loop + elif event.type == pygame.MOUSEBUTTONDOWN: + # User clicks the mouse. Get the position + pos = pygame.mouse.get_pos() + # Change the x/y screen coordinates to grid coordinates + column = pos[0] // (WIDTH + MARGIN) + row = pos[1] // (HEIGHT + MARGIN) + # Set that location to one + grid[row][column] = 1 + print("Click ", pos, "Grid coordinates: ", row, column) + + # Set the screen background + screen.fill(BLACK) + + # Draw the grid + for row in range(15): + for column in range(15): + color = WHITE + if grid[row][column] == 1: + color = BLUE + pygame.draw.rect(screen, + color, + [(MARGIN + WIDTH) * column + MARGIN, + (MARGIN + HEIGHT) * row + MARGIN, + WIDTH, + HEIGHT]) + + # Limit to 60 frames per second + clock.tick(60) + + # Go ahead and update the screen with what we've drawn. + pygame.display.flip() + +# Be IDLE friendly. If you forget this line, the program will 'hang' +# on exit. +pygame.quit() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..27a222f --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pygame==1.9.6 \ No newline at end of file