Question

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

use python software to do this
Use the customized virtual environment you have created in previous Labs, create a graphical game.
You can either think of something of your own, you can search the internet.

http://programarcadegames.com/

What you need to do:
1. Please talk to me before you start your game. This is a homework, not a project, so do not pick something that is too complex.
2. You can borrow and modify an existing open source code. But do identify the source and put some comment on what you have modified/added.
3. There should be sufficient amount of contribution of your own. Not just simply copy an existing program.

What to show:
1. Show me your game works.
2. Paste the source code so that I have the option to try it.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

  • he collides with the end of the screen
  • he presses an arrow opposite to the direction of motion of snake
  • the snake collides with itself

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

Add a comment
Know the answer?
Add Answer to:
use python software to do this Use the customized virtual environment you have created in previous...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT