Difference between revisions of "CSC111 Final Exam 2015b"
Line 121: | Line 121: | ||
</source> | </source> | ||
<br /> | <br /> | ||
+ | <br /> | ||
+ | =Problem 2: Frogger Game= | ||
+ | <br /> | ||
+ | <center><videoflash>plgm_p2zAek</videoflash></center> | ||
+ | <br /> | ||
+ | (if the video does not show in the page, you can watch it on YouTube: [https://www.youtube.com/watch?v=plgm_p2zAek https://www.youtube.com/watch?v=plgm_p2zAek]) | ||
+ | Your assignment is to write a program that uses graphics, and that implements the game illustrated in the video, with a few additional features. | ||
+ | <br /> | ||
+ | Note that the cars appearing on the left of the screen in the video, blink. This is a side-effect of the graphics library, and not a voluntary feature of the program. | ||
+ | <br /> | ||
+ | ==Frog== | ||
+ | <br /> | ||
+ | [[Image:frog3.gif|right]] | ||
+ | You can use the frog image shown on the right for your game, or use one you will have found on the Web. Or you can draw it using ovals and/or circles. The URL for the image on the right is: [http://cs.smith.edu/dftwiki/images/f/f6/Frog3.gif cs.smith.edu/dftwiki/images/f/f6/Frog3.gif]. If you use your own image, make sure you call it '''Frog3.gif'''. When your program is tested, the Frog3.gif image shown here will be the one your program will find and use. | ||
+ | <br /> | ||
+ | ==The Banner== | ||
+ | <br /> | ||
+ | The banner at the top of the screen is an object of a class called '''Banner''', which is given below, along with a main program that illustrates how to use it. | ||
+ | <br /> | ||
+ | ::<source lang="python"> | ||
+ | # bannerDemo.py | ||
+ | # D. Thiebaut | ||
+ | # A short program illustrating the use of a banner in | ||
+ | # graphics. | ||
+ | from graphics import * | ||
+ | WIDTH=800 | ||
+ | HEIGHT=600 | ||
+ | |||
+ | class Banner: | ||
+ | def __init__( self, message ): | ||
+ | """constructor. Creates a message at the top of the graphics window""" | ||
+ | self.text = Text( Point( WIDTH//2, 20 ), message ) | ||
+ | self.text.setFill( "black" ) | ||
+ | self.text.setTextColor( "black" ) | ||
+ | self.text.setSize( 20 ) | ||
+ | |||
+ | def draw( self, win ): | ||
+ | """draws the text of the banner on the graphics window""" | ||
+ | self.text.draw( win ) | ||
+ | self.win = win | ||
+ | |||
+ | def setText( self, message ): | ||
+ | """change the text of the banner.""" | ||
+ | self.text.setText( message ) | ||
+ | |||
+ | def main(): | ||
+ | # creates a window | ||
+ | win = GraphWin( "Demo", WIDTH, HEIGHT ) | ||
+ | |||
+ | # draw the banner at the top | ||
+ | banner = Banner( "Demo. Please click the mouse!" ) | ||
+ | banner.draw( win ) | ||
+ | |||
+ | # wait for the user to click the mouse before continuing... | ||
+ | p = win.getMouse() | ||
+ | |||
+ | # update the banner | ||
+ | banner.setText( "Mouse clicked at Point({0:1}, {1:1})" | ||
+ | .format( p.getX(), p.getY() ) ) | ||
+ | |||
+ | # wait again, and update the banner one more time | ||
+ | p = win.getMouse() | ||
+ | banner.setText( "Mouse clicked again, at Point({0:1}, {1:1})" | ||
+ | .format( p.getX(), p.getY() ) ) | ||
+ | |||
+ | win.getMouse() | ||
+ | win.close() | ||
+ | |||
+ | main() | ||
+ | |||
+ | </source> | ||
+ | <br /> | ||
+ | ==Implementation== | ||
+ | <br /> | ||
+ | * Call your program '''final2.py''' | ||
+ | * You '''must''' use objects to define the cars. | ||
+ | * The number of cars used by the program is fixed and does not grow as the game evolves. In the video, the number of cars is 3, but you can use more. When a car disappears on one end of the screen it reappears on the other side, after a short delay. The delay is up to you. | ||
+ | * The frog moves up or down by a fixed amount. To make the frog move up, the user must click the mouse in the area of the window above the road. To make the frog move down, the user clicks the mouse in the area of the window below the road. | ||
+ | * The frog "dies," or loses a ''life point'' when it is run over by a car. You are free to determine the conditions for which the program will determine that the car is running over the frog. In the video the top or bottom of the frog can overlap slightly the body of a car without triggering the program to detect an overlap. There is flexibility. | ||
+ | * The program automatically brings the frog back down to its initial position when a car runs over it, or when the frog has fully crossed the road. | ||
+ | <br /> | ||
+ | ==Grading== | ||
+ | <br /> | ||
+ | * Assuming that your program is well documented, and nicely organized with functions and classes, the following features will be worth various number of points. A grade of 100 will be given to a will documented and organized program that behaves similarly to the game illustrated in the YouTube video, but with two lanes of cars, one lane going left to right, one going right to left. The number of cars must remain constant, and cars disappearing on one end are made to reappear on the other side. | ||
+ | * Banner working correctly: 10 points | ||
+ | * Cars moving off the graphics window and reappearing on the other side: 10 points. | ||
+ | * Game stopping when the number of life points reaches 0: 10 points | ||
+ | * Frog and car intersection works well: 10 points | ||
+ | * Frog moved back to original position when run over, or when fully crossed: 10 points | ||
+ | * Frog moves up and down on mouse clicks: 10 points. | ||
+ | <br /> | ||
+ | ==Submission== | ||
+ | <br /> | ||
+ | * Submit your program in the Final Problem 2 area on Moodle. | ||
+ | |||
</onlydft> | </onlydft> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | [[Category:CSC111]] |