Giới thiệu sản phẩm

#khởi tạo một cửa sổ

import pygame, sys
import random

pygame.init() #module

#tạo kích thước cửa sổ và tiêu đề cửa sổ

screen = pygame.display.set_mode((400,500))

pygame.display.set_caption("Game Tetris")

GREEN = (20, 255, 140)
GREY = (210, 210 ,210)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
PURPLE = (255, 0, 255)
YELLOW = (255, 255, 0)
CYAN = (0, 255, 255)
BLUE = (100, 100, 255)
GRAY = (128, 128, 128)
BLACK = (0, 0, 0)
colors = (RED, GREEN, PURPLE, YELLOW, CYAN, BLUE, GRAY, BLACK)

class Figure:
    x = 0
    y = 0
    
    figures = [
            [[1, 5, 9, 13], [4, 5, 6, 7]],
            [[1, 2, 5, 9], [0, 4, 5, 6], [1, 5, 9, 8], [4, 5, 6, 10]],
            [[1, 2, 6, 10], [5, 6, 7, 9], [2, 6, 10, 11], [3, 5, 6, 7]],
            [[1, 4, 5, 6], [1, 4, 5, 9], [4, 5, 6, 9], [1, 5, 6, 9]],
            [[1, 2, 5, 6]],]
    
    def __init__(self, x ,y):
        self.x = x
        self.y = y
        #khởi tạo ngẫu nhiên kiểu khối gạch
        self.type = random.randint(0,len(self.figures)-1)
        self.color = random.randint(1, len(colors)-1)
        self.rotation = 0

    #phương thức image: trả về hình dạng của figure lên lưới
        #( ô 4x4 = 16 ô vuông)

    def image(self):
        return self.figures[self.type][self.rotation]
    def rotate(self):
        self.rotation = (self.rotation+1)%len(self.figures[self.type])

#khởi tạo class Tetris
class Tetris:
    x = 100
    y = 60
    zoom = 20
    field=[]
    state='start'
    figure = None
    

    def __init__(self, height, width):
        self.height = height
        self.width = width
        for i in range(0,height,1):
            new_line = []
            for j in range(0,width,1):
                new_line.append(0)
            self.field.append(new_line)

    def new_figure(self):
        self.figure = Figure(3,0)

    def go_down(self):
        self.figure.y += 1
        if self.intersects():
            self.figure.y-=1
            self.freeze()

    def go_side(self, dx):
        old_x=self.figure.x
        self.figure.x+=dx


Hình ảnh sản phẩm
Hãy bình luận để nhặt 100 thóc nhé

Đăng nhập để tham gia bình luận

Thông tin tác giả

Địa vị cộng đồng: Nông dân

Sản phẩm cùng tác giả

Sản phẩm liên quan

    Không có sản phẩm nào

Bạn muốn thử làm game không?