Showing posts with label Programs. Show all posts
Showing posts with label Programs. Show all posts

Game.CPP


 /////////////////////////////////////////////////////////////////////////
 //*************************** TIC TAC GAME ******************************
 /////////////////////////////////////////////////////////////////////////

 #include
 #include
 #include
 #include
 #include

 //************************* Functions Declearations *********************

 void Intro();
 void instructions();
 void Rectangle(int ,int ,int, int ,int );
 void Rectangle1(int ,int ,int ,int ,int);
 void fill(int,int,int);
 void movement(int,int);
 void check1();
 void insert1(int ,int);
 void insert2(int ,int);
 void Tick1(int ,int );
 void Tick2(int ,int );
 void win_player1();
 void win_player2();

 //************************* End Functions Declearations ******************

 main()
  {

   int d,m;
   d=DETECT;
   initgraph(&d,&m,"..\\bgi");
      cleardevice();
      Intro();   // Intro Function Called
      top:

 ///////////////////////////// Start Of Main Menue  //////////////////////
      cleardevice();
      setbkcolor(0);
      setcolor(2);
      settextstyle(10,0,1);
      outtextxy(220,30,"Main Menue");
      setcolor(4);
      line(220,70,380,70);
      line(220,72,380,72);
      int za1x=4,zb1y=4,za2x=615,zb2y=469;
      for(int zafar1=1;zafar1<4;zafar1++)
       {
       setcolor(9);
       rectangle(++za1x,++zb1y,--za2x,--zb2y);
       }
       setcolor(7);
       rectangle(3,3,616,470);
       rectangle(10,10,609,463);
  menu:
    char ch1='H';
    int x=0;
      while(ch1!='\r')
    {
  me:
       switch(ch1)
    {
     case 'H':
     setcolor(4);
     settextstyle(7,0,3);
     outtextxy(100,160,"Enter To View Instructions");
     outtextxy(100,200,"Enter To Exit Game");
     setcolor(2);
     outtextxy(100,120,"Enter To Play Game");
     ch1=getche();
     x=0;
     if(ch1=='\r')
     goto  game;
     break;

     case 'P':
     if(x==0){
     setcolor(4);
     settextstyle(7,0,3);
     outtextxy(100,120,"Enter To Play Game");
     outtextxy(100,200,"Enter To Exit Game");
     setcolor(2);
     outtextxy(100,160,"Enter To View Instructions");
     x=x+1;
     rept:
     ch1=getche();
     if(ch1=='\r')
     {
     instructions();
     getch();
     goto top;
      }
    if(ch1=='H')
        goto menu;
    else
       if(ch1!='P')
          goto rept;
       else
          goto next;
       }

    else
     {
  next:
     setcolor(4);
     settextstyle(7,0,3);
     outtextxy(100,120,"Enter To Play Game");
     outtextxy(100,160,"Enter To View Instructions");
     setcolor(2);
     outtextxy(100,200,"Enter To Exit Game");
     rept1:
     ch1=getche();
     if(ch1=='\r')
        exit(0);
     else
       if(ch1!='H')
       goto rept1;
     else
         goto menu;

      {
     goto menu;
     break;
      }
       }
    }   // End Of Switch
    ch1=getche();
       } // End Of While
 ///////////////////////////  End Of Main Menue  ////////////////////////

  game :

 ///////////////////////// Start Of Coding For Game /////////////////////

  int arr[3][3],count1[3][3],count2[3][3];

    for(int l=0;l<3;l++)         // Initilization of arr[3][3]
       for(int n=0;n<3;n++)
        arr[l][n]=0;

    for(l=0;l<3;l++)            // Initilization of count1[3][3]
       for(n=0;n<3;n++)
       count1[l][n]=0;

    for(l=0;l<3;l++)            // Initilization of count2[3][3]
       for(n=0;n<3;n++)
        count2[l][n]=0;

     cleardevice();
     setbkcolor(0);

 ////////////////////// Designing of Game's Main page //////////////////

 int a1x=4,b1y=4,a2x=615,b2y=469;

     for(int zafar2=1;zafar2<4;zafar2++)
      {
      setcolor(9);
      rectangle(++a1x,++b1y,--a2x,--b2y);
      }
      setcolor(7);
      rectangle(3,3,616,470);
      rectangle(10,10,609,463);
      setcolor(7);
      rectangle(30,394,590,455);
     a1x=31,b1y=395,a2x=589,b2y=454;
    for(zafar1=1;zafar1<5;zafar1++)   // Rectangular Border of The Page
    {
    setcolor(1);
    rectangle(a1x++,b1y++,a2x--,b2y--);
    }
    setcolor(2);
    setfillstyle(1,2);
    rectangle(35,399,585,450);
    floodfill(37,402,2);
    setcolor(7);
    rectangle(35,399,585,450);
    setcolor(14);
    settextstyle(8,0,3);
    outtextxy(180,20,"TIC TAC GAME ");

 ///// Instruct instructions Given On The Game's Main Page For Player 1 /////

    setcolor(10);
    settextstyle(8,0,3);
    outtextxy(20,60,"PLAYER 1");
    setcolor(4);
    line(20,90,140,90);
    line(20,92,140,92);
    setcolor(15);
    settextstyle(7,0,1);
    outtextxy(20,120," Use Arrow ");
    settextstyle(7,0,1);
    outtextxy(20,160,"   Keys   ");
    settextstyle(7,0,1);
    outtextxy(20,200," to Select &");
    settextstyle(7,0,1);
    outtextxy(20,240,"Enter Button");
    settextstyle(7,0,1);
    outtextxy(20,280," to Insert");

 ///// Instruct instructions Given On The Game Main Page For Player 2 /////

    setcolor(10);
    settextstyle(8,0,3);
    outtextxy(420,60,"PLAYER 2");
    setcolor(4);
    line(420,90,540,90);
    line(420,92,540,92);
    setcolor(15);
    settextstyle(7,0,1);
    outtextxy(420,120,"Use Numeric");
    settextstyle(7,0,1);
    outtextxy(420,160," Arrow Keys ");
    settextstyle(7,0,1);
    outtextxy(420,200," to Select & ");
    settextstyle(7,0,1);
    outtextxy(420,240,"Ins Button");
    settextstyle(7,0,1);
    outtextxy(420,280," to Insert");

 ////////////////////////////  End Instructions ////////////////////////////

 /////Formation of Main Rectangular Box Containing Smallar Rectangles //////

 //******* Formation Of Border of Rectangular Box With Colored Fill *******
    setcolor(10);
    rectangle(160,70,395,380);
    rectangle(161,71,394,379);
    setcolor(4);
    setfillstyle(1,4);
    rectangle(162,72,393,378);
    floodfill(164,74,4);
    setcolor(14);
    rectangle(159,69,396,381);
    setcolor(1);
    rectangle(158,68,397,382);
    rectangle(157,67,398,383);
    rectangle(156,66,399,384);
 //********End of Formation Of Border Of Box Colored Fill.

 //******** Small Rectangular in Main Box
    setcolor(7);
    Rectangle(170,80,235,150,14);    //rectangle [0,0]
    Rectangle(245,80,310,150,14);    //rectangle [0,1]
    Rectangle(320,80,385,150,14);    //rectangle [0,2]

    Rectangle(170,160,235,230,14);   //rectangle [1,0]
    Rectangle(245,160,310,230,14);   //rectangle [1,1]
    Rectangle(320,160,385,230,14);   //rectangle [1,2]

    Rectangle(170,240,235,305,14);   //rectangle [2,0]
    Rectangle(245,240,310,305,14);   //rectangle [2,1]
    Rectangle(320,240,385,305,14);   //rectangle [2,3]


 //******** End Small Rectangular in Main Box

     movement(0,0);

 /////////////////// End Designing of Game's Main page //////////////////


 /////////////////// Start of Game's Logical Programming /////////////////

     int x1,y1,x2,y2;
     x1=169;
     y1=313;
     x2=389;
     y2=373;
     for(x=1;x<17;x++)
     {
       setcolor(15);
       rectangle(x1,y1,x2,y2);
    x1=x1+2;
    y1=y1+2;
    x2=x2-2;
    y2=y2-2;
     }
   char ch=0;
    x=0;
   int  y=0;

 player1:

////////////////////// Plying Conditions For Player 1 ///////////////////

   while(ch!=27)
     {

     setcolor(2);
     settextstyle(8,0,4);
     outtextxy(120,400,"Second Player's Term");
     setcolor(1);
     settextstyle(8,0,4);
     outtextxy(120,400,"First Player's Term");

     movement(x,y);
   ch=getche();
      if(ch=='M'&&y<2&&y>=0)
     {
     y=y+1;
     }
      if(ch=='K'&&y<=2&&y>0)
     {
     y=y-1;
     }
      if(ch=='P'&&x<2&&x>=0)
    {
     x=x+1;
     }
       if(ch=='H'&&x<=2&&x>0)
    {
    x=x-1;
    }

    if(ch=='\r'&&arr[x][y]==0)
      {
      insert1(x,y);
      arr[x][y]=1;
      count1[x][y]=1;
      setcolor(10);
      settextstyle(8,0,4);

 //******************* Win Conditions For First Player ******************

       if(count1[0][0]==1&&count1[1][0]==1&&count1[2][0]==1)  //1st column
      {
          Rectangle1(170,80,235,150,2);
          Rectangle1(170,160,235,230,2);
          Rectangle1(170,240,235,305,2);
          win_player1();
          goto end;
        }
       else
     if(count1[0][1]==1&&count1[1][1]==1&&count1[2][1]==1) //2nd column
         {
          Rectangle1(245,80,310,150,2);
          Rectangle1(245,160,310,230,2);
          Rectangle1(245,240,310,305,2);
          win_player1();
          goto end;
         }
    else
     if(count1[0][2]==1&&count1[1][2]==1&&count1[2][2]==1) //3rd column
       {
         Rectangle1(320,80,385,150,2);
         Rectangle1(320,160,385,230,2);
         Rectangle1(320,240,385,305,2);
         win_player1();
          goto end;
        }
     else
     if(count1[0][0]==1&&count1[0][1]==1&&count1[0][2]==1)  //1st row
     {
       Rectangle1(170,80,235,150,2);
       Rectangle1(245,80,310,150,2);
       Rectangle1(320,80,385,150,2);
       win_player1();
        goto end;
     }
     else
      if(count1[1][0]==1&&count1[1][1]==1&&count1[1][2]==1)  //2nd row
      {
       Rectangle1(170,160,235,230,2);
       Rectangle1(245,160,310,230,2);
       Rectangle1(320,160,385,230,2);
          win_player1();
          goto end;
        }
     else
     if(count1[2][0]==1&&count1[2][1]==1&&count1[2][2]==1) // 3rd row
     {
      Rectangle1(170,240,235,305,2);
      Rectangle1(245,240,310,305,2);
      Rectangle1(320,240,385,305,2);
          win_player1();
          goto end;
        }
     else
     if(count1[0][0]==1&&count1[1][1]==1&&count1[2][2]==1)
     {
         Rectangle1(170,80,235,150,2);
         Rectangle1(245,160,310,230,2);
         Rectangle1(320,240,385,305,2);
          win_player1();
          goto end;
        }
     else
     if(count1[0][2]==1&&count1[1][1]==1&&count1[2][0]==1)
        {
          Rectangle1(320,80,385,150,2);
          Rectangle1(245,160,310,230,2);
          Rectangle1(170,240,235,305,2);
          win_player1();
          goto end;
        }

    //*******************Win Conditions For Second Player ***********
       else
    if(count2[0][0]==1&&count2[1][0]==1&&count2[2][0]==1) //1st column
      {
          Rectangle1(170,80,235,150,2);
          Rectangle1(170,160,235,230,2);
          Rectangle1(170,240,235,305,2);
          win_player2();
          goto end;
        }
       else
     if(count2[0][1]==1&&count2[1][1]==1&&count2[2][1]==1) //2nd column
         {
          Rectangle1(245,80,310,150,2);
          Rectangle1(245,160,310,230,2);
          Rectangle1(245,240,310,305,2);
         win_player2();
          goto end;
         }
    else
     if(count2[0][2]==1&&count2[1][2]==1&&count2[2][2]==1) //3rd column
       {
         Rectangle1(320,80,385,150,2);
         Rectangle1(320,160,385,230,2);
         Rectangle1(320,240,385,305,2);
         win_player2();
          goto end;
        }
     else
     if(count2[0][0]==1&&count2[0][1]==1&&count2[0][2]==1) //1st row
     {
       Rectangle1(170,80,235,150,2);
       Rectangle1(245,80,310,150,2);
       Rectangle1(320,80,385,150,2);
       win_player2();
        goto end;
     }
     else
      if(count2[1][0]==1&&count2[1][1]==1&&count2[1][2]==1) //2nd row
      {
       Rectangle1(170,160,235,230,2);
       Rectangle1(245,160,310,230,2);
       Rectangle1(320,160,385,230,2);
          win_player2();
          goto end;
        }
     else
     if(count2[2][0]==1&&count2[2][1]==1&&count2[2][2]==1) //3rd row
     {
      Rectangle1(170,240,235,305,2);
      Rectangle1(245,240,310,305,2);
      Rectangle1(320,240,385,305,2);
          win_player2();
          goto end;
        }
     else
     if(count2[0][0]==1&&count2[1][1]==1&&count2[2][2]==1)
     {
         Rectangle1(170,80,235,150,2);
         Rectangle1(245,160,310,230,2);
         Rectangle1(320,240,385,305,2);
          win_player2();
          goto end;
        }
     else
     if(count2[0][2]==1&&count2[1][1]==1&&count2[2][0]==1)
        {
          Rectangle1(320,80,385,150,2);
          Rectangle1(245,160,310,230,2);
          Rectangle1(170,240,235,305,2);
          win_player2();
          goto end;
        }
     else
 //***************** Conditions For Draw ************************
     if(arr[0][0]==1&&arr[0][1]==1&&arr[0][2]==1
        &&arr[1][0]==1&&arr[1][1]==1&&arr[1][2]==1
        &&arr[2][0]==1&&arr[2][1]==1&&arr[2][2]==1)
      {
         movement(5,5);

         for(int i=22;i<557;i++)
           {
        setcolor(4);
        settextstyle(10,0,4);
        outtextxy(i,389,"Þ");
        delay(5);
        }
        setcolor(10);
        settextstyle(8,0,4);
        outtextxy(120,400,"  Game has Drawn ");
        goto end;
       }

      goto player2;
     }
   }

 player2:
 ////////////////////// Plying Conditions For Player 2 ///////////////////
  while(ch!=27)
   {

     setcolor(2);
     settextstyle(8,0,4);
     outtextxy(120,400,"First Player's Term");
     setcolor(1);
     settextstyle(8,0,4);
     outtextxy(120,400,"Second Player's Term");

   movement(x,y);
   ch=getche();
   if((ch==54)&&y<2&&y>=0)
   {
   y=y+1;
   }
     if((ch==52)&&y<=2&&y>0)
     {
     y=y-1;
     }

   if((ch==50)&&x<2&&x>=0)
   {
   x=x+1;
   }
   if((ch==56)&&x<=2&&x>0)
   {
   x=x-1;
   }
    if(ch==48&&arr[x][y]==0)
    {
      insert2(x,y);
      arr[x][y]=1;
      count2[x][y]=1;
      setcolor(10);
      settextstyle(8,0,4);

 //*************** Win Conditions For First Player ***********

       if(count1[0][0]==1&&count1[1][0]==1&&count1[2][0]==1) //1st column
      {
          Rectangle1(170,80,235,150,2);
          Rectangle1(170,160,235,230,2);
          Rectangle1(170,240,235,305,2);
          win_player1();
          goto end;
        }
       else
     if(count1[0][1]==1&&count1[1][1]==1&&count1[2][1]==1) //2nd column
         {
          Rectangle1(245,80,310,150,2);
          Rectangle1(245,160,310,230,2);
          Rectangle1(245,240,310,305,2);
          win_player1();
          goto end;
         }
    else
     if(count1[0][2]==1&&count1[1][2]==1&&count1[2][2]==1) //3rd column
       {
         Rectangle1(320,80,385,150,2);
         Rectangle1(320,160,385,230,2);
         Rectangle1(320,240,385,305,2);
         win_player1();
          goto end;
        }
     else
     if(count1[0][0]==1&&count1[0][1]==1&&count1[0][2]==1) //1st row
     {
       Rectangle1(170,80,235,150,2);
       Rectangle1(245,80,310,150,2);
       Rectangle1(320,80,385,150,2);
       win_player1();
        goto end;
     }
     else
      if(count1[1][0]==1&&count1[1][1]==1&&count1[1][2]==1) //2nd row
      {
       Rectangle1(170,160,235,230,2);
       Rectangle1(245,160,310,230,2);
       Rectangle1(320,160,385,230,2);
          win_player1();
          goto end;
        }
     else
     if(count1[2][0]==1&&count1[2][1]==1&&count1[2][2]==1) //3rd row
     {
      Rectangle1(170,240,235,305,2);
      Rectangle1(245,240,310,305,2);
      Rectangle1(320,240,385,305,2);
          win_player1();
          goto end;
        }
     else
     if(count1[0][0]==1&&count1[1][1]==1&&count1[2][2]==1)
     {
         Rectangle1(170,80,235,150,2);
         Rectangle1(245,160,310,230,2);
         Rectangle1(320,240,385,305,2);
          win_player1();
          goto end;
        }
     else
     if(count1[0][2]==1&&count1[1][1]==1&&count1[2][0]==1)
        {
          Rectangle1(320,80,385,150,2);
          Rectangle1(245,160,310,230,2);
          Rectangle1(170,240,235,305,2);
          win_player1();
          goto end;
        }

  //*******************Win Conditions For Second Player ***********

       else
    if(count2[0][0]==1&&count2[1][0]==1&&count2[2][0]==1) //1st column
      {
          Rectangle1(170,80,235,150,2);
          Rectangle1(170,160,235,230,2);
          Rectangle1(170,240,235,305,2);
          win_player2();
          goto end;
        }
       else
     if(count2[0][1]==1&&count2[1][1]==1&&count2[2][1]==1) //2nd column
         {
          Rectangle1(245,80,310,150,2);
          Rectangle1(245,160,310,230,2);
          Rectangle1(245,240,310,305,2);
          win_player2();
          goto end;
         }
    else
     if(count2[0][2]==1&&count2[1][2]==1&&count2[2][2]==1) //3rd column
       {
         Rectangle1(320,80,385,150,2);
         Rectangle1(320,160,385,230,2);
         Rectangle1(320,240,385,305,2);
         win_player2();
          goto end;
        }
     else
     if(count2[0][0]==1&&count2[0][1]==1&&count2[0][2]==1) //1st row
     {
       Rectangle1(170,80,235,150,2);
       Rectangle1(245,80,310,150,2);
       Rectangle1(320,80,385,150,2);
       win_player2();
        goto end;
     }
     else
      if(count2[1][0]==1&&count2[1][1]==1&&count2[1][2]==1) //2nd row
      {
       Rectangle1(170,160,235,230,2);
       Rectangle1(245,160,310,230,2);
       Rectangle1(320,160,385,230,2);
          win_player2();
          goto end;
        }
     else
     if(count2[2][0]==1&&count2[2][1]==1&&count2[2][2]==1) //3rd row
     {
      Rectangle1(170,240,235,305,2);
      Rectangle1(245,240,310,305,2);
      Rectangle1(320,240,385,305,2);
          win_player2();
          goto end;
        }
     else
     if(count2[0][0]==1&&count2[1][1]==1&&count2[2][2]==1)
     {
         Rectangle1(170,80,235,150,2);
         Rectangle1(245,160,310,230,2);
         Rectangle1(320,240,385,305,2);
          win_player2();
          goto end;
        }
     else
     if(count2[0][2]==1&&count2[1][1]==1&&count2[2][0]==1)
        {
          Rectangle1(320,80,385,150,2);
          Rectangle1(245,160,310,230,2);
          Rectangle1(170,240,235,305,2);
          win_player2();
          goto end;
        }
     else
 //***************** Conditions For Draw ************************

     if(arr[0][0]==1&&arr[0][1]==1&&arr[0][2]==1
        &&arr[1][0]==1&&arr[1][1]==1&&arr[1][2]==1
        &&arr[2][0]==1&&arr[2][1]==1&&arr[2][2]==1)
       {
           movement(5,5);
         for(int i=22;i<557;i++)
           {
        setcolor(4);
        settextstyle(10,0,4);
        outtextxy(i,389,"Þ");
        delay(5);
           }
        setcolor(10);
        settextstyle(8,0,4);
        outtextxy(120,400,"  Game has Drawn ");
        }
      goto player1;
     }
       }
  end:
    getch();
    goto top;
    getch();
    closegraph();
     }  //End main
 ////////////////////////////  End Of Main Function ///////////////////////

 //************************ Start Of Function Definations ***************

 //** To Design small squre Rectangular Box ie 'Rectangle Within A Rectangle'

  void Rectangle(int x1,int y1,int x2,int y2,int col1)
       {
       setcolor(0);
       setfillstyle(1,0);
       rectangle(x1+7,y1+7,x2-7,y2-7);
       floodfill(x1+10,y1+10,0);
       setcolor(10);
       rectangle(x1,y1,x2,y2);
       rectangle(x1+7,y1+7,x2-7,y2-7);
       }

 //************* Rectangles To Design Selected portions

  void Rectangle1(int x1,int y1,int x2,int y2,int col1)
       {
       setcolor(col1);
       for(int n=1;n<7;n++)
       rectangle(x1+n,y1+n,x2-n,y2-n);
       }

//************************  Function For Selected Rectangle  ***************

    void movement(int x,int y)
    {
    int col1,col2;
    col1=2;
    col2=1;
    if(x==0&&y==0)
    Rectangle1(170,80,235,150,col1);
    else
    Rectangle1(170,80,235,150,col2);
    if(x==0&&y==1)
    Rectangle1(245,80,310,150,col1);
    else
    Rectangle1(245,80,310,150,col2);
    if(x==0&&y==2)
    Rectangle1(320,80,385,150,col1);
    else
    Rectangle1(320,80,385,150,col2);
    if(x==1&&y==0)
    Rectangle1(170,160,235,230,col1);
    else
    Rectangle1(170,160,235,230,col2);
    if(x==1&&y==1)
    Rectangle1(245,160,310,230,col1);
    else
    Rectangle1(245,160,310,230,col2);
    if(x==1&&y==2)
    Rectangle1(320,160,385,230,col1);
    else
    Rectangle1(320,160,385,230,col2);
    if(x==2&&y==0)
    Rectangle1(170,240,235,305,col1);
    else
    Rectangle1(170,240,235,305,col2);
    if(x==2&&y==1)
    Rectangle1(245,240,310,305,col1);
    else
    Rectangle1(245,240,310,305,col2);
    if(x==2&&y==2)
    Rectangle1(320,240,385,305,col1);
    else
    Rectangle1(320,240,385,305,col2);
    }

  //****************** Function For '-' Sign Called Tic

  void Tick1(int x,int y)
      {
      setcolor(10);
      settextstyle(10,0,4);
      outtextxy(x,y,"-");
       }
 //******************* Function For '+' Sign Called cross

  void Tick2(int x,int y)
      {
      setcolor(10);
      settextstyle(10,0,4);
      outtextxy(x,y,"+");
      }

//***** Insertion Of '-'Sign When Enter is Pressed By Player 1.***********

    void insert1(int x,int y)
       {
      if(x==0&&y==0)
      Tick1(192,77);
      if(x==0&&y==1)
      Tick1(266,77);
      if(x==0&&y==2)
      Tick1(340,77);
      if(x==1&&y==0)
      Tick1(192,155);
      if(x==1&&y==1)
      Tick1(266,155);
      if(x==1&&y==2)
      Tick1(340,155);
      if(x==2&&y==0)
      Tick1(192,233);
      if(x==2&&y==1)
      Tick1(266,233);
      if(x==2&&y==2)
      Tick1(340,233);
       }


//***** Insertion Of '+'Sign When Ins Button is Pressed By Player 2.*******

   void insert2(int x,int y)
       {
      if(x==0&&y==0)
      Tick2(192,77);
      if(x==0&&y==1)
      Tick2(266,77);
      if(x==0&&y==2)
      Tick2(340,77);
      if(x==1&&y==0)
      Tick2(192,155);
      if(x==1&&y==1)
      Tick2(266,155);
      if(x==1&&y==2)
      Tick2(340,155);
      if(x==2&&y==0)
      Tick2(192,233);
      if(x==2&&y==1)
      Tick2(266,233);
      if(x==2&&y==2)
      Tick2(340,233);
       }

 //**************Instruction Page Accessable From main Menue Options

  void instructions()
     {
     cleardevice();
     setbkcolor(0);
     setcolor(2);
     settextstyle(10,0,1);
     outtextxy(200,10,"INSTRUCTIONS");
     int a1x=4,b1y=4,a2x=615,b2y=469;
     for(int zafar1=1;zafar1<4;zafar1++)
     {
     setcolor(9);
     rectangle(++a1x,++b1y,--a2x,--b2y);
     }
     setcolor(7);
     rectangle(3,3,616,470);
     rectangle(10,10,609,463);
     setcolor(4);
     line(200,50,400,50);
     line(200,52,400,52);
     setcolor(2);
     settextstyle(8,0,3);
     outtextxy(30,70,"Player 1 :");
     settextstyle(8,0,1);
     setcolor(7);
     outtextxy(80,110,"1-Use Arrow Keys To Select A box. ");
     outtextxy(80,150,"2-Use Enter Button To insert tick on selected box. ");
     setcolor(4);
     outtextxy(80,200,"               ***************");
     setcolor(2);
     settextstyle(8,0,3);
     outtextxy(30,250,"Player 2 :");
     settextstyle(8,0,1);
     setcolor(7);
     outtextxy(80,290,"1-Use Numeric Arrow Keys To Select A box. ");
     outtextxy(80,330,"2-Use Numeric Ins Button To insert Cross on");
     outtextxy(80,370,"   selected box. ");
     setcolor(4);
     outtextxy(80,410,"               ***************");
     }

  //********* Winning Message For Player 1

  void win_player1()
    {
    for(int i=22;i<557;i++)
       {
    setcolor(4);
    settextstyle(10,0,4);
    outtextxy(i,389,"Þ");
    delay(5);
    }
    setcolor(10);
    settextstyle(8,0,4);
    outtextxy(100,400,"First Player is Winner");
     }

  //********* Winning Message For Player 2

  void win_player2()
    {
     for(int i=22;i<557;i++)
       {
    setcolor(4);
    settextstyle(10,0,4);
    outtextxy(i,389,"Þ");
    delay(5);
    }
     setcolor(10);
     settextstyle(8,0,4);
     outtextxy(100,400,"Second Player is Winner");
     }

 //************ First Page (Intro)

 void Intro()
    {
    int za1x=4,zb1y=4,za2x=615,zb2y=469;
    for(int zafar1=1;zafar1<4;zafar1++)
       {
    setcolor(9);
    rectangle(++za1x,++zb1y,--za2x,--zb2y);
    }
    setcolor(7);
    rectangle(3,3,616,470);
    rectangle(10,10,609,463);
    setcolor(4);
    settextstyle(7,0,5);
    outtextxy(100,260,"PROGRAMMED BY");
    setcolor(14);
    settextstyle(7,0,7);
    outtextxy(50,312,"M.");
    setcolor(2);
    settextstyle(7,0,6);
    outtextxy(129,323,"Z");
    setcolor(4);
    outtextxy(162,323,"A");
    setcolor(14);
    outtextxy(198,323,"F");
    setcolor(2);
    outtextxy(233,323,"A");
    setcolor(4);
    outtextxy(266,323,"R");
    setcolor(14);
    outtextxy(325,323,"S");
    setcolor(2);
    outtextxy(362,323,"A");
    setcolor(4);
    outtextxy(395,323,"L");
    setcolor(14);
    outtextxy(433,323,"E");
    setcolor(2);
    outtextxy(469,323,"E");
    setcolor(14);
    outtextxy(505,323,"M");
  int i,j,col,counter,c1=2,c2=40,f=0;
  while(!kbhit())
   {
   counter++;
   i=160,j=30;
   setcolor(col);
   settextstyle(7,0,6);
   outtextxy(i+=30,j,"T");
   setcolor(col+1);
   outtextxy(i+=30,j,"I");
   setcolor(col+2);
   outtextxy(i+=30,j,"C");
   setcolor(col+3);
   outtextxy(i+=60,j,"T");
   setcolor(col+4);
   outtextxy(i+=30,j,"A");
   setcolor(col+5);
   outtextxy(i+=40,j,"C");
   j=100;
   i=140;
   settextstyle(7,0,4);
   setcolor(col+6);
   outtextxy(i+=90,j,"G");
   setcolor(col+7);
   outtextxy(i+=30,j,"A");
   setcolor(col+8);
   outtextxy(i+=30,j,"M");
   setcolor(col+9);
   outtextxy(i+=30,j,"E");

     if(c1<=40)
     {
     delay(150);
     setcolor(2);
     circle(300,200,c1);
     c1+=2;
     }
   else
     {
     delay(150);
     setcolor(4);
     circle(300,200,c2);
     c2-=2;
      }
      if(c2<=0)
    {
    c1=2;
    c2=40;
     }
      col++;

      } //End While
      getch();
   }//End Function Body


 ////////////////////////////////////////////////////////////////////////

 //****************************  End Of Prgrame *************************

 ////////////////////////////////////////////////////////////////////////

Read Users' Comments (0)

Code for creating a Calculater in C++ ( Calculater.CPP )


#include
#include
#include
#include
#include
#include

  class graphics
     {
       public:
      void screen(int x1,int y1,int x2,int y2)
          {
           setcolor(0);
           setfillstyle(1,0);
           rectangle(x1,y1,x2,y2);
           floodfill(x1+2,y1+2,0);
           setcolor(15);
           Rectangle(x1,y1,x2,y2,15,8);
           Rectangle(x1-1,y1-1,x2+1,y2+1,15,8);
           gotoxy(30,9);
           cout<<"0";
          }
      /*   void button(int x1,int y1,int x2,int y2,char *ch,int true)
        {
           int col;
           setcolor(15);
           rectangle(x1,y1,x2,y2);
           if(true==1)
         col=4;
        else
         col=5;
           setcolor(col);
           setfillstyle(1,col);
           rectangle(x1+2,y1+2,x2-2,y2-2);
           floodfill(x1+4,y1+4,col);
           setcolor(15);
           rectangle(x1+2,y1+2,x2-2,y2-2);
           setcolor(15);
           settextstyle(2,0,6);
           outtextxy(x1+12,y1+4,ch);
        }*/
    void button(int x1,int y1,int x2,int y2,char *ch,int col)
         {
          int color;
          setcolor(col);
          setfillstyle(1,col);
          rectangle(x1,y1,x2,y2);
          floodfill(x1+2,y1+2,col);
          Rectangle(x1-1,y1-1,x2+1,y2+1,0,15);
          if(col==4)
         color=15;
         else
          color=0;
          setcolor(color);
          settextstyle(2,0,6);
          outtextxy(x1+12,y1+3,ch);
         }
      void pressed_button(int x1,int y1,int x2,int y2,char *ch,int col1,int col2)
        {
          button(x1,y1,x2,y2,ch,col1);
          delay(200);
          button(x1,y1,x2,y2,ch,col2);
        }

       void Rectangle(int x1,int y1,int x2,int y2,int col1,int col2)
        {
         setcolor(col1);
         line(x2,y1,x2,y2);
         line(x1,y2,x2,y2);
         setcolor(col2);
         line(x1,y1,x2,y1);
         line(x1,y1,x1,y2);
        }
       void Form(int x1,int y1,int x2,int y2,int col1,int col2,char *ch)
        {
          setcolor(col1);
          setfillstyle(1,col1);
          rectangle(x1,y1,x2,y2);
          floodfill(x1+2,y1+2,col1);
          setcolor(col2);
          setfillstyle(1,col2);
          rectangle(x1,y1,x2,y1+20);
          floodfill(x1+2,y1+2,col2);
          Rectangle(x1-1,y1-1,x2+1,y2+1,8,15);
          Rectangle(x1-2,y1-2,x2+2,y2+2,8,15);
          setcolor(15);
          settextstyle(2,0,5);
          outtextxy(x1+8,y1+2,ch);
       }
       void Interface()
       {
        setcolor(15);
        settextstyle(1,0,4);
        outtextxy(170,20,"Simple Calculator");
        setcolor(0);
        setfillstyle(1,0);
        rectangle(220,90,410,340);
        floodfill(222,92,0);
        Form(210,80,400,330,7,4,"Calculator");
        screen(225,120,385,145);
        int x1=220,y1=175,x2=250,y2=200;
         int col=4;
        button(x1,y1,x2,y2,"7",col);
        button(x1+=35,y1,x2+=35,y2,"8",col);
        button(x1+=35,y1,x2+=35,y2,"9",col);
        button(x1+=35,y1,x2+=35,y2,"û",col);
        button(x1+=35,y1,x2+=35,y2,"C",col);
      y1+=35;
      y2+=35;
      x1=220;
      x2=250;
   button(x1,y1,x2,y2,"4",col);
   button(x1+=35,y1,x2+=35,y2,"5",col);
   button(x1+=35,y1,x2+=35,y2,"6",col);
   button(x1+=35,y1,x2+=35,y2,"*",col);
   button(x1+=35,y1,x2+=35,y2,"/",col);
      y1+=35;
      y2+=35;
      x1=220;
      x2=250;
   button(x1,y1,x2,y2,"1",col);
   button(x1+=35,y1,x2+=35,y2,"2",col);
   button(x1+=35,y1,x2+=35,y2,"3",col);
   button(x1+=35,y1,x2+=35,y2,"+",col);
   button(x1+=35,y1,x2+=35,y2,"-",col);
      y1+=35;
      y2+=35;
      x1=220;
      x2=250;
   button(x1,y1,x2,y2,"0",col);
   button(x1+=35,y1,x2+=35,y2,".",col);
   button(x1+=35,y1,x2+=35,y2,"ã",col);
   button(x1+=35,y1,x2+=35,y2,"A",col);
   button(x1+=35,y1,x2+=35,y2,"=",col);

        setcolor(14);
        settextstyle(1,0,3);
        outtextxy(185,380,"Press Escape To Exit");
        setcolor(15);
        settextstyle(7,0,2);
        outtextxy(440,100,"Instructions");
        setcolor(10);
        settextstyle(8,0,1);
        outtextxy(430,150,"Press 'u' For û");
        outtextxy(430,200,"Press 'p' For ã");
        outtextxy(430,250,"Press 'c' For Clear");
        setcolor(15);
        settextstyle(7,0,2);
        outtextxy(20,100,"Designer & ");
        outtextxy(50,140,"Progrmmer");
        setcolor(10);
        settextstyle(7,0,2);
        outtextxy(20,180,"M. Zafar Saleem");
        setcolor(15);
        outtextxy(20,225,"Group Name");
        setcolor(10);
        outtextxy(50,270,"Educators (é)");

       }
     };


void main()
 {
  int d,m;
   d=DETECT;
   initgraph(&d,&m,"..\\bgi");
   cleardevice();
   /////////////////////  backcolor
          int col=1;     // Adgust Background color
          setcolor(col);
          setfillstyle(1,col);
          rectangle(0,0,625,475);
          floodfill(2,2,col);
          setcolor(7);
          rectangle(0,0,625,475);
          rectangle(1,1,624,474);
          rectangle(3,3,622,472);
   /////////////////////////////////////
   graphics g;
   g.Interface();

 char ch,a1[25],a2[25];
 int x=0,c=30,r=9,pi=0;
 int clear=0,equals=0,equal1=0,answer=0;
 float val1,val2;
 float result;
 int sum=0,mul=0,div=0,sub=0;
 do
  {
  gotoxy(c,r);
  ch=getch();
  if(clear==1||equals==1||answer==1||pi==1)
    {
    gotoxy(30,9);
    cout<<"0                 ";
    clear=0;
    equals=0;
    answer=0;
    pi=0;
    }
  if(x>9&&(!(ch=='+'||ch=='-'||ch=='*'||ch=='/'||ch=='='||ch=='c'||ch=='C'||ch=='u'||ch=='U')))
      continue;
  gotoxy(c,r);
  switch(ch)
   {
    case '1':
    g.pressed_button(220,245,250,270,"1",14,4);
    cout<<"1";
    break;
    case '2':
    g.pressed_button(255,245,285,270,"2",14,4);
    cout<<"2";
    break;
    case '3':
    g.pressed_button(290,245,320,270,"3",14,4);
    cout<<"3";
    break;
    case '4':
    g.pressed_button(220,210,250,235,"4",14,4);
    cout<<"4";
    break;
    case '5':
    g.pressed_button(255,210,285,235,"5",14,4);
    cout<<"5";
    break;
    case '6':
    g.pressed_button(290,210,320,235,"6",14,4);
    cout<<"6";
    break;
    case '7':
    g.pressed_button(220,175,250,200,"7",14,4);
    cout<<"7";
    break;
    case '8':
    g.pressed_button(255,175,285,200,"8",14,4);
    cout<<"8";
    break;
    case '9':
    g.pressed_button(290,175,320,200,"9",14,4);
    cout<<"9";
    break;
    case 'C':case 'c':
      g.pressed_button(360,175,390,200,"C",14,4);
      gotoxy(30,9);
      cout<<"0                  ";
      sum=0;mul=0;div=0;sub=0;
      c=30;r=9;x=0;
      clear=1;
      continue;
      break;
    case '*':
       g.pressed_button(325,210,355,235,"*",14,4);
      a1[x]='\0';
      val1=atof(a1);
      mul=1;
      c=30;r=9;x=0;
      clear=1;
      continue;
    break;
    case '/':
      g.pressed_button(360,210,390,235,"/",14,4);
      a1[x]='\0';
      val1=atof(a1);
      div=1;
      c=30;r=9;x=0;
      clear=1;
      continue;
    break;

    case '+':
      g.pressed_button(325,245,355,270,"+",14,4);
      a1[x]='\0';
      val1=atof(a1);
      sum=1;
      c=30;r=9;x=0;
      clear=1;
      continue;
    break;
    case '-':
      g.pressed_button(360,245,390,270,"-",14,4);
      a1[x]='\0';
      val1=atof(a1);
      sub=1;
      c=30;r=9;x=0;
      clear=1;
      continue;
    break;
    case 'p':case 'P':
    g.pressed_button(290,280,320,305,"ã",14,4);
    gotoxy(30,9);
    cout<<"                   " ;
    gotoxy(30,9);
    cout<<"3.14";
    pi=1;
    continue;
    break;
    case 'U': case 'u':
      g.pressed_button(325,175,355,200,"û",14,4);
      a1[x]='\0';
      val1=atof(a1);
      result=sqrt(val1);
      gotoxy(30,9);
      cout<<"             ";
      gotoxy(30,9);
      cout<
      c=30;r=9;x=0;
      clear=1;
      continue;
    break;
    case 'A':case 'a':
    g.pressed_button(325,280,355,305,"A",14,4);
    if(equal1==1)
    {
    gotoxy(30,9);
    cout<<"                ";
    gotoxy(30,9);
    cout<
    }
    answer=1;
    continue;
    break;
    case '=':
      a2[x]='\0';
      val2=atof(a2);
      g.pressed_button(360,280,390,305,"=",14,4);
      gotoxy(30,9);
      cout<<"0                 ";
      if(sum==1)
      {
      result=val1+val2;
      gotoxy(30,9);
      cout<
      }
      else
      if(div==1)
      {
    if(val2==0)
      {
      gotoxy(30,9);
      cout<<"ì";
     }
      else
      {
      result=val1/val2;
      gotoxy(30,9);
      cout<
      }
      }
      else
      if(mul==1)
      {
      result=val1*val2;
      gotoxy(30,9);
      cout<
      }
      else
      if(sub==1)
      {
      result=val1-val2;
      gotoxy(30,9);
      cout<
      }
    equals=1;
    equal1=1;
       c=30;r=9,x=0;
       continue;
    break;
    case '.':
      g.pressed_button(255,280,285,305,".",14,4);
      if(x>0)
      cout<<".";
      else
       continue;
    break;
    case '0':
      g.pressed_button(220,280,250,305,"0",14,4);
      if(x>0)
      cout<<"0";
      else
    continue;
    break;
  default:
       continue;
   }
   c++;
   if(sum==0&&sub==0&&mul==0&&div==0)
       a1[x]=ch;
    else
       a2[x]=ch;
    x++;

  }while(ch!=27);

  closegraph();
 }

Read Users' Comments (0)