#include <graphics.h> 
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

#include "ex3.h"
#include "cerc.h"

// variabile Globale

CERC c[NR_CERCURI];

int main(void)
//*********
{
// variabile locale

int CercCurent=0,gata=0,k;

// cod

   OurInitGraph();

   for(k=0;k<NR_CERCURI;k++)                     //initializari
      {
      c[k].Atribuie(30*k+100,200,5*k+25,k+1);
      c[k].Afiseaza();
      }

   while(!gata)
     switch(getch())
       {
       case ESC:
         gata=1;
         break;
       case TAB:
         CercCurent++;
         CercCurent%=NR_CERCURI;
         break;
	   case UNU:    c[CercCurent].Creste(  +10   ); break;
       case DOI:    c[CercCurent].Creste(  -10   ); break; 
       case 0:
         switch(getch())
           {
             case LEFT:  c[CercCurent].Muta( -10,   0 ); break;
             case RIGHT: c[CercCurent].Muta(  10,   0 ); break;
             case UP:    c[CercCurent].Muta(   0, -10 ); break;
             case DOWN:  c[CercCurent].Muta(   0,  10 ); break;
            
             default:    break;            }
       }
   closegraph();
   return 0;
}

void OurInitGraph()
//*****************
{
int gdriver = DETECT, gmode, errorcode;

   initgraph(&gdriver,&gmode,""); /* initialize graphics and local variables */

   errorcode = graphresult();     /* read result of initialization */
   if (errorcode != grOk)         /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);                    /* terminate with an error code */
   }
}
