From 897dc374bfa0412f790a34c6cab217b7a5dc5a27 Mon Sep 17 00:00:00 2001 From: OFF-0-1 Date: Thu, 21 Jan 2021 00:52:41 +0900 Subject: [PATCH 1/9] =?UTF-8?q?=EB=A0=88=EB=B2=A8=EB=B3=84=20=EC=86=8D?= =?UTF-8?q?=EB=8F=84=20=EC=A1=B0=EC=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/snake.py b/snake.py index 14fd8c97..848d973c 100644 --- a/snake.py +++ b/snake.py @@ -12,6 +12,9 @@ rows = 20 +clock = pygame.time.Clock() + + class cube(): rows = 20 w = 500 @@ -88,7 +91,10 @@ def move(self): self.turns.pop(p) else: c.move(c.dirnx,c.dirny) - + + level = int(len(self.body) / 5) + fps = 6 + (1.5*level) + clock.tick(fps) def reset(self,pos): self.head = cube(pos) From b89ed3d72a9e15b7b7f0eefa801186730482d5b4 Mon Sep 17 00:00:00 2001 From: hjver123 Date: Thu, 21 Jan 2021 01:03:21 +0900 Subject: [PATCH 2/9] =?UTF-8?q?=EB=A7=88=EC=A7=80=EB=A7=89=20=EB=A0=88?= =?UTF-8?q?=EB=B2=A8=20=EB=8F=84=EB=8B=AC=EC=8B=9C,=20=EC=A2=85=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/snake.py b/snake.py index 14fd8c97..a0584ffc 100644 --- a/snake.py +++ b/snake.py @@ -120,6 +120,10 @@ def draw(self, surface): c.draw(surface, True) else: c.draw(surface) + + def end_game(): + print("Score:", len(self.body)) + sys.exit(0) @@ -189,7 +193,10 @@ def main(): print("Score:", len(s.body)) s.reset((10,10)) break - + + if len(s.body) > 25: + end_game() + redrawWindow() main() From 715dfa723f7d6c464f70a2abfc170073907795b0 Mon Sep 17 00:00:00 2001 From: hjver123 Date: Thu, 21 Jan 2021 01:35:38 +0900 Subject: [PATCH 3/9] =?UTF-8?q?25=EB=A0=88=EB=B2=A8=20=EB=8B=AC=EC=84=B1?= =?UTF-8?q?=EC=8B=9C,=20=EC=A2=85=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snake.py b/snake.py index a0584ffc..256653a1 100644 --- a/snake.py +++ b/snake.py @@ -194,7 +194,7 @@ def main(): s.reset((10,10)) break - if len(s.body) > 25: + if len(s.body) > 25: end_game() redrawWindow() From e5c9514810a4221a4e63e66dfd1567e27a244efa Mon Sep 17 00:00:00 2001 From: 0uni <2303h@naver.com> Date: Thu, 21 Jan 2021 02:06:09 +0900 Subject: [PATCH 4/9] =?UTF-8?q?=EA=B2=8C=EC=9E=84=20=EC=8B=9C=EC=9E=91=20?= =?UTF-8?q?=EC=A0=84=20=EC=9C=88=EB=8F=84=EC=9A=B0=20=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 --- snake.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/snake.py b/snake.py index 2b6702ae..ed747590 100644 --- a/snake.py +++ b/snake.py @@ -4,6 +4,7 @@ import random import tkinter as tk from tkinter import messagebox +from tkinter import * width = 500 height = 500 @@ -14,6 +15,14 @@ clock = pygame.time.Clock() +win=Tk() +win.title("NEW Snake Game") +win.resizable(500,500) + +label1=Label(win, text="Game Start",width=30,height=5,fg="blue",relief="solid") +label1.pack() + +win.mainloop() class cube(): rows = 20 From 5b2d0b7687493a3ca8da63cd7c95b36c6fb75269 Mon Sep 17 00:00:00 2001 From: 0uni <2303h@naver.com> Date: Thu, 21 Jan 2021 02:43:17 +0900 Subject: [PATCH 5/9] =?UTF-8?q?=EC=9C=88=EB=8F=84=EC=9A=B0=EC=B0=BD=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snake.py b/snake.py index ed747590..d069732a 100644 --- a/snake.py +++ b/snake.py @@ -19,7 +19,7 @@ win.title("NEW Snake Game") win.resizable(500,500) -label1=Label(win, text="Game Start",width=30,height=5,fg="blue",relief="solid") +label1=Label(win, text="Game Start\nLet's go",width=30,height=5,fg="blue",relief="solid") label1.pack() win.mainloop() From 70ee4c96be079fdbd5dd421ceb715807c0363f87 Mon Sep 17 00:00:00 2001 From: OFF-0-1 Date: Thu, 21 Jan 2021 14:05:40 +0900 Subject: [PATCH 6/9] =?UTF-8?q?=EC=A0=90=EC=88=98=ED=8C=90=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 --- snake.py | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/snake.py b/snake.py index b7260bdf..8a3c3021 100644 --- a/snake.py +++ b/snake.py @@ -4,6 +4,9 @@ import random import tkinter as tk from tkinter import messagebox +from tkinter import * + +pygame.init() width = 500 height = 500 @@ -11,9 +14,25 @@ cols = 25 rows = 20 +WINDOW_WIDTH = 500 +WINDOW_HEIGHT = 500 +GRID = 30 +GRID_WIDTH = int(WINDOW_WIDTH/GRID) +GRID_HEIGHT = int(WINDOW_HEIGHT/GRID) clock = pygame.time.Clock() +screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) + + + +win=Tk() +win.title("NEW Snake Game") +win.resizable(500,500) + +label1=Label(win, text="Game Start\nLet's go",width=30,height=5,fg="blue",relief="solid") +label1.pack() +win.mainloop() class cube(): rows = 20 @@ -28,14 +47,23 @@ def move(self, dirnx, dirny): self.dirnx = dirnx self.dirny = dirny self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny) - + + def draw(self, surface, eyes=False): dis = self.w // self.rows i = self.pos[0] j = self.pos[1] - - pygame.draw.rect(surface, self.color, (i*dis+1,j*dis+1,dis-2,dis-2)) + + screen = pygame.draw.rect(surface, self.color, (i*dis+1,j*dis+1,dis-2,dis-2)) + + font = pygame.font.SysFont('malgungothic',35) + image = font.render(f' 점수: {111} ', True, (255,255,255)) + pos = image.get_rect() + pos.move_ip(20,20) + pygame.draw.rect(image, (255,255,255),(pos.x-20, pos.y-20, pos.width, pos.height), 2) + surface.blit(image, pos) + if eyes: centre = dis//2 radius = 3 @@ -43,8 +71,8 @@ def draw(self, surface, eyes=False): circleMiddle2 = (i*dis + dis -radius*2, j*dis+8) pygame.draw.circle(surface, (0,0,0), circleMiddle, radius) pygame.draw.circle(surface, (0,0,0), circleMiddle2, radius) - + class snake(): body = [] @@ -131,6 +159,13 @@ def end_game(): print("Score:", len(self.body)) sys.exit(0) + def show_info(self, surface): + font = pygame.font.SysFont('malgungothic',35) + image = font.render(f' 점수: {len(self.body)} ', True, (255,255,255)) + pos = image.get_rect() + pos.move_ip(20,20) + pygame.draw.rect(image, (255,255,255),(pos.x-20, pos.y-20, pos.width, pos.height), 2) + surface.blit(image, pos) def redrawWindow(): @@ -143,7 +178,6 @@ def redrawWindow(): pass - def drawGrid(w, rows, surface): sizeBtwn = w // rows @@ -155,7 +189,6 @@ def drawGrid(w, rows, surface): pygame.draw.line(surface, (255,255,255), (x, 0),(x,w)) pygame.draw.line(surface, (255,255,255), (0, y),(w,y)) - def randomSnack(rows, item): @@ -181,6 +214,8 @@ def main(): flag = True clock = pygame.time.Clock() + s.show_info(screen) + while flag: pygame.time.delay(50) clock.tick(10) @@ -200,12 +235,10 @@ def main(): s.reset((10,10)) break - if len(s.body) > 25: + if len(s.body) > 25: end_game() redrawWindow() main() - - From d778f2152602a8f44b3113c6ace192fd3eb382ba Mon Sep 17 00:00:00 2001 From: 0uni <2303h@naver.com> Date: Thu, 21 Jan 2021 15:21:16 +0900 Subject: [PATCH 7/9] =?UTF-8?q?=EA=B2=8C=EC=9E=84=EC=8B=9C=EC=9E=91=20?= =?UTF-8?q?=EC=A0=84=20=EC=9C=88=EB=8F=84=EC=9A=B0=EC=B0=BD=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=20=EC=B6=94=EA=B0=80=EC=99=80=20=EC=A2=85=EB=A3=8C?= =?UTF-8?q?=EC=8B=9C=20=EC=9C=88=EB=8F=84=EC=9A=B0=EC=B0=BD=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/snake.py b/snake.py index 89c15f8b..ce1ddee6 100644 --- a/snake.py +++ b/snake.py @@ -3,7 +3,6 @@ import pygame import random import tkinter as tk -from tkinter import messagebox from tkinter import * pygame.init() @@ -26,14 +25,17 @@ -win=Tk() -win.title("NEW Snake Game") -win.resizable(500,500) +window=Tk() +window.title("NEW Snake Game") +window.geometry('300x100+470+200') -label1=Label(win, text="Game Start\nLet's go",width=30,height=5,fg="blue",relief="solid") +label1=Label(window, text="Game Start\nLet's go",width=30,height=5,fg="blue",relief="solid") label1.pack() -win.mainloop() +b1=Button(window,text="시작하기",width=10,height=5,bg='yellow',command = window.destroy) +b1.pack() + +window.mainloop() class cube(): rows = 20 @@ -169,6 +171,16 @@ def show_info(self, surface): surface.blit(image, pos) +def finish_game(): + fin=Tk() + fin.title("Full Levell") + fin.geometry('300x100+500+200') + label2=Label(fin, text="SUCCESS",width=30,height=5,fg="red",relief="solid") + label2.pack() + + fin.mainloop() + + def redrawWindow(): global win win.fill((0,0,0)) @@ -236,9 +248,10 @@ def main(): s.reset((10,10)) break - if len(s.body) > 25: + if len(s.body) > 5: + finish_game() end_game() - + redrawWindow() main() From 7022a2d3f8c2564b0fe6c66c9a3bb866f80c7e0b Mon Sep 17 00:00:00 2001 From: OFF-0-1 Date: Thu, 21 Jan 2021 16:02:46 +0900 Subject: [PATCH 8/9] =?UTF-8?q?=EC=A0=90=EC=88=98=ED=8C=90=20=EC=99=84?= =?UTF-8?q?=EC=84=B1,=20=EB=B0=B0=EA=B2=BD=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake.py | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/snake.py b/snake.py index 8a3c3021..a1f16707 100644 --- a/snake.py +++ b/snake.py @@ -3,26 +3,16 @@ import pygame import random import tkinter as tk -from tkinter import messagebox from tkinter import * -pygame.init() - width = 500 height = 500 - cols = 25 rows = 20 -WINDOW_WIDTH = 500 -WINDOW_HEIGHT = 500 -GRID = 30 -GRID_WIDTH = int(WINDOW_WIDTH/GRID) -GRID_HEIGHT = int(WINDOW_HEIGHT/GRID) - +pygame.init() clock = pygame.time.Clock() -screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) - +background = pygame.display.set_mode((width, height)) win=Tk() @@ -34,6 +24,7 @@ win.mainloop() + class cube(): rows = 20 w = 500 @@ -47,7 +38,6 @@ def move(self, dirnx, dirny): self.dirnx = dirnx self.dirny = dirny self.pos = (self.pos[0] + self.dirnx, self.pos[1] + self.dirny) - def draw(self, surface, eyes=False): @@ -57,13 +47,6 @@ def draw(self, surface, eyes=False): screen = pygame.draw.rect(surface, self.color, (i*dis+1,j*dis+1,dis-2,dis-2)) - font = pygame.font.SysFont('malgungothic',35) - image = font.render(f' 점수: {111} ', True, (255,255,255)) - pos = image.get_rect() - pos.move_ip(20,20) - pygame.draw.rect(image, (255,255,255),(pos.x-20, pos.y-20, pos.width, pos.height), 2) - surface.blit(image, pos) - if eyes: centre = dis//2 radius = 3 @@ -159,36 +142,37 @@ def end_game(): print("Score:", len(self.body)) sys.exit(0) - def show_info(self, surface): - font = pygame.font.SysFont('malgungothic',35) - image = font.render(f' 점수: {len(self.body)} ', True, (255,255,255)) + def show_info(self): + font = pygame.font.SysFont('malgungothic',30) + image = font.render(f' Lv.: {len(self.body)} ', True, (0,0,0)) pos = image.get_rect() pos.move_ip(20,20) - pygame.draw.rect(image, (255,255,255),(pos.x-20, pos.y-20, pos.width, pos.height), 2) - surface.blit(image, pos) + pygame.draw.rect(image, (0,0,0),(pos.x-20, pos.y-20, pos.width, pos.height), 2) + background.blit(image, pos) def redrawWindow(): global win - win.fill((0,0,0)) + win.fill((176,224,230)) drawGrid(width, rows, win) s.draw(win) snack.draw(win) + s.show_info() pygame.display.update() pass - def drawGrid(w, rows, surface): - sizeBtwn = w // rows + sizeBtwn = w // rows x = 0 y = 0 + for l in range(rows): x = x + sizeBtwn y = y +sizeBtwn - pygame.draw.line(surface, (255,255,255), (x, 0),(x,w)) - pygame.draw.line(surface, (255,255,255), (0, y),(w,y)) + pygame.draw.line(surface, (150,150,150), (x, 0),(x,w)) + pygame.draw.line(surface, (150,150,150), (0, y),(w,y)) def randomSnack(rows, item): @@ -213,14 +197,13 @@ def main(): snack = cube(randomSnack(rows,s), color=(0,255,0)) flag = True clock = pygame.time.Clock() - - s.show_info(screen) - + while flag: pygame.time.delay(50) clock.tick(10) s.move() headPos = s.head.pos + if headPos[0] >= 20 or headPos[0] < 0 or headPos[1] >= 20 or headPos[1] < 0: print("Score:", len(s.body)) s.reset((10, 10)) From 92932c1b70f380daf3ff018ce42ec90b72b7ad5e Mon Sep 17 00:00:00 2001 From: hjver123 Date: Thu, 21 Jan 2021 22:35:43 +0900 Subject: [PATCH 9/9] =?UTF-8?q?=EB=A0=88=EB=B2=A8=20=ED=81=B4=EB=A6=AC?= =?UTF-8?q?=EC=96=B4=20=EA=B9=8C=EC=A7=80=20total=20time=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake.py | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/snake.py b/snake.py index 4a4e960f..8e5cdcf3 100644 --- a/snake.py +++ b/snake.py @@ -6,10 +6,10 @@ from tkinter import * -width = 500 -height = 500 +width = 700 +height = 700 cols = 25 -rows = 20 +rows = 25 pygame.init() clock = pygame.time.Clock() @@ -30,12 +30,12 @@ class cube(): - rows = 20 - w = 500 + rows = 25 + w = 700 def __init__(self, start, dirnx=1, dirny=0, color=(255,0,0)): self.pos = start self.dirnx = dirnx - self.dirny = dirny # "L", "R", "U", "D" + self.dirny = dirny self.color = color def move(self, dirnx, dirny): @@ -49,7 +49,7 @@ def draw(self, surface, eyes=False): i = self.pos[0] j = self.pos[1] - screen = pygame.draw.rect(surface, self.color, (i*dis+1,j*dis+1,dis-2,dis-2)) + pygame.draw.rect(surface, self.color, (i*dis+1,j*dis+1,dis-2,dis-2)) if eyes: centre = dis//2 @@ -66,7 +66,6 @@ class snake(): turns = {} def __init__(self, color, pos): - #pos is given as coordinates on the grid ex (1,5) self.color = color self.head = cube(pos) self.body.append(self.head) @@ -145,22 +144,26 @@ def draw(self, surface): def end_game(): print("Score:", len(self.body)) sys.exit(0) + def show_info(self): - font = pygame.font.SysFont('malgungothic',30) - image = font.render(f' Lv.: {len(self.body)} ', True, (0,0,0)) + font = pygame.font.SysFont('malgungothic',30,bold=5) + image = font.render(f' {len(self.body)} .Lv ', True, (0,0,0)) pos = image.get_rect() pos.move_ip(20,20) - pygame.draw.rect(image, (0,0,0),(pos.x-20, pos.y-20, pos.width, pos.height), 2) + pygame.draw.rect(image, (0,0,0),(pos.x-15, pos.y-15, pos.width, pos.height), 2) background.blit(image, pos) -def finish_game(): +def finish_game(seconds): fin=Tk() - fin.title("Full Levell") + fin.title("Full Level") fin.geometry('300x100+500+200') - label2=Label(fin, text="SUCCESS",width=30,height=5,fg="red",relief="solid") + b=int(seconds) + print ("Total Time :", b) + label2=Label(fin, text="SUCCESS\nTotal Time :"+str(b),width=30,height=5,fg="red",relief="solid") label2.pack() + fin.mainloop() @@ -204,21 +207,24 @@ def randomSnack(rows, item): def main(): - global s, snack, win + global s, snack, win, b win = pygame.display.set_mode((width,height)) s = snake((255,0,0), (10,10)) s.addCube() snack = cube(randomSnack(rows,s), color=(0,255,0)) flag = True clock = pygame.time.Clock() + start_ticks=pygame.time.get_ticks() + while flag: pygame.time.delay(50) clock.tick(10) s.move() headPos = s.head.pos + seconds=(pygame.time.get_ticks()-start_ticks)/1000 - if headPos[0] >= 20 or headPos[0] < 0 or headPos[1] >= 20 or headPos[1] < 0: + if headPos[0] >= 25 or headPos[0] < 0 or headPos[1] >= 25 or headPos[1] < 0: print("Score:", len(s.body)) s.reset((10, 10)) @@ -231,12 +237,13 @@ def main(): print("Score:", len(s.body)) s.reset((10,10)) break - - if len(s.body) > 5: - finish_game() + + + if len(s.body) > 25: + finish_game(seconds) end_game() redrawWindow() main() - + \ No newline at end of file