-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (53 loc) · 2.29 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pygame as pg
import sys
import random
from tetris_container import *
from constants import *
from pygame.locals import QUIT
class Tetris:
def __init__(self):
pg.init()
self.font = pg.font.SysFont('arial', 10, bold = True)
self.clock = pg.time.Clock()
def run(self):
#Intro Screen ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pg.display.set_caption("Tetris")
win.fill((0,0,0))
label = self.font.render("Welcome to Tetris", 1, (255,255,255))
win.blit(label, (TOP_LEFT[0] + GRID_WIDTH /2 - (label.get_width()/2), TOP_LEFT[1] + GRID_HEIGHT/2 - label.get_height()))
pg.display.update()
pg.time.delay(3000)
win.fill((30,30,30))
label = self.font.render("Use the Down, Left, and Right arrow keys to move your tetrimino around.", 1, (255,255,255))
win.blit(label, (TOP_LEFT[0] + GRID_WIDTH /2 - (label.get_width()/2), TOP_LEFT[1] + GRID_HEIGHT/2 - label.get_height()))
pg.display.update()
pg.time.delay(3000)
win.fill((20,20,20))
label = self.font.render("Use the Up arrow key to rotate your Tetrimino", 1, (255,255,255))
win.blit(label, (TOP_LEFT[0] + GRID_WIDTH /2 - (label.get_width()/2), TOP_LEFT[1] + GRID_HEIGHT/2 - label.get_height()))
pg.display.update()
pg.time.delay(3000)
win.fill((10,10,10))
label = self.font.render("Use Space to instantly place your Tetrimino", 1, (255,255,255))
win.blit(label, (TOP_LEFT[0] + GRID_WIDTH /2 - (label.get_width()/2), TOP_LEFT[1] + GRID_HEIGHT/2 - label.get_height()))
pg.display.update()
pg.time.delay(4500)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
while True:
self.clock.tick(40)
win.fill((0,0,0))
label = pg.font.SysFont('arial', 20, bold = True).render("Press any key to play, press 'T' to enter testing mode", 1, (255,255,255))
win.blit(label, (TOP_LEFT[0] + GRID_WIDTH /2 - (label.get_width()/2), TOP_LEFT[1] + GRID_HEIGHT/2 - label.get_height()))
for event in pg.event.get():
if event.type == QUIT:
pg.quit()
sys.quit()
elif event.type == pg.KEYDOWN:
if event.key == pg.K_t:
run(win,True)
else:
print("Game Ran successfully")
run(win)
pg.display.update()
if __name__ == "__main__":
Tetris().run()