Last active
August 29, 2015 14:21
-
-
Save wibbia/d672e4ec7295ef1499af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame, sys, random, time | |
from pygame.locals import * | |
pygame.init() | |
size = width, height = 400,600 | |
screen = pygame.display.set_mode(size) | |
picked_letter = [] | |
class Tetris_Maker(pygame.sprite.Sprite): | |
def __init__(self, x, y, width, height, colour): | |
pygame.sprite.Sprite.__init__(self) | |
self.image = pygame.Surface([width, height]) | |
self.image.fill(colour) | |
self.rect = self.image.get_rect() | |
self.rect.x = x | |
self.rect.y = y | |
self.colour = colour | |
def letters(x): | |
if x == 0: | |
picked_letter.append([["X","X"], | |
["X","X"], | |
["X","X"], | |
["X","X"]]) | |
elif x == 1: | |
picked_letter.append([["X","O"], | |
["X","O"], | |
["X","O"], | |
["X","X"]]) | |
width_divide = width / 40 | |
height_divide = height / 50 | |
Tetris_blocks = pygame.sprite.Group() | |
red = 255,0,0 | |
blue = 0,0,255 | |
black = 0,0,0 | |
count = 0 | |
YBegin = [] | |
XBegin = [] | |
adder = 0 | |
recent = pygame.sprite.Group() | |
i = 0 | |
while True: | |
Tetris_blocks.empty() | |
del picked_letter[:] | |
x = random.randint(0,1) | |
letters(x) | |
time.sleep(2) | |
if len(Tetris_blocks) == 0: | |
for box in picked_letter: | |
for x, row in enumerate(box): | |
for y, cell in enumerate(row): | |
print cell | |
if cell == "X": | |
new_block = Tetris_Maker(width_divide*y, height_divide*x, width_divide, height_divide, blue) | |
Tetris_blocks.add(new_block) | |
XBegin.append(x) | |
elif cell == "O": | |
new_block = Tetris_Maker(width_divide*y, height_divide*x, width_divide, height_divide, black) | |
Tetris_blocks.add(new_block) | |
XBegin.append(x) | |
recent.add(new_block) | |
while True: | |
for box in picked_letter: | |
for x, row in enumerate(box): | |
for y, cell in enumerate(row): | |
screen.fill(black) | |
if cell == "X": | |
x += 1 | |
new_block = Tetris_Maker(width_divide*y, height_divide*x, width_divide, height_divide, blue) | |
Tetris_blocks.add(new_block) | |
elif cell == "O": | |
x += 1 | |
new_block = Tetris_Maker(width_divide*y, height_divide*x, width_divide, height_divide, black) | |
Tetris_blocks.add(new_block) | |
i += 1 | |
Tetris_blocks.draw(screen) | |
pygame.display.update() | |
time.sleep(1) | |
if x == 8: | |
break | |
recent.empty() | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
sys.exit() | |
Tetris_blocks.draw(screen) | |
pygame.display.update() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment