Exam 13: Video Games: Multithreading, Event Handlers, Static Variables

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Case Study 2: 1. import turtle 2. 3. class Etch: 4. def __init__(self): 5. self.__myT = turtle.Turtle() 6. self.__myScreen = turtle.Screen() 7. self.__myT.color('blue') 8. self.__myT.pensize(2) 9. self.__myT.speed(0) 10. self.__distance = 5 11. self.__turn = 10 ... 19. def fwd(self): 20. self.__myT.forward(self.__distance) -Refer to the session in the accompanying Case Study 2. The Etch class uses the inheritance approach to working with a turtle.

Free
(True/False)
4.9/5
(38)
Correct Answer:
Verified

False

Explain how to set up a callback for mouse events on the turtle.

Free
(Essay)
5.0/5
(42)
Correct Answer:
Verified

To set up a callback for a mouse click, we call the onclick method and simply pass it the function to call whenever the mouse is clicked. The main difference between the keyboard callbacks and the mouse callbacks is that the function we write to accept mouse callbacks must accept two parameters. The two parameters will specify the x and y coordinates of where the cursor was when the mouse was clicked.

What is the main structure of an event-driven program?

Free
(Multiple Choice)
4.7/5
(43)
Correct Answer:
Verified

A

Match each definition with its term. -Hides any functions from outside of the class and starts with __.

(Multiple Choice)
4.7/5
(48)

Match each definition with its term. -First-come first-served data structure.

(Multiple Choice)
4.8/5
(37)

Passing ____ to a turtle function that is used to register a callback effectively cancels the callback mechanism.

(Multiple Choice)
4.8/5
(44)

What are some of the benefits of extending a class from Thread?

(Essay)
4.8/5
(36)

Case Study 1: 1. class EventHandler: 2. def __init__(self): 3. self.__queue = [] 4. self.__eventKeeper = {} 5. 6. def addEvent(self, eventName): 7. self.__queue.append(eventName) 8. 9. def registerCallback(self, event, func): 10. self.__eventKeeper[event] = func 11. 12. def run(self): 13. while(True): 14. if len(self.__queue) > 0: 15. nextEvent = self.__queue.pop(0) 16. self.__eventKeeper[nextEvent]() 17. else: 18. print('queue is empty') -Refer to the session in the accompanying Case Study 1. What kind of loop is shown on lines 13-18?

(Multiple Choice)
4.8/5
(31)

Match each definition with its term. -A special instruction to the Python interpreter that starts with @.

(Multiple Choice)
4.9/5
(35)

Describe the __moveOneStep method of the AnimatedTurtle class presented in your text. What is the significance of the two underscores in the method name?

(Essay)
4.9/5
(33)

Match each definition with its term. -Variable that is shared by all instances of a class and is available to all the methods in the class.

(Multiple Choice)
4.8/5
(44)

What is the name of the event loop for a turtle?

(Multiple Choice)
4.7/5
(38)

A(n) ____ variable is shared by all instances of the class.

(Multiple Choice)
4.9/5
(31)

Typically, desktop applications are single-threaded.

(True/False)
4.9/5
(40)

Before using the screen to respond to keyboard events, call the ____ method of Screen.

(Multiple Choice)
4.8/5
(37)

Case Study 2: 1. import turtle 2. 3. class Etch: 4. def __init__(self): 5. self.__myT = turtle.Turtle() 6. self.__myScreen = turtle.Screen() 7. self.__myT.color('blue') 8. self.__myT.pensize(2) 9. self.__myT.speed(0) 10. self.__distance = 5 11. self.__turn = 10 ... 19. def fwd(self): 20. self.__myT.forward(self.__distance) -Refer to the session in the accompanying Case Study 2. Explain the composition approach used by the Etch class.

(Essay)
4.8/5
(31)

How do you make a class multithreaded in Python?

(Multiple Choice)
4.8/5
(35)

The main difference between keyboard callbacks and mouse callbacks is that the function we write to accept mouse callbacks must accept two parameters.

(True/False)
4.9/5
(45)

To hide a function from use outside of the class, begin the name with:

(Multiple Choice)
4.8/5
(28)

How would you detect when two turtles collide?

(Essay)
4.9/5
(30)
Showing 1 - 20 of 33
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)