Your mission is to draw a comfy home for the party. The house will be drawn using Quickdraw. Your home must possess the following features:
HINT: The first floor is different from the others and needs its own function, which we have provided. But the second, third, and all other floors appear identical. Can you take advantage of this fact?
install HomeWhen you first open the stencil, you will find that a few of the lines "commented out"; these lines are surrounded by comment braces /* */, which tell the compiler to ignore them. These lines call functions that you need to write. Be careful to make sure that your functions will accept the parameters listed in the commented out code.
The GUI for Home is not complicated. All we are asking you to do is add a quit button, so that the program will only quit when the user clicks the button. The Quickdraw guide deals thoroughly with the topic of implementing a button. Read it carefully! The Quickdraw guide is your friend and mine!
Remember, you must remove the brackets and asterisks on the commented out lines and write the necessary functions. If you are confused or have any questions, please feel free to ask. Have fun!
/*********************************************************************** * Name: Put Your Name Here * Account: Put Your Account Number Here * Program: Home * * Home draws a house with three or more floors, two doors, doorknobs, * windows, and a roof. ***********************************************************************/ /* NOTE: This program has lines commented out. They are all lines that invoke functions that YOU need to write! These lines begin with a bracket and two asterisks and ends with two asterisks and a bracket. Once you have written the invoked function, delete those six bracket and asterisk characters, and then delete this comment...If you have any questions, please see a TA. */ #include "genlib.h" #include "quickdraw.h" #define HOUSE_HEIGHT 5 /* Height of the house, in tiles */ #define HOUSE_WIDTH 5 /* Width of the house, in tiles */ #define WINDOW_SIZE 30 /* Edge length of window */ #define BORDER 100 /* White space around house */ #define TILE_SIZE 50 /* Edge length of tile */ /*********************************************************************** * function: HouseFrame * * Draws the the main body of the house * parameters: none * returns: none ***********************************************************************/ void HouseFrame() { int left, /* the left boundary of the house */ top, /* the top boundary of the house */ right, /* the right boundary of the house */ bottom; /* the bottom boundary of the house */ Rect houseRect; /* the rectangle representing the house */ left = BORDER; top = BORDER; right = left + HOUSE_WIDTH * TILE_SIZE; bottom = top + HOUSE_HEIGHT * TILE_SIZE; SetRect(houseRect, left, top, right, bottom); /* draw a blue house; you may change the color */ SetColor(blueColor); PaintRect(houseRect); /* draw a black boundary around the house */ SetColor(blackColor); FrameRect(houseRect); } /*********************************************************************** * function: DrawWindow * * Draws a window with cross-bars * parameters: xTile, yTile - x and y location of window, in tiles * returns: none ***********************************************************************/ void DrawWindow(int xTile, /* window's x-location, in tiles */ int yTile) { /* window's y-location, in tiles */ int left, /* left boundary of window */ top, /* top boundary of window */ right, /* right boundary of window */ bottom; /* bottom boundary of window */ Rect windowRect; /* defines dimensions of window */ /* sets coordinates by : starting at the border of the house, moving over to the tile on which to draw the window, and moving to the edge of the window such that the window is centered */ left = BORDER + (xTile - 1) * TILE_SIZE + ((TILE_SIZE - WINDOW_SIZE) / 2); top = BORDER + (HOUSE_HEIGHT - yTile) * TILE_SIZE + ((TILE_SIZE - WINDOW_SIZE) / 2); right = left + WINDOW_SIZE; bottom = top + WINDOW_SIZE; SetRect(windowRect, left, top, right, bottom); /* draw window box now that the coordinates are set */ SetColor(whiteColor); PaintRect(windowRect); /* draw black boundary for window */ SetColor(blackColor); FrameRect(windowRect); /* divide the window into four square window panes */ /* HINT: Try using MoveTo and LineTo -- read the QuickDraw Guide */ /** YOUR CODE HERE **/ } /*********************************************************************** * function: DrawDoor * * Draws a Door with a doorknob. * parameters: * returns: ***********************************************************************/ /*********************************************************************** * function: FirstFloor * * Draws the first floor of the home * parameters: none * returns: none ***********************************************************************/ void FirstFloor() { int windowCounter; /* loop variable for drawing windows */ /* Draw the front door, don't forget the doorknob. */ /** DrawDoor(1,1); **/ /* Draw first-floor windows */ for(windowCounter = 2; windowCounter < HOUSE_WIDTH; windowCounter++) DrawWindow(windowCounter,1); /* Draw the back door, don't forget doorknob. */ /** DrawDoor(HOUSE_WIDTH, 1); **/ } /*********************************************************************** * function: NextFloors * * Starts drawing the other floors of the house * parameters: * returns: ***********************************************************************/ /*********************************************************************** * function: Roof * * Finishes the house by drawing the Roof. * parameters: * returns: ***********************************************************************/ /*********************************************************************** * function: DrawQuitButton * * Draw a quit button on the screen. Hint: make your own constants above * to define where the quit button appears. ***********************************************************************/ /*********************************************************************** * function: main * * main() controls the program. So far, it initializes the * quickdraw window, and calls the calls the draw functions for the * HouseFrame and the FirstFloor. ***********************************************************************/ void main() { int qDrawWidth, /* width of quickdraw window */ qDrawHeight; /* height of quickraw window */ qDrawWidth = 2 * BORDER + HOUSE_WIDTH * TILE_SIZE; qDrawHeight = 2 * BORDER + HOUSE_HEIGHT * TILE_SIZE; InitDraw(qDrawWidth, qDrawHeight); HouseFrame(); FirstFloor(); /** NextFloors() **/ /** Roof() **/ /* Right now, we just quit after one click. You should modify this * code to quit only when the user clicks in the quit button. */ while(!Button()) ; QuitDraw(); }