c++ - using event handler -


A student has a way of using the mouse as an event handler in C / C + IM and a mini project , Is making a game on the snake and stair (famous board game) and is trying to make it with the basic Borland C ++ compiler, which is to work with a header file called Graphics H, which is very much Is basic and outputs 640 x 480 race, so i sleep Is that the ability to use as Peler event the mouse to control the coin handler on board (no experience which I).

I second year engineering (branch computer science)

thx in advance for help!

I'm not sure which version of the graphics you have, but getmousey , getmousey , clearmouseclick and getmouseclick function. For some documents that can work for you.

It seems that you can use the call back function to do some level of registermousehandler and incident-based programming. Here I have given a sample from the document I sent.

  // Whenever the left mouse button is clicked // click_handler will be called. It looks at the copies of X, Y coordinate of the click, // see if the click was on a red pixel. If so, then the Boolean // variable is set to red_clicked right. Note that normally / all the handlers should be quick if they need to do a bit of work, then they need to set a variable that will trigger the job , And then will return. Bool red_clicked = false; Zero click_handler (int x, int y) {if (getpixel (x, y) == red) red_clicked = true; } // Call this function to attract an isoceol triangle with given base and // height. The triangle will be pulled right above the bottom of the screen. Zero triangle (integer base, integer height) {int maxx = getmaxx (); Int maxy = getmaxy (); Line (max / 2 - base / 2, max - 10, max / 2 + base / 2, max-10); Line (max / 2 - base / 2, max - 10, max / 2, max - 10 - height); Line (max / 2 + base / 2, max - 10, max / 2, max - 10 - height); } Zero main (zero) {int maxx, maxy; // Max X and Y pixel int diviser coordinates; // Place the separator / machine for a triangle length in graphics mode and get the maximum coordinates: InitVindo (450, 300); Maxx = getmaxx (); Maxy = getmaxy (); // Register a left mouse click function registermousehandler (WM_LBUTTONDOWN, click_handler); // Draw a white circle with red inside and radius of 50 pixels: setfilstyle (SOLID_FILL, RED); Setcolor (white); Philatelyaps (max / 2, max / 2, 50, 50); // Print a message and wait for the red pixel to double click: settextstyle (DEFAULT_FONT, HORIZ_DIR, 2); Outtextxy (20, 20, "Red to Finish"); Setcolor (blue); Red_clicked = false; Separator = 2; While (! Red_clicked) {triangle (maxx / divisor, maxy / divisor); Delay (500); Divisor ++; } Cout & lt; & Lt; "Mouse was clicked on:"; Cout & lt; & Lt; "X =" & lt; & Lt; Mousex (); Cout & lt; & Lt; "Y =" & lt; & Lt; Mousse () & lt; & Lt; Endl; // Switch back to text mode: closegraph (); }  

Comments