Creating a Snake game with Python in under 5 minutes
Why Stack Overflow recommends it
Stack Overflow users link it as the source of a short curses-based Snake script, usually when asking why the copied code fails (for example on Windows, where curses is missing) or when sharing the code as a quick example.
Recommended by 0 people across 0 different months, 2018 to 2020.
What it is
Engineer Man codes a terminal-based Snake game in Python in under six minutes, using the standard-library curses module. It is a fast, live-coded fun challenge, with the finished code published on GitHub.
What people said
Cites Alex · 2018-10 · Stack Overflow · on “Trying to make the Snake game on Python. Where do I download the cursor extension”
So I'm new to python. I was messing around on youtube and I found this video that shows a dude coding a snake game in under 5 min. This interested me so I tried copying all his code. It is correct for as far as I can see except when I run it, it keeps telling me there is no such thing as a curses module. I looked around on the internet for a website where I can download it but all of them are either shady or only explain how to use the module after you download it. I even asked my teacher where to get it and he just abandoned me after a while of searching. Oh, and I've been coding my game on idle because for some reason pycharm doesn't work on my computer, which is fine by me. Please help. Y
Cites Jacobacon215 · 2019-12 · Stack Overflow · on “Curses giving error when running curses.initscr() - python”
Background: I recently installed curses with pip install curses I found a couple tutorials online ( [LINK] , [LINK] , [this video] ) I always constantly testrun my code when I install a new package or learn something new Whenever I run s = curses.initscr() in IDLE, I get this error message: File "C:/Users/jacob/AppData/Local/Programs/Python/Python37-32/screentest.py", line 3, in <module> s = curses.initscr() File "C:\Users\jacob\AppData\Local\Programs\Python\Python37-32\lib\curses\__init__.py", line 30, in initscr fd=_sys.__stdout__.fileno()) AttributeError: 'NoneType' object has no attribute 'fileno' This is the message from PyCharm: Redirection is not supported. Process finished with exit code
Cites LifeLearner · 2020-02 · Stack Overflow · on “Tried to apply what I've learned to build snake game python but it doesn't work”
I've been trying to apply what I've learned so far following this video but it doesn't seem to work, why? This's the video's link. [this video] And this is the code I wrote to run it. 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(food[0], 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][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], snake[
Cites Biggyboiii · 2020-09 · Stack Overflow · on “making a snake pygame”
This is possibly the easiest way to create a snake game. No images needed :). Code: 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][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], snake[0][1]] if key == curses.KEY_DOWN: new_head[0] += 1 if key == curses.KEY_UP: n