Step2 - CSE 335 Step 2: Building a City This is CSE 335...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 335 Step 2: Building a City This is CSE 335 Step 2 This assignment Will introduce wxWidgets and how to create an application With a graphical user interface The bulk ofthis step assignment is tutorial, butthere are several programming tasks you Will need to complete There are at the end ofthe step assignment. This assignment are due Thursday, September id, 2010 at ti 55pm. Wheneveryou see this icon: you should be sure your program Wlll compile and run. An Initial Application First, please follow the instructions in . Name your application Step2. Be sure your program is running at this point in time. Drawing The first thing we're going to do is to set up for draWing. Add this public member function to CFrame: p: * Name : CFrame: :OnPaintO * Description : This function is called whenever we need to redraw the * window on the screen. It is responsible for painting that * window. */ void CFrame: :OnPaint (wxPaintEvent .ievent) l // Create a device context wxPaintDC do (this) ; } Now add this line to the event table (between BEGlNiEVENTiTABLE and ENDiEVENTiTABLE in CFrame cpp): EV‘I'_PAIN'1' (CFrame : :OnPaint) Eventedriven programs have a Window that may be erased at any time So, they send you an message indicating that the Window needs to be redrawn. We call this apamt event and we have yust created a handler to handle it The OnPaint function Will be responsible for completely draWing the Window from scratch every time wxPaintDC creates a painting deVioe context. A deVice context is like a bit painting toolbox it is where we Will define brushes, pens, and fonts We Will use to draw it‘s basically in charge ofpainting for us. We create itwhen the paint event is handled. Lers draw 3 Emma "He: Add ms cede m we em Of CFrame Oflpamto: As in most Window systems, the top lelt corner of the Window is (O, O) and the Window is measured in ' pixels by default, though that can be changed. V increaSes as you go down the Screen dc.DrawLinetilOO, 100, 300, 200) ,' .m Run this to be sure itworks. We can change the appearance ofthe line by creating a different pen. Add these two lines before dc.DrawLine: // Create a pen wxPen pen(waolour(0, 255, 0) , 3),- do . SetPen (pen) ,' Now run this. The first line creates a pen object as a object. The color is set to green (0 red, 255 green, 0 blue) and the Width is set up 3. There are many more pen options possible, butthis is a simple example. The second line sets this as the current pen in the deVice context We are setting a pen that is a reference to a local object. When the function exits, it may leave this pen as active, even though it has been destroyed. To prevent Senmg me pen to WKMHPEfl ,5 my reaw necessary WU“ are “,ng cade m, Mlcmsun Wmdaws wee mat pmmem add “7'5 “’79 m we end “(Chamemnpamt a deVice context is systemrlevel there and stays around afterthe function. But, we want to write code that is as general as possible and WxWidgets is crosseplatform. So, We‘ll do things the right Way even when they don't immediately impact our program on the platform We are running on do .SetPen(wau11Pen) ; Pens draw lines. Brushes draw regions such as rectangles. Add this line to CFrarne::OnPaint right aftertne call to dc.DrawLine: dc.DrawRectanglethO, 125, 400, 50); Run this. This draws a rexftangle With the upperelefl corner at (100, 125) that is 400 pixels wide by 50 pixels tall Note that it draws over the line, so you can see it is filling With White, the default brush color. To change the brush color, add this line before the call to dc.DrawRectangle to create a brush using a object: warush brush(waolour(O, 0, 255)) ; do.SetBrush (brush) ; Add this line at the end ofthe function to clear the brush. dc . Se thsh (waul lfimsh) : Run this and you should see a blue rectangle With a green outline Ifyou don‘t Want the outline, set a one pixel Width line that is the same color as the brush. To display text, you create a font as a object like this: // Create a font waont font (12 , WKFONTFAMILY_SWISS, waONTSTYLE_NORMAI-, WKFONTVEIGHT_NORMAL, false) : dc.5etE‘ont(font) 7 The first parameter is the font size in points. A point is 1/72 ofan inch. There are other options for creating fonts See the waont construCtor for details. Then just draw: do.DrawText(L“CSE 335 is oaol!", 10, 10); Add clear the font When done: dc . SetE‘ont (wa'ullE'ont) ; Run this to see that you can do all ofthese tasks More draWing options can be found in the ,the base class for all device contexts Creating the City We‘re going to write a simple program that creates a city using images. lt Will look something like this: Welcome [0 [he Cily’ First, you Will need the image files. Download onto your machine into the Step2 directory containing your DTOJEC‘L Then do this command: tar rxvzt Cityi mages targz This should create a directory named rmagesizBWith a bunch otpng Images in it. These are the Images we‘ll use to create our city. These are images from the obenrsouice game . They have been cleaned and iesized for our use. Al’teryou have extraCted the images, please delete cityimages tar gz. Change the background color for the Window to blackih the CFrame constructor. Be sure everything is working. The CCity Class Create a class called CCity. This Will be the main class for our city. Add this private memberyariable to the CFrai'ne class: CCi by mCity F Add this line to CCityh: #inelude <wx/wx.h> Our cityWill be responsible for draWIng. Add this public memberfunCtion to CCity: void CCity::OnDraw(wxDC Sdc) { // Create a font waant font (12, waONTFAMII-Y_SWISS, waONTSTYI-E_NORMAL, waONTWEIGI-IT_NORMAL, false); dc.5etFonl’-(Eont)i dc.SetTextForeground(waolour(255, 255, 255)); dc.Draw'1'ext(L"We1cume to the City!", 2, 2); 1 When l ask you to add a member funcuon, l'll proVide the definition. You are responsible for adding the declaration to the headerfile You'll probably see something new here ofuse to you (foreground colors?) This won't draw yet. We need to call the function Change CFrai'ne OnDrawl) to this: void CFrame: :OnPainl: (wxPaintEvent Sevent) { // Create a device context wxPaintDC dc(this) ; mCity .OnDraw (dc) ,- dc . Se tPen (waullPen) F do .SetBrueh(wau11Brush) ,- de.SetFant(wau11FontJ ; When you run this, you should see “Welcome to the City“ in white letters on a black background l have added to code to set the pen, brush, and font to null values, so you do not have to in your drawmg code for the city An Image We need to enable loading of PNG images in wxWidgets. Go to CApp Onlnit() and add this line as the newfirst line ofthe function: wani mu Imageflandlers (J ,' This line must be before we create CFrarne. Add this private membervariable to CCity' wai tmap mBl an): ; Add this line to CCity::CCity (the constructor) to load the image: mBlank . LoadE‘ile (1.." images 128 /blank . png") ; Add this line to CCIty::OnDraw() to draw the Image. dc.DrawBitmap(mBlanlc, 100, 100, true); ' This should run and display a plot of grass that looks like this on a black background: The Image is a PNG formal image WI”) an alpha mall ThlS "193051931 llaflS Dime Image ale _ transparent. When you draw the Image, the last para meter (true) Indicates you want to draw using transparency We‘ll do a lot of that Inthis assignment. An Image Cache SoMething very important here: We‘re going to create classes that refer to these images There may be many plots ofgrass We don‘t want each class to load the grass image. Each image uses about 32K of Memory. Vou won‘t want a bunch of redundant copies sitting in memory. So, we‘regOIng to store only one copy of each image in the CCIty class In an Image cache. This Is a data structure that holds a collection of images and loads them as needed. When l need an Image, l askthe cache to give me a pomter to It. lfthe Image does not exist, It loads it in at that time We‘ll referto the Images by filename. Add this private member variable to CCIty' // The image cache std: :map<std: :wstring, waitmap) mImageCache; You'll have to #include <map> and #include <string>. You should also add “using namespace std;“ to CCity.cpp. Notice' wstring Is not the same as string wstring is a Unicode string. This Is 32 bit characters under Linux and 16 bit characters under Windows We‘ll store everything In Unicode from now on (with some exceptions related to files). We need to indicate where we will find our images. l don‘t like to embed constants like that in program code, so add this constant to the beginning of CCIty.cpp after any headers and using statements const wstring DirectoryContainingImages (L"imagele€/“) ,' Then add this public member function /1- * Name : CCity: :GetCachedImageU * Description : Given a base name for an image file, determine if * we have already loaded it. If we have, return a pointer * to the waitmap object in the cache. If we have not * previously loaded it, load it into the cache and then * return a pointer to the image. * Parameters : name — The base name of the image file. We put imgeleB/ unto * the front of this because that is where the file is located. a- / waitmap *CCity: :GetCachedImage(const std: :wstring name) f I/ See if the name exists in the cache already. map<wstring, waitmap): :iterator i = mImageCache.find(name) ; if(i != mImageCache.end()) l [I If we get here, it does exist and i—>seccnd is a ll reference to the bitmap object. return &i->second; l // We‘ll add the path to the name of the file here. wstring realname = DirectoryContainingImages + name; // Create a bitmap image and load the file into it. waitmap bitmap; bitmap. LoadE‘ile (realname . c_str()) : I/ Add it to the cache and return it. mImageCache[name] = bitmap: return mImageCache [name] ; Be sure you read over this fundion and understand what It does. Thefirst timel call GetCachedlmage(L“blank.png"), It looks in the map for a key named "blank png". ltwon'tfind It thefirst time. So, the call to mlmageCachehndO will return mlmageCache end() an Indication of key not found We then build a real name by prepending "images128/" onto the name to give "imagestES/blankpng“ This is loaded into a bitmap and placed into the map with the key "blank png". The second time We call this function with the parameter "blank png“, find returns an iterator that points to the waitmap object inthe cache The iterator for a map as two parts, first, which is the key, and secondwhich is the value We return a pointer to the value, which is of type waitmap. Whew! Change the dc DrawBitmap line in CCity OnDraw to dc.DrawBitmap(*GetCachedImage(L“blank.png") , 100, 100, true) ,- : This now uses our image cache This should work and display the image. Remove the variable mBlank and any uses of it from the program. A Tile Base Class Create a new class called CTile This will be the class that describes a tile of ground in our city. Add this line to CTile h before the class is defined: were 90mg ‘0 use a med swam {m 5,991an our my much like Farmvllle and Fan.” Town "SE Each me will be 123 piXEIS wide and 64 piXels tall in the shape ofdiamond This gives our city an appearance of perspective, even though it‘s completely 2D class CCity; r: This does a shange thing. Our tiles need to know the city they are a member of. But, the city needs to know about the files In order to draw them. So, we have a circular dependency. lfwe #include “CCity h" In CTile,h and then #include "CTile h" In CCity h, We have a circular dependency problem For this reason, C++ allows us to indicate that CCity is a class, but notto indicate any details. We won‘t be able to use any members of ()0in in CTile.h, but that won‘t be a problem. We can use it as a pointer Adeclaration ofa class with no body is called a forward reference. Add these member variables to CTile' // The city this tile is contained in CCity *mcity: // Tile location in the city int mX; H X location for the center of the tile int mY: // Y location for the center of the tile Add these public functions to get and set the location: int Getxn const (return mx;) int GetYU canst {return mY;) void SetLocation(int x, int Y) lmx = x; mY = 3n} Remove thedefault constructor and add this constructor, which is the only one we will use and make it protected, so this is an abstract base class CTile::CTi.1e(CCity *city) : mCity(city) , mX(O) , mY(O) { ) You need to add #include “CCity h" to CTile cpp after the #include “CTile,h“, but do NOT add it to CTile h, Here IS whale include 0mm many Mars amen has “award [defence 10 Gem h 30 “you include CTile h, you'll haveto abs include CC.in h, but always alter any headerth has atomard reierericetothe class, This is whyl saytc Include CCrtyh atter CTileh Vou'll be doing that more in tnefuture a THIS should Dulld and run as betore. A Blank Tile Class Now we‘ll create the class for a blank city tile. Create a new class CTiIeBIank. In CTiIeBlank h, do a #ihclude “CTileh” and make the class derived from CTiIe h (public), Remove the default constructor and add this constructor to CTileBIank: CTileBlank::CTileBlank(CCity *city) : CTile(city) i l/ TODD Ante-generated constructor stub Drawing Tiles All of our tiles need to have the ability to draw themsewes Add this public pure virtual fimcti'cin to CTile virtual void Draw(wxDC Edc) = o,- You'll need to #include <wxlwx h> to use the wxWidgets cla 55, Add this member variable to CTileBlank. waBitmap *mBlank; Add this constant to define the nanie oi the file in CTileBlankcpp: const “string 'l'ileBlankImageName (I."h1ank.png") ,- Hopetulty, you‘ll realize that you need a “using namespace std,“ somewhere, Add this line of code to the CTileBlank construdor to obtain a pointer to the bitmap for the tile mBlank = city- >Ge tC achedImage (1‘ ileBl aninnageName) ; Now add this tunction to CTiIeBIank: void CTileBlank: :Draw (nxDC Ede) i dc.DrawBitlnap(*mBlank, GetXU - 64, GetYU + 32 — mBlank->Getfleight() , true); ) The tiles are 128 pixels wide, so we subtract 64 from the X value to determine where the left side ofthe image is The images vary in height, but the center of the image should be 32 pixels from the bottom of the image, That puts the bottom at GetV() + 32, We subtract the height to figure out where the top should he, Add this private member variable to CCity // All of the tiles that make up our city std: :list<CTile *> m'l'iles; Hope you can figure out the #includes you'll need Get this to compile first, Le 's create some initial tiles to draw, Add this code to the CCity constructor: // Loop over the rows of tiles we «111 create // We use the constant here to indicate how many rows we want to create const int Nuchms = 15; for(int 2:0,- r<NumRows; r++) ( II There is a row every 32 pixels and we start 150 pixels from the top inty=r*32+150; II The number of columns starts at 1 and increases as we [I go down in the Y direction until half way, then decreases. II If we had 5 rows, the number of columns for each row l/Hillbe:12341 int nuchls = NumRows I 2 - abe(r - NuinRowe/Z) + 1; II We center the columns on the screen int xStart = 512 - (nuchls - 1) * 64: for(int c=0,' c<numcals; c++) ( // Each column is 128 pixels to the right. int x = c 5' 128 + xstart; // Create a new tile. C'l‘ileBlanlc *tile = new C'J'ileBlank(this); fl Set the location tile—>3eEL-ocation(x, y) ,' // Add to the list of tiles. mTiles .push_back (tile) ,- Add #include “CTileBlank h" to CCitycpp, but not CCity h Add this code to the destructorto clean up after ourselves while ( !m'l'iles . empty () ) i delete mTiles.front() ; m'l'iles.pop_front() ; Now, onto draw, Remove the existing call to chrawBitmap in CCity and add this code in its place' fcr(list<CTile *>::iterator t=m'.'l'iles.hegin(); t!=m'.'l'iles.end(); t++) i C'J'ile *tile = *t; tile->Draw(dc) : ETNS should compile and run and display a bunch ofblank tiles in a diamond shape on the screen Just to be sure, is what CTileh, CTile cpp, CTileBlahkh, and CTileBlank cpp should look like at this point, Adding a Toolbar We‘re going to want to be able to create quite a few different types oftiles for our city We'll do this by using a toolbar, The toolbar has images oftiles and we'll drag these onto the city surface We‘ll get this working first With only the blanktile Add this member variable to CFrarne waiLmap m'l'oolbar; Add this code to the CFrame constructorto load the toolbar bitmap: mToolbar.LoadE‘ile(L"image5123/toolbar1 .png") .' Then add this code to CFrame::OnPaint atterthe call to mCity.OnDraw(): dc.DrawBitmap(m'l'oolhar, o, 0, true); ETWS should run and you should see the toolbar across the top ofthe Window Creating Mouse Handlers Add this member WHC’UOH l0 CFrame: /e * Name : CFrame: :OnLeftButtonDownO * Description : This function is called when the left mouse button is clicked * on the window. */ void CFrame: :OnLeftButtonDown(wxMouseEvent Sevent) { ) Then add this definition to the Event Table EV‘I_LEE‘T_DOWN (CFrame: :OnLeftButtonDown) This creates a function that is called when the left mouse button is pressed, lwaht to be sure the handler is working Add this line of code to CFrame OnLeflButtonDowno int x event.m_x; int y event.rri_y; int 2 = 0; Set a breakpoint on the line intz = 0, Debug the program, When you click on the Window, the program should break at this line and you should be able to see You may be wondering why i added that last line Often, it‘s convenient to add a line of code that does the values ofx and y nothing so you have something to easily set a breakpoint at, This can make it easier to see variables that would be destroyed otherWise, Remove these three lines of code from CFrame::0nLettButtonDown(), Next, create this member function in CFrarne: /e * Name : CFrame: :OnMouseMoveU * Description : This function is called whenever the mouse is * moved over the window. */ void CFrame: :OnMouseMove(wxMouseEvent sevent) ( ) Add these definition to the Event Table EV‘I_MDT ION (CE‘ram OnMouseMove) EV‘I_LEFT_UP (CFrarne : :OnMo us eMove) l‘m mapping the mouse move event to OnMouseMove. l'm also mapping the button up event to OnMouseMove, so we can detect that a button as been released when not mdvmg. Be sure everything compiles okay at this time. Creating a Tile with the Mouse We‘re going to use the simple idea that you can drag a tile from the tool bar into the city First, add this public memberfunction to CCityto create a new blanktile: /e * Name : CCity::AddIileBlank() * Description : Add. a new blank tile to the city at the location * specified by x, y. * Parameters : x — X location of the mouse click. * y - Y location of the mouse click. e I CTile *CCity: :Add'l'ileBlank(int x, int y) ( C'l'ileBlank *tile = new CTileBlank(this); tile—>SetLocation(x, y),- m'l'ilea .push_back (tile) ; return tile,- tfyou want to, you can add x and y to the constructor tor CTileBlank rather than calling SetLucatiunO. We need a definition ofwhat the items in the toolbar are. Add this enum as publicto CFrame: enum Modes (Trash=0 , Blank=1 , Grass=2 , Blacksmith=3 , Coalmine=4 , Commune=5 , Cricket=6 , Port=7 , Firestation=8, University=9, Industryfleavy=10, IndustryLight=11, Market=12, Tree=13, Reaidential=14, Parkland=15 l ; This is the meaning ofthe 16 leTETETIt locations on the toolbar. We can tell the location by divrding the Xvalue by 64. For example, an Xvalue of450 is location 450/64 = 7', the Port We‘re going to have the idea here that we create a tile and then “grab” it and move itwith the mouse We'll need a member variable to keep track ofwhat tile we are movrng Add this member variable to CFrame C'l'ile *mMouse'l'ile; Set this variable to NULL in the CFrame construmor: mMouseTile = NULL; Add this code to CFrame::0nLettBimonDown()to create a tile ifwe click on the toolbar if(event.m_y < 64) l II We are clicking on the toolbar Modes "Mousemode = (Modes) (event.m_x I 64); switch (nMouseMode) { case Blank: mMouseTile = mCityJdeTileBlank(event.m_x, event.:m_y),' break; default : break; } Refresh () ; return; We can tell we are on the toolbar because it is 64 pixels tall and starts at a Vvalue of 0. So anvaalue from O to 63 is on the toolbar. Note howl cast the result of you may bewomenng Whanhls line does. the divrsion to the enumerated type so we can use it In our swrtch statement. Modes '“MDIEEMDGE = (Modesnevem m “54) Modes is an enum An enum is a C++ wpethat allows you to assign names to integers. In the enum i definition, you‘ll see that Blank is assigned to l. The toolbar is 1024 pixels Wide. Each icon is 64 pixels a Tm Show “m and Just flame me maflk me “my me mama, we ” move n max" wide and there are l6. So, when you divide the X value by 64, you get an integer that is the icon number 0 to l5. it is bad practiceto put these numbers in the switch statement like this: “case l:“ llyou change the toolbar, you only want to change it in one place That place is the enum We then cast that value to the enum type. Internally it‘s still an integer, but the cast helps make it clear in the code that this is a mode value. Add this code to CFrame::OnMouseMove()to actually move the tile: // see if a tile is currently being moved by the mouse rmmmmmmmmnmrmmmmmmmmmm,mmrmmmmmmmmnmrmmmmmmmmmm,mwmmmmm m. if(mMouseTile != NULL) l [I If a tile is being moved, we only continue to I] move it while the left button is down. if (event . m_leftann) { mmouseTile—>SetLocation(event.m_x, event.m_g); ) else { // When the left button is released, we release the fl tile. mmouseTile = NULL; ) // Force the screen to redraw Refresh“ ; EYou should be able to run the program now and drag blank tiles from the toolbar onto the city Please now remove the code from the CCity constructorthat created the initial cityfiles. We can make them ourselves now, instead, so we don‘t need that code anymore. Quantizing the Tile Locations Games that use a layout like this, such as FarmVilIe or Farm Town, usually force the tiles to a grid. This makes rt easrerto layout the tiles. We‘ll call that process in i ii. We‘ll use a simple grid layout of every 32 DIXElS. Add this code to CTiIe: /i- * Name : CTile::QuantizeLooation() * Description : Force the tile to a regular grid by forcing * the values to be multiples of 32. */ void CTile: :QuantizeLoeation () l nix: ((mx+ 16) l 32) k 32,- RH = ((m‘l + 16) l 32) t 32,- ) This rounds the location to the nearest multiple of 32 Add this line of code to CFrame OnMouseMove() right before mMouSeTile : NULL: mouseTile—wuanti zeLoeation () ,' This does the quantization when the tile is released by the mouse. We don't force itto the grid until we release rt. You should see itrump. Some Independent Work At this point, I want you to implement the Grass and Blacksmith Shop options. For Grass, use the image images123lgreenpng and call the class CTiIeGrass w t t I r htl r L t t k t h I For the Blacksmith, use theimage images128lblacksmith0.png and callthe class CTiIeBlacksmithShop You wrllneed to: earegmng “mafia” mm '9wa “mm” a er" may ma esense 0 am somecasses that represent more than one type of tile, like grass or blank and, later, power lines and roads But, for now I want them separate, since We‘re going to have difierent functionalities of some of our tiles. l. Create a class for each ofthese. It Will be Virtually identical to your existing CTileBlank class. Just the image Will be different. 2. Add member functions to CCityto create these two I’IEthlES. 3. Add code to CFrame::OnLettButtonDown() to create these other two tiles. When done, you should be able to drag the first three items from the toolbar into the city Sorting Tiles Try dragging three blacksmith shop tiles, putting the second one to the left front ofthe first, and the third to the right rear ofthe first You should see something like this: So, why does this happen7 We are draWing our tiles in the orderthey are created. But, we really need to draw from back to front. So, we need to sort ourtiles by - increasing Y and, when we have a Y tie, decreasing X. First, add this code to the beginning of CCity cpp (after the headers, but before the constructor) Do NOT Qxfligérfiqggg Eggaéflagugfifig Eggéagglifgfngfiggad‘sfigmhljsffid' 80‘ you can pm u add it asamemberfunctionin CCityDon‘t putitin CCityh ' ’ ' ’ bool Compare'l'iles(c'l'ile *a, CTile *b) l if(a.->GetY() < b->GetY()) return true; if(a.->Get¥() > b->Get¥()) return false; return a->Getx() > b->Getx() 7 I This function compares two tiles as pointed to by a and b it is called a global function, since it is not a member ofa class We use a global function here because that is what the sort routine we Will use from the standard template library requires Now add this publicfunction to CCity: h; * Name : CCity::SartTiles() * Description : Ensure the tiles are in the correct drawing order. */ void CCity: :SortTilesO ( m'l'ilee . sort (: :CompareTilee) ; 1 Adding to the front of CompareTiles() indicates it is a global function and ensures the compiler Will not lookfor a function named CompareTiles in the class CCity Add this call to CFrame::OnMouseMove() right after the call to mMouseTiler>QuantizeLocation(), mCity . Sort'l'iles H F This should run and the blacksmith shop appear correct Inside Testing You're going to need the abilityto tell ifthe mouse has clicked on a tile Add this public memberfunction to CTile boal Islnsideflnt x, int 3;) (return (abs (1: — mX) + absty — mY) * 2) <= 64;) This function returns true if an x,y location is on the diamond shape ofthe tile. To determine what tile the mouse has been clicked on, you‘ll need to iterate over all ofthe tiles and find the one you are inside. You might want to make a function in CCitythat does that. Your Programming Tasks Your programming tasks, and what you will turn in, are t. The two additional tile types you have already created 2. The abilityto grab a tile and drag itWith the mouse. 3. The abilityto delete a tile by moVing it to the trash. 4. Add the ability to count the number of “blank” files and pop up a message box indicating this number. Notice: Do not add a membervariable to CCitythat keeps track ofthe number of blank tiles. You should count the number of blank tiles when requested. Trying to keep a number like this up to date is very hard to do and often leads to bugs in programs. The solutien to #4 must not involve any changes to the classes C'n'lefilacksmithshep or CTiieGrass. When you are done, follow the instrudtions in e: : T. ‘l‘ T ' :' and turn in the file using Handin. Notice: Expect the .zip file to be in excess at 5MB due to the large number 0! images in the images123 directory. Hmfi You have code that determines ifyou have clicked on the toolbar it does this by checking to see ifthe yvalue is less than 64 lfit is not, you‘ll wantto iterate over all ofthe tiles and see ifthe mouse click is inside one ofthem. if so, make mMouseTile point to it. When you grab a tile With the mouse, you need to move it to the end ofthe list oftiles in the city ifyou don‘t, it Will disappear as you move it lower on the screen because it gets covered. To move a tile to the end ofthe list, yust remove it and do a pushiback. Don‘t delete the tile you are moving Be sure you delete a tile when you remove itfrom the city list oftiles: mTilee . remove (tile) F delete tile; The easiest way to create a formatted UNICODE string is to use wstringstream. Just #include <sstream> and be sure to do using namespace std; Then this code Will pop up a message boxthat displays a formatted string: wstringstream str; ...
View Full Document

This note was uploaded on 12/12/2010 for the course CSE CSE 335 taught by Professor Owen during the Fall '10 term at Michigan State University.

Page1 / 7

Step2 - CSE 335 Step 2: Building a City This is CSE 335...

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

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