import pygame
import random
import math
# pygame setup
pygame.init()
screen = pygame.display.set_mode((1280, 720))
clock = pygame.time.Clock()
running = True
teduri = pygame.Rect(340,60,600,600)
suatja =[[0 for i in range(4)] for i in range(4)]
sp = [2,2,2,2,2,2,2,2,2,4]
normalFont = pygame.font.SysFont(None,50)
box_color=["#CCCC77","#DDDD88"]
def randomSpawn():
y = random.randrange(0,4)
x = random.randrange(0,4)
if suatja[y][x]==0:
suatja[y][x] = random.choice(sp)
else:
return randomSpawn()
#def banghwang(i):
# for i in range(4)
#
for i in range(2):
randomSpawn()
print(suatja)
while running:
# poll for events
# pygame.QUIT event means the user clicked X to close your window
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
#for i in range(4):
randomSpawn()
print("up")
elif event.key == pygame.K_DOWN:
randomSpawn()
print("down")
elif event.key == pygame.K_LEFT:
randomSpawn()
print("left")
elif event.key == pygame.K_RIGHT:
randomSpawn()
print("right")
# fill the screen with a color to wipe away anything from last frame
screen.fill("#AAAA99")
pygame.draw.rect(screen,"#FFFFAA",teduri,0,10)
for i in range(4):
for j in range(4):
if suatja[i][j]==0:
pygame.draw.rect(screen,"#EEEEAA",(350+146*j,70+146*i,142,142),0,5)
else:
pygame.draw.rect(screen,box_color[int(math.log2(suatja[i][j])-1)],(350+146*j,70+146*i,142,142),0,5)
text = normalFont.render("%d"%suatja[i][j],True,(0,0,0))
screen.blit(text,(410+146*j,125+146*i))
# flip() the display to put your work on screen
pygame.display.flip()
clock.tick(60) # limits FPS to 60
pygame.quit()top of page

실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
asdf
asdf
댓글 0개
좋아요
댓글(0)
더 이상 게시물에 대한 댓글 기능이 지원되지 않습니다. 자세한 사항은 사이트 소유자에게 문의하세요.
bottom of page


