Program demo pt. grafica si mouse

#include <iostream>
#include <winbgim.h>
#include<stdlib.h>
using namespace std;

int stanga,sus,width,height,latura, numar;
bool gata;

void punerePiesa()
{
 int linia,coloana,x,y;
 if(ismouseclick(WM_LBUTTONDOWN))
 {
 clearmouseclick(WM_LBUTTONDOWN);
 x=mousex();
 y=mousey();
 if (!(x>=stanga && x<=stanga+width && y>=sus&&y<=sus+height))
 gata=true;
 else
 {
 linia=(y-sus)/latura+1;
 coloana=(x-stanga)/latura+1;
 circle(stanga+latura*(coloana-1)+latura/2,sus+latura*(linia-1)+latura/2,10);
 }
 }
}

void desen()
{
 int i,j;
 numar=5;
 width=400;
 height=400;
 latura=width/numar;
 sus=(getmaxy()-width)/2;
 stanga=(getmaxx()-height)/2;
 for(i=1; i<=numar; i++)
 for(j=1; j<=numar; j++)
 rectangle(stanga+latura*(i-1),sus+latura*(j-1),stanga+latura*i,sus+latura*j);
}

int main()
{
 initwindow(800,600);
 desen();
 gata=false;
 do
 {
 punerePiesa();
 }
 while (!gata);
 getch();
 closegraph();
 return 0;
}