From 2b4b2f9866d178eed75c1ba5ee87359da2714100 Mon Sep 17 00:00:00 2001 From: chaelimee Date: Wed, 4 Oct 2023 17:19:21 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=EA=B2=8C=EC=9E=84=EC=B0=BD=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- G-snake.py | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/G-snake.py b/G-snake.py index d513843839ef5..2fe2fb0d0bb49 100644 --- a/G-snake.py +++ b/G-snake.py @@ -1,28 +1,15 @@ # Make G-snake.py import pygame -#게임 화면의 크기, 색상 등을 정의 -white = (255, 255, 255) -black = (0, 0, 0) -red = (213, 50, 80) -green = (0, 255, 0) -blue = (50, 153, 213) - -display_width = 600 -display_height = 400 - -dis = pygame.display.set_mode((display_width, display_height)) -pygame.display.set_caption('Snake Game') - -#뱀과 먹이를 정의 -snake_block = 10 -snake_speed = 15 -x1 = display_width / 2 -y1 = display_height / 2 -x1_change = 0 -y1_change = 0 -snake_List = [] -Length_of_snake = 1 - -foodx = round(random.randrange(0, display_width - snake_block) / 10.0) * 10.0 -foody = round(random.randrange(0, display_height - snake_block) / 10.0) * 10.0 +pygame.init() +dis=pygame.display.set_mode((800,600)) +pygame.display.update() +pygame.display.set_caption('Snake game') +game_over=False +while not game_over: + for event in pygame.event.get(): + if event.type==pygame.QUIT: + game_over=True + +pygame.quit() +quit() \ No newline at end of file From f55966a62cf4c809cecd54625478974dc06c937c Mon Sep 17 00:00:00 2001 From: chaelimee Date: Wed, 4 Oct 2023 17:30:51 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EC=B0=BD=20=EC=83=9D=EC=84=B1.=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=20=EB=B1=80=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- G-snake.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/G-snake.py b/G-snake.py index 2fe2fb0d0bb49..2ff741538bf30 100644 --- a/G-snake.py +++ b/G-snake.py @@ -1,15 +1,53 @@ # Make G-snake.py import pygame +#게임창 생성 pygame.init() + +white = (255, 255, 255) +black = (0, 0, 0) +red = (255, 0, 0) + dis=pygame.display.set_mode((800,600)) pygame.display.update() pygame.display.set_caption('Snake game') + game_over=False + +x1 = 400 +y1 = 300 + +x1_change = 0 +y1_change = 0 + +clock = pygame.time.Clock() + while not game_over: for event in pygame.event.get(): if event.type==pygame.QUIT: game_over=True + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + x1_change = -10 + y1_change = 0 + elif event.key == pygame.K_RIGHT: + x1_change = 10 + y1_change = 0 + elif event.key == pygame.K_UP: + y1_change = -10 + x1_change = 0 + elif event.key == pygame.K_DOWN: + y1_change = 10 + x1_change = 0 + + x1 += x1_change + y1 += y1_change + dis.fill(white) + pygame.draw.rect(dis, black, [x1, y1, 10, 10]) + + pygame.display.update() + + clock.tick(30) pygame.quit() quit() \ No newline at end of file From 6f3236ac5dd89a8032fe6a3e9a35c00752a536fe Mon Sep 17 00:00:00 2001 From: chaelimee Date: Wed, 11 Oct 2023 17:12:09 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EB=B2=94=EC=9C=84=EB=A5=BC=20=EB=B2=97?= =?UTF-8?q?=EC=96=B4=EB=82=AC=EC=9D=84=20=EB=95=8C=20=EA=B2=8C=EC=9E=84?= =?UTF-8?q?=EC=98=A4=EB=B2=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- G-snake.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/G-snake.py b/G-snake.py index 2ff741538bf30..dc467f15cb4df 100644 --- a/G-snake.py +++ b/G-snake.py @@ -8,19 +8,29 @@ black = (0, 0, 0) red = (255, 0, 0) -dis=pygame.display.set_mode((800,600)) -pygame.display.update() +dis_width=800 +dis_height=600 +dis=pygame.display.set_mode((dis_width,dis_height)) pygame.display.set_caption('Snake game') game_over=False -x1 = 400 -y1 = 300 - +x1=dis_width/2 +y1=dis_height/2 + +snake_block=10 + x1_change = 0 y1_change = 0 clock = pygame.time.Clock() +snake_speed=30 + +font_style=pygame.font.SysFont(None, 50) + +def message(msg,color): + mesg=font_style.render(msg, True, color) + dis.blit(mesg, [dis_width/2, dis_height/2]) while not game_over: for event in pygame.event.get(): @@ -28,18 +38,19 @@ game_over=True if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: - x1_change = -10 + x1_change = -snake_block y1_change = 0 elif event.key == pygame.K_RIGHT: - x1_change = 10 + x1_change = snake_block y1_change = 0 elif event.key == pygame.K_UP: - y1_change = -10 + y1_change = -snake_block x1_change = 0 elif event.key == pygame.K_DOWN: - y1_change = 10 + y1_change = snake_block x1_change = 0 + x1 += x1_change y1 += y1_change dis.fill(white) @@ -47,7 +58,11 @@ pygame.display.update() - clock.tick(30) + clock.tick(snake_speed) +message("You lost", red) +pygame.display.update() +time.sleep(2) + pygame.quit() quit() \ No newline at end of file