here is my code but i guess the problem is mainly in my python
import random
import curses
screen=curses.initscr()
# Initialize curses
screen = curses.initscr()
curses.curs_set(0)
screen_height,screen_width= screen.getmaxyx()
window=curses.newwin(screen_height,screen_width,0,0)
window.keypad(1) #allow window to take input
window.timeout(100)
snk_x=screen_width//4
snk_y=screen_height//2
snake=[
[snk_y,snk_x],
[snk_y,snk_x-1],
[snk_y,snk_x-2],
]
food=[screen_width//2,screen_height//2]
window.addch(food[0],food[1],curses.ACS_PI)
key=curses.KEY_RIGHT
while True:
next_key=window.getch()
key=key if next_key==-1 else next_key
if snake[0][0]in [screen_height,0] or snake[0][1] in [screen_width,0] or snake[0] in snake[1:]:
break
new_head=[snake[0][0],snake[0][1]]
if key==curses.KEY_UP:
new_head[0]-= 1
if key==curses.KEY_DOWN:
new_head[0]+= 1
if key==curses.KEY_RIGHT:
new_head[1]+= 1
if key==curses.KEY_LEFT:
new_head[1]-= 1
snake.insert(0,new_head)
if snake[0]==food:
food=None
while food==None:
new_food=[
random.randint(1,screen_width-1),
random.randint(1,screen_height-1)
]
food=new_food if new_food not in snake else None
window.addch(food[0],food[1],curses.ACS_PI)
else:
tail=snake.pop()
window.addch(tail[0],tail[1],' ')
window.addch(snake[0][0],snake[0][1],curses.ACS_CKBOARD)
curses.endwin()
quit()
i have tried installing curses from my terminal and i tried installing python again but it didn’t work i also got to a point where it worked well but stopped at the addch function
New contributor
Mariaa Ik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.