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

#include "lab4.h"
#include "cerc.h"

#define MAX_FIGURI 6                //Numarul maxim de cercuri care pot exista

CERC *pc[MAX_FIGURI];               //variabile Globale
CERC cg1,cg2(100,100,25,BLUE);      //doua cercuri definite global

int main(void)
//*****************************************************************************
{
int CercCurent=0,gata=0,k;                //variabile locale
CERC cl1(500,300,75,RED),cl2(200,100,30); //doua cercuri definite local

//cod

  OurInitGraph();

  pc[0]=&cg1;
  pc[1]=&cg2;
  pc[2]=&cl1;
  pc[3]=&cl2;
  pc[4]=new CERC(400,200,100,YELLOW);   //cercuri definite dinamic
  pc[5]=new CERC;

  for(k=0;k<MAX_FIGURI;k++)         //afisare pe ecran a tuturor cercurilor 
    pc[k]->Afiseaza();

  while(!gata)                      //bucla program principal
   switch(getch())                  //citire tasta curenta
   {
     case ESC:                      //terminare program
        gata=1;
        break;
      case TAB:                     //trece la urmatorul cerc
        CercCurent++; 
        CercCurent%=MAX_FIGURI;
        break;
      case 0:                       //tasta speciala?
        switch(getch())
        {
          case LEFT:  pc[CercCurent]->Muta(   -10,  0 ); break;
          case RIGHT: pc[CercCurent]->Muta(    10,  0 ); break;
          case UP:    pc[CercCurent]->Muta(     0,-10 ); break;
          case DOWN:  pc[CercCurent]->Muta(     0, 10 ); break;
          default:    break;
        };break;
	  case UNU:    pc[CercCurent]->Creste( +10     ); break;
	  case DOI:    pc[CercCurent]->Creste( -10     ); 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 */
   }
}
