so lets start making a very basic game called snakes using python . now the snakes game has very simple rules .
a snake is there on the screen you can move the snake using up down right and left key . the main purpose of the snake is eating food and growing big
a person looses if
now for this assignment we will use python 3 and curses library . since we are using python 3 i advice the user to install curses support for windows using pip install windows-curses
you can think of curses library as a tool to paint the screen and erase using keyboard based inputs
# regular imports
"""importing the random and curses library """
import random
import curses
"""initializing the cursor screen"""
screen = curses.initscr()
curses.curs_set(0)
"""taking screen height and measurement """
screen_height, screen_width = screen.getmaxyx()
"""opening the new windows of same height"""
start = curses.newwin(screen_height, screen_width, 0, 0)
"""initializing keypad"""
start.keypad(1)
start.timeout(100)
"""positioning the snake """
snake_position_x = screen_width/4
snake_position_y = screen_height/2
""" starting withsnake of size three character """
snake_pos = [
[snake_position_y, snake_position_x],
[snake_position_y, snake_position_x-1],
[snake_position_y, snake_position_x-2]
]
"""initializing snakes food """
snake_food = [screen_height/2, screen_width/2]
"""addingsnake food to the screen """
start.addch(int(snake_food[0]), int(snake_food[1]), 'f')
""" taking key input"""
key_input = curses.KEY_RIGHT
while True:
""""starting the game and adding the rules """
next_key_input = start.getch()
key_input = key_input if next_key_input == -1 else
next_key_input
"""" boundary condtion that is if snake touches the boundary
"""
if snake_pos[0][0] in [0, screen_height] or snake_pos[0][1] in [0,
screen_width] or snake_pos[0] in snake_pos[1:]:
curses.endwin()
quit()
""" determining head of snake """
new_head_snake = [snake_pos[0][0], snake_pos[0][1]]
"""getting keyinput and determining what to do
"""
if key_input == curses.KEY_DOWN:
new_head_snake[0] += 1
if key_input == curses.KEY_UP:
new_head_snake[0] -= 1
if key_input == curses.KEY_LEFT:
new_head_snake[1] -= 1
if key_input == curses.KEY_RIGHT:
new_head_snake[1] += 1
"""increasing snakes length sccoring to food """
snake_pos.insert(0, new_head_snake)
"""snake eating the food and creating nmew food using rand function
determine food location"""
if snake_pos[0] == snake_food:
snake_food = None
while snake_food is None:
nf = [
random.randint(1, screen_height-10),
random.randint(1, screen_width-10)
]
snake_food = nf if nf not in snake_pos else None
start.addch(int(snake_food[0]), int(snake_food[1]), 'a')
else:
tail = snake_pos.pop()
start.addch(int(tail[0]), int(tail[1]), ' ')
"""else keep roaming """
start.addch(int(snake_pos[0][0]), int(snake_pos[0][1]), 'a')
the output


use python software to do this Use the customized virtual environment you have created in previous...