tetris example 1

This commit is contained in:
Mert Gör 🇹🇷 2023-07-15 13:47:34 +03:00
parent e157da5bbe
commit 5bc969328c
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9

39
python-temel/tetris.py Normal file
View File

@ -0,0 +1,39 @@
class Shape:
pass
class SquareShape(Shape):
def move_down(self):
print('SquareShape moves down')
class BarShape(Shape):
def move_down(self):
print('BarShape moves down')
class TShape(Shape):
def move_down(self):
print('TShape moves down')
class LShape(Shape):
def move_down(self):
print('LShape moves down')
class ZShape(Shape):
def move_down(self):
print('ZShape moves down')
import random
import time
class Tetris:
def get_random_shape(self):
return random.choice([ZShape, TShape, SquareShape, BarShape, LShape])()
def run(self):
while True:
shape = self.get_random_shape()
for i in range(20):
shape.move_down()
time.sleep(0.5)
tetris = Tetris()
tetris.run()