У меня проблема с импортом модуля pygame ⇐ Python
У меня проблема с импортом модуля pygame
import math import random import pygame import tkinter as tk from tkinter import messagebox class cube(object): rows = 20 def __init__(self, start, dirnix=1, dirniy=0, color=(0, 0, 0)): self.pos = start self.dirnx = dirnix self.dirny = dirniy self.color = color def move(self, dirnx, dirny): self.dirnx = dirnx self.dirny = dirny self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny) def draw(self, surface, eyes=False): dis = size // rows rw = self.pos[0] cm = self.pos[1] pygame.draw.rect(surface, self.color, (rw * dis + 1, cm * dis + 1, dis - 2, dis - 2)) if eyes: center = dis // 2 radius = 3 circle_middle = (rw * dis + center - radius - 2, cm * dis + 8) circle_middle2 = (rw * dis + dis - radius * 2, cm * dis + 8) pygame.draw.circle(surface, (255, 255, 255), circle_middle, radius) pygame.draw.circle(surface, (255, 255, 255), circle_middle2, radius) class snake(object): body = [] turns = {} def __init__(self, color, pos): self.color = color self.head = cube(pos) self.body.append(self.head) self.dirnx = 0 self.dirny = 1 def move(self): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() keys = pygame.key.get_pressed() for i, c in enumerate(self.body): p = c.pos[:] if p in self.turns: turn = self.turns[p] c.move(turn[0], turn[1]) if i == len(self.body) - 1: self.turns.pop(p) else: if c.dirnx == -1 and c.pos[0] = c.rows - 1: c.pos = (0, c.pos[1]) elif c.dirny == 1 and c.pos[1] >= c.rows - 1: c.pos = (c.pos[0], 0) elif c.dirny == -1 and c.pos[1]
Источник: https://stackoverflow.com/questions/781 ... ame-module
import math import random import pygame import tkinter as tk from tkinter import messagebox class cube(object): rows = 20 def __init__(self, start, dirnix=1, dirniy=0, color=(0, 0, 0)): self.pos = start self.dirnx = dirnix self.dirny = dirniy self.color = color def move(self, dirnx, dirny): self.dirnx = dirnx self.dirny = dirny self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny) def draw(self, surface, eyes=False): dis = size // rows rw = self.pos[0] cm = self.pos[1] pygame.draw.rect(surface, self.color, (rw * dis + 1, cm * dis + 1, dis - 2, dis - 2)) if eyes: center = dis // 2 radius = 3 circle_middle = (rw * dis + center - radius - 2, cm * dis + 8) circle_middle2 = (rw * dis + dis - radius * 2, cm * dis + 8) pygame.draw.circle(surface, (255, 255, 255), circle_middle, radius) pygame.draw.circle(surface, (255, 255, 255), circle_middle2, radius) class snake(object): body = [] turns = {} def __init__(self, color, pos): self.color = color self.head = cube(pos) self.body.append(self.head) self.dirnx = 0 self.dirny = 1 def move(self): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() keys = pygame.key.get_pressed() for i, c in enumerate(self.body): p = c.pos[:] if p in self.turns: turn = self.turns[p] c.move(turn[0], turn[1]) if i == len(self.body) - 1: self.turns.pop(p) else: if c.dirnx == -1 and c.pos[0] = c.rows - 1: c.pos = (0, c.pos[1]) elif c.dirny == 1 and c.pos[1] >= c.rows - 1: c.pos = (c.pos[0], 0) elif c.dirny == -1 and c.pos[1]
Источник: https://stackoverflow.com/questions/781 ... ame-module
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Pygame установлен, тест работает, ошибка модуля pygame все еще отсутствует [дубликат]
Anonymous » » в форуме Python - 0 Ответы
- 20 Просмотры
-
Последнее сообщение Anonymous
-