ex09HousesKangYooPark

ex09HousesKangYooPark - # ex09HouseKangYooPark.py #...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
# ex09HouseKangYooPark.py # 11/05/08 # based on: ex09DrawHousesWithTests.py, P. Conrad CS5NM, 10/14/2008 # stuff we need to import in order to use PyGame import pygame from pygame.locals import * from sys import exit # A function for running test cases # Note that \ character at the end of a line means that the line continues # on the next line def check_expect(test,check,expect): if (check == expect): print "Test " + test + " passed." else: print "Test " + test + " failed: expected " + str(expect) + \ " but I got " + str(check) # makeHouseFrame make the list of points for the frame of a house # consumes: # x, y (numbers: lower left corner of the house) # width, height (numbers: width and height of house) # produces # a list of points # # Note that this doesn't actually draw a house. It just returns a list # of points we can pass to pygame.draw.lines (with closed=False) def makeHouseFrame(x,y,width,height): points = [] # start with an empty list points.append((x,y- ((2/3.0) * height))) # top of 1st story, upper left points.append((x,y)) # lower left corner points.append((x+width,y)) # lower right corner points.append((x+width,y-(2/3.0) * height)) # top of 1st story upper right points.append((x,y- ((2/3.0) * height))) # top of first story, upper left points.append((x + width/2.0,y-height)) # top of roof points.append((x+width,y-(2/3.0)*height)) # top of 1st story, upper right return points # Test cases for makeHouseFrame check_expect("makeHouseFrame test 1", makeHouseFrame(100,200,120,150), [(100,100), (100,200), (220,200), (220,100), (100,100), (160,50), (220,100)]) check_expect("makeHouseFrame test 2", makeHouseFrame(200,200,120,150), [(200,100), (200,200), (320,200), (320,100),
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

ex09HousesKangYooPark - # ex09HouseKangYooPark.py #...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online