Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_curses not working
#1
So I'm very new to python, and I was trying to learn how to program a simple snake game after doing a bit of research. I think I got all the code right, but before I started, I saw I needed to install a "module" called Unicurses. So I installed it and it let me import the module. Everything seemed to be going fine, but when I tried to run the program, I got the error message "ModuleNotFoundError: No module named '_curses'". If anyone knows how to fix this, please let me know. Just be warned I am very unknowledgeable in this Python. Here is my code:

import random
import curses
s = curses.intscr()
curses.curs_set(0)
sh, sw = s.getmaxyx()
w = curses.newwin(sh, sw, 0, 0)
we.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(food[0], food[1], cursess.ACS_PI)

key = curses.KEY_RIGHT

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

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

new_head = [snake[0][0], smale [0][1]]

if key == curses.KEY_DOWN:
new_head[0] += 1
if key == curses.KEY_UP:
new_head[0] -= 1
if key == curses.KEY_LEFT:
new_head[1] -= 1
if key == curses.KEY_RIGHT:
new_head[1] += 1

snake.insert(0, new_head)

if snake[0] == food:
food = None
while food is None:
nf = [
random.randint(1, sh-1),
random.randint(1, sw-1)
]
food = nf if nf not in snake else None
w.addch(food[0], food[1], curses.ACS_PI)
else:
tail = snake.pop()
w.addch(tail[0], tail[1], ' ')

w.addch(snake[0][0], snake [0][1], curses.ACS_CKBOARD)
Reply
#2
You should try it with a Linux system, because Windows does not have curses.
Reply
#3
(Nov-09-2017, 02:31 PM)heiner55 Wrote: You should try it with a Linux system, because Windows does not have curses.
I have a Raspberry Pi but it doesn't seem to work anymore but it WAS running on Linux... Any way to make my computer run off of Linux instead of Windows?
Reply
#4
See https://www.virtualbox.org/
See https://linuxmint.com/
Reply
#5
first here in code is mistake "smale". you need to install curses. go to curses official page and read what to paste in cmd with admin rights. not sure, but maybe you should add folder with pip into env variables. ok-ok) on windows: "pip install windows-curses" run it in cmd with admin rights.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020