top of page

소스 코드 제출

공개·회원 81명

251022

# import pygame

# pygame.init()

#

# WHITE = (255,255,255)

# BLACK = (61,78,199)

# size = [1000,600]

# screen =pygame.display.set_mode(size)

#

# done = False

# clock = pygame.time.Clock()

#

# def runGame():

# global done

#

# screen_width = size[0]

# screen_height = size[1]

#

# bar_width = 9

# bar_height = 125

#

# bar_x = bar_start_x = 0

# bar_y = bar_start_y =(screen_height - bar_height) / 2

#

# circle_radius = 15

# circle_diameter = circle_radius * 2

#

# circle_x = circle_start_x = screen_width - circle_diameter

# circle_y = circle_start_y = (screen_width - circle_diameter) / 2

#

# bar_move = 0

# speed_x,speed_y,speed_bar = -screen_width / 1.28, screen_height/1.92,screen_height * 1.2

#

#

#

# while not done:

# time_passed = clock.tick(30)

# time_sec = time_passed/1000.0

# screen.fill(BLACK)

#

# circle_x += speed_x * time_sec

# circle_y += speed_y * time_sec

# ai_speed = speed_bar * time_sec

#

#

# for event in pygame.event.get():

# if event.type == pygame.QUIT:

# done = True

# break

# if event.type == pygame.KEYDOWN:

# if event.key == pygame.K_UP:

# bar_move = -ai_speed

# elif event.key == pygame.K_DOWN:

# bar_move = ai_speed

# elif event.type == pygame.KEYUP:

# if event.key == pygame.K_UP:

# bar_move = 0

# elif event.key == pygame.K_DOWN:

# bar_move = 0

# bar_y += bar_move

#

# if bar_y >= screen_height:

# bar_y = screen_height

# elif bar_y <= 0:

# bar_y =0

# if circle_x < bar_width:

# if circle_y >= bar_y - circle_radius and circle_y <= bar_y + bar_height + circle_radius:

# circle_x = bar_width

# speed_x = -speed_x

# if circle_x < - circle_radius:

# circle_x,circle_y = circle_start_x,circle_start_y

# bar_x,bar_y = bar_start_x,bar_start_y

# elif circle_x > screen_width - circle_diameter:

# speed_x = -speed_x

# if circle_y <= 0:

# speed_y = -speed_y

# circle_y = 0

# elif circle_y >= screen_height - circle_diameter:

# speed_y = -speed_y

# circle_y = screen_height - circle_diameter

#

# pygame.draw.rect(screen,

# WHITE,

# (bar_x, bar_y,int(bar_width),int(bar_height)))

# pygame.draw.circle(screen,

# WHITE,

# (int(circle_x),int(circle_y)),

# int(circle_radius))

#

# pygame.display.update()

#

#

# runGame()

# pygame.quit()

#

import pygame

pygame.init()

import time



BLACK = (0,0,0)

RED = (255,0,0)

GREEN = (0,255,0)

BLUE = (0,0,255)

WHITE = (255,255,255)

YELLOW = (255,255,0)

large_font = pygame.font.SysFont(None,72)

small_font = pygame.font.SysFont(None,36)

screen_width = 600

screen_height = 800

screen = pygame.display.set_mode((screen_width,screen_height))


clock = pygame.time. Clock()



def runGame():

score = 0

missed = 0

SUCCESS = 1

FAILURE = 2

game_over = 0


bricks = []

COLUMN_COUNT = 8

ROW_COUNT = 7

for column_index in range(COLUMN_COUNT):

for row_index in range(ROW_COUNT):

brick = pygame.Rect(column_index*(60+10)+35,row_index * (16+5)+35,60,16)

bricks.append(brick)

ball = pygame.Rect(screen_width // 2 -16 // 2,screen_height // 2 - 16 // 2,16,16)

ball_dx = 5

ball_dy = -5


paddle = pygame.Rect(screen_width // 2 - 80 // 2, screen_height -16 ,120,16)

paddle_dx = 0

while True:

clock.tick(150)

screen.fill(BLACK)


for event in pygame.event.get():

if event.type == pygame.QUIT:

break

elif event.type == pygame.KEYDOWN:

if event.key == pygame.K_LEFT:

paddle_dx = -10

elif event.key == pygame.K_RIGHT:

paddle_dx = 10

elif event.type == pygame.KEYUP:

if event.key == pygame.K_LEFT:

paddle_dx = 0

elif event.key == pygame.K_RIGHT:

paddle_dx =0

paddle.left += paddle_dx


ball.left += ball_dx

ball.top += ball_dy


if ball.left <= 0:

ball.left = 0

ball_dx = -ball_dx

elif ball.left >= screen_width - ball.width:

ball.left = screen_width - ball.width

ball_dx = -ball_dx

if ball.top < 0:

ball.top = 0

ball_dy = -ball_dy

elif ball.top >= screen_height:

missed += 1

ball.left = screen_width // 2 - ball.width // 2

ball.top = screen_height // 2 - ball.width // 2

ball_dy = -ball_dy


if missed >= 3:

game_over = FAILURE


if paddle.left < 0:

paddle.left = 0

elif paddle.left > screen_width - paddle.width:

paddle.left = screen_width - paddle.width


for brick in bricks:

if ball.colliderect(brick):

bricks.remove(brick)

ball_dy = -ball_dy

score += 1

break


if ball.colliderect(paddle):

ball_dy = -ball_dy

if ball.centerx <= paddle.left or ball.centerx > paddle.right:

ball_dx = ball_dx * -1



if len(brick) == 0:

print('success')

game_over = SUCCESS


for brick in bricks:

pygame.draw.rect(screen,GREEN,brick)


if game_over == 0:

pygame.draw.circle(screen, WHITE ,(ball.centerx, ball.centery), ball.width // 2)


pygame.draw.rect(screen,BLUE, paddle)


score_image = small_font.render('Point {}'.format(score), True, YELLOW)

screen.blit(score_image,(10,10))


missed_image = small_font.render('Missed {}'.format(missed), True, YELLOW)

screen.blit(missed_image, missed_image.get_rect(right=screen_width - 10, top=10))


if game_over > 0:

if game_over == SUCCESS:

success_image = large_font.render('성공', True , RED)

screen.blit(success_image, success_image.get_rect(centerx=screen_width // 2, centery = screen_height // 2))

elif game_over == FAILURE:

failure_image = large_font.render('실패', True , RED)

screen.blit(failure_image,failure_image.get_rect(centrex=screen_width // 2, centery =screen_height // 2))


pygame.display.update()



runGame()

pygame.quit()

19회 조회
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546 ,     031) 215 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호
bottom of page