Ask coding questions

← Back to all posts
How do I get the snake to appear, thank you in advance! (only w and food appears)
Mel4

import random
import curses

s= curses.initscr()
curses.curs_set (0)
sh, sw = s.getmaxyx()
w = curses.newwin(sh, sw, 0, 0)
w.keypad(1)
w.timeout(100)

snk_x = sw//4
snk_y = sh//2
snake = [
[snk_y, snk_x],
[snk_y, snk_x-1],
[snk_y, snk_x-2]
]

food = [sh//2, sw//2]
w.addch(int(food[0]), int(food[1]), curses.ACS_PI)

key = curses.KEY_RIGHT

while True:
next_key = w.getch()
key = key if next_key == -1 else next_key

if snake[0] in [0, sh] or snake [0] in [0, sw] or snake [0] in snake [1:]:
curses.endwin ()
quit ()

else:
tail = snake.pop()
w.addch(tail[0], tail[1], ' ')

w.addch(snake[0], snake[0]. curses.ACS_CKBOARD)

Voters
Mel4
Comments
hotnewtop
BearCoder01

I think because, you need to append the snake in your list.