#!/bin/python
import pygame
import random
WIDTH = 400
HEIGHT = 500
FPS = 60
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
f1 = pygame.font.Font(None, 36)
running = True
counter = 0
number = []
for i in range(0,16):
number.append(i)
x = 0
y = 0
#должно быть именно 15 перестановок 16 элементов
def mix_fields():
for index in range(0,15,1):
num1 = number[i]
index_random = random.randint(0,15)
num2 = number[index_random]
number[i] = num2
number[index_random] = num1
mix_fields()
state = 0
current_fields = 0
index_field = 0
while running:
screen.fill(BLACK)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
state = state + 1
x, y = pygame.mouse.get_pos()
x = x//100 * 100
y = y//100 * 100
ipos = 0
if y//100 == 0:
ipos = 4*(x//100)
if y//100 == 1:
ipos = 4*(x//100)+1
if y//100 == 2:
ipos = 4*(x//100)+2
if y//100 == 3:
ipos = 4*(x//100)+3
if state == 1:
current_fields = number[ipos]
index_field = ipos
print(index_field)
if state == 2:
number[index_field] = number[ipos]
number[ipos] = current_fields
state = 0
if (event.pos[0] >= 0 and event.pos[0] <= 400):
if (event.pos[1] >= 400 and event.pos[1] <= 500):
mix_fields()
counter = 0
for it_1 in range(0,400,100):
for it_2 in range(0,400,100):
pygame.draw.rect(screen,WHITE, (it_1,it_2,99,99))
font = pygame.font.SysFont(None, 34)
img = font.render(str(number[counter]), True, BLACK)
screen.blit(img, (it_1,it_2))
counter = counter + 1
surface_button = pygame.Surface((400,100))
surface_button.fill((192, 192, 192))
f1 = pygame.font.Font(None, 36)
text = f1.render("Перемешать", True,
(180, 0, 0))
surface_button.blit(text, (0, 0))
screen.blit(surface_button, (0, 400))
pygame.display.update()
pygame.quit()
|