Skip to content

Commit b976224

Browse files
authored
Update Snake.py
1 parent 723d19f commit b976224

File tree

1 file changed

+0
-20
lines changed

1 file changed

+0
-20
lines changed

Juego Snake/Snake.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Juego Snake
22
# @autor: Magno Efren
33
# Youtube: https://www.youtube.com/c/MagnoEfren
4-
54
#print('🟢❤🍎🌍💛💚🧡🧡❤💥⚪🟥🟧🟨🟩🟦🟫🟪🔶🔸🔷🔹🔺🔻')
65

76
from tkinter import Tk, Frame, Canvas, Button,Label, IntVar, ALL
@@ -15,13 +14,10 @@
1514
posicion_food = (15,15)
1615
posicion_snake = [(75,75)]
1716
nueva_posicion =[(15,15)]
18-
1917
mixer.init()
2018

21-
2219
def coordenadas_snake():
2320
global direccion, posicion_snake,x,y ,nueva_posicion
24-
2521
if direction =='up': # arriba
2622
y = y-30
2723
nueva_posicion[0:] = [(x, y)]
@@ -50,15 +46,12 @@ def coordenadas_snake():
5046
x=15
5147
elif x <=0:
5248
x=15
53-
5449
posicion_snake = nueva_posicion + posicion_snake[:-1]
55-
5650
for parte, lugar in zip(canvas.find_withtag("snake"), posicion_snake):
5751
canvas.coords(parte, lugar)
5852

5953
def direccion(event):
6054
global direction
61-
6255
if event == 'left':
6356
if direction != 'right':
6457
direction = event
@@ -71,31 +64,22 @@ def direccion(event):
7164
elif event == 'down':
7265
if direction != 'up':
7366
direction = event
74-
7567
def movimiento():
7668
global posicion_food, posicion_snake,nueva_posicion
7769
posiciones = [15, 45, 75,105,135,165, 195, 225, 255,
7870
285, 315, 345, 375, 405, 435, 465]
79-
8071
coordenadas_snake()
81-
8272
if posicion_food == posicion_snake[0]:
8373
n = len(posicion_snake)
84-
8574
cantidad['text'] = 'Cantidad 🍎 : {}'.format(n)
86-
8775
posicion_food = (random.choice(posiciones), random.choice(posiciones))
8876
posicion_snake.append(posicion_snake[-1])
89-
9077
mixer.music.load("audio_snake.mp3")
9178
mixer.music.play(loops=0)
92-
9379
if posicion_food not in posicion_snake:
9480
canvas.coords(canvas.find_withtag("food"), posicion_food)
95-
9681
canvas.create_text(*posicion_snake[-1], text= '▀', fill='green2',
9782
font = ('Arial',20), tag ='snake')
98-
9983
if posicion_snake[-1] == nueva_posicion[0] and len(posicion_snake)>=4:
10084
cruzar_snake()
10185

@@ -105,7 +89,6 @@ def movimiento():
10589

10690
cantidad.after(300, movimiento)
10791

108-
10992
def cruzar_snake():
11093
canvas.delete(ALL)
11194
canvas.create_text(canvas.winfo_width() / 2, canvas.winfo_height() / 2,
@@ -122,7 +105,6 @@ def salir ():
122105
ventana.destroy()
123106
ventana.quit()
124107

125-
126108
ventana = Tk()
127109
ventana.config(bg='black')
128110
ventana.title('Juego Snake')
@@ -139,15 +121,13 @@ def salir ():
139121
ventana.bind("<KeyPress-Down>", lambda event:direccion('down'))
140122
ventana.bind("<KeyPress-Left>", lambda event:direccion('left'))
141123
ventana.bind("<KeyPress-Right>", lambda event:direccion('right'))
142-
143124
canvas = Canvas(frame_2, bg='black', width=479, height=479)
144125
canvas.pack()
145126

146127
for i in range(0,460,30):
147128
for j in range(0,460,30):
148129
canvas.create_rectangle(i,j,i+30, j+30, fill='gray10')
149130

150-
151131
canvas.create_text(75,75, text='🍎', fill='red2',
152132
font = ('Arial',18), tag = 'food')
153133

0 commit comments

Comments
 (0)