Make an animated program in where a circle moves across the screen. The circle starts out on (0,0) and moves right one square at a time. Upon reaching the end of a row, the circle will move to the first square of the next row. When the circle reaches the end of the last row, it is transferred back to the initial (0,0) position. When the user presses space, the circle should change into an apple. When the user presses space again it should change back. Use the Snakeuserinterface. Call ui.place(x,y,ui.SNAKE) to place a circle at position (x,y). Use ui.FOOD instead of ui.SNAKE to draw an apple. Please complete this in Python 3. We have to use Snakeuserinterface. This is the format we should use: import snakelib width = 0 # initialized in play_animation height = 0 # initialized in play_snake ui = None # initialized in play_animation SPEED = 20 keep_running = True def draw(): ui.clear() # fill in draw code here ui.show() def play_animation(init_ui): global width, height, ui, keep_running ui = init_ui width, height = ui.board_size() draw() while keep_running: event = ui.get_event() if event.name == "alarm": draw() # make sure you handle the quit event like below, # or the test might get stuck in an infinite loop if event.name == "quit": keep_running = False if __name__ == "__main__": # do this if running this module directly # (not when importing it for the tests) ui = snakelib.SnakeUserInterface(10, 10) ui.set_animation_speed(SPEED) play_animation(ui)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Make an animated program in where a circle moves across the screen. The circle starts out on (0,0) and moves right one square at a time. Upon reaching the end of a row, the circle will move to the first square of the next row. When the circle reaches the end of the last row, it is transferred back to the initial (0,0) position. When the user presses space, the circle should change into an apple. When the user presses space again it should change back. Use the Snakeuserinterface. Call ui.place(x,y,ui.SNAKE) to place a circle at position (x,y). Use ui.FOOD instead of ui.SNAKE to draw an apple.

Please complete this in Python 3. We have to use Snakeuserinterface.

This is the format we should use:

import snakelib width = 0 # initialized in play_animation height = 0 # initialized in play_snake ui = None # initialized in play_animation SPEED = 20 keep_running = True def draw(): ui.clear() # fill in draw code here ui.show() def play_animation(init_ui): global width, height, ui, keep_running ui = init_ui width, height = ui.board_size() draw() while keep_running: event = ui.get_event() if event.name == "alarm": draw() # make sure you handle the quit event like below, # or the test might get stuck in an infinite loop if event.name == "quit": keep_running = False if __name__ == "__main__": # do this if running this module directly # (not when importing it for the tests) ui = snakelib.SnakeUserInterface(10, 10) ui.set_animation_speed(SPEED) play_animation(ui)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY