Monday, 6 April 2015

Add Search Box in Website Search Result in Google (Site links Search Box)

Add This Java Script and HTML in Your Home Page
Java Script
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "WebSite",
  "url": "https://www.sarvesh345.cuccfree.org/",
  "potentialAction": {
    "@type": "SearchAction",
    "target": "https://query.example.com/search?q={search_term_string}",
    "query-input": "required name=search_term_string"
  }
}
</script>
HTML CODE
<div itemscope itemtype="http://schema.org/WebSite">
  <meta itemprop="url" content="https://www.example.com/"/>
  <form itemprop="potentialAction" itemscope itemtype="http://schema.org/SearchAction">
    <meta itemprop="target" content="https://query.example.com/search?q={search_term_string}"/>
    <input itemprop="query-input" type="text" name="search_term_string" required/>
    <input type="submit"/>
  </form>
</div>

Wednesday, 6 August 2014

Use Rupee Symbol in html

 Best way to use rupee font in HTML

Step-1:

Link css file in your head section

<link href="http://sarvesh345.cuccfree.org/rupees.css" rel="stylesheet" type="text/css" /> 



Step- 2 :
 Use this where you want to use rupee symbol
 <span style="font-family:rupee;font-size:14pt">R</span>










 

Create Fancy Calender Using Javascript

 Step 1

Link css and Javascript File in the head section


 <link href="http://sarvesh345.cuccfree.org/calender.css" rel="stylesheet" type="text/css" />
     <script src="http://sarvesh345.cuccfree.org/newcalender.js" type="text/javascript"></script>



 Step 2


 <input type="text" onfocus="showCalendarControl(this);" Placeholder="Click see calender" />





Click to See Demo

Wednesday, 9 July 2014

Convert String to Date Time and Subtract to Current Date Time and store in Integer Variable In C#

  Convert String to Date Time and Subtract to Current Date Time and store in Integer Variable In C# 



string str = dr[0].ToString();
                DateTime OLDDATE = DateTime.Now.AddHours(5.5);
                DateTime NEWDATE = DateTime.ParseExact(str, "dd/MM/yyyy", null);
                TimeSpan span = NEWDATE.Subtract(OLDDATE);
                int day = Convert.ToInt16(span.TotalDays);

Thursday, 12 June 2014

Introduction HTML5

What is HTML5?

HTML5 is the latest standard for HTML.
The previous version of HTML, HTML 4.01, came in 1999, and the internet has changed significantly since then.
HTML5 was designed to replace both HTML 4, XHTML, and the HTML DOM Level 2.
It was specially designed to deliver rich content without the need for additional plugins. The current version delivers everything from animation to graphics, music to movies, and can also be used to build complicated web applications.
HTML5 is also cross-platform. It is designed to work whether you are using a PC, or a Tablet, a Smartphone, or a Smart TV.

How Did HTML5 Get Started?

HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG).
WHATWG was working with web forms and applications, and W3C was working with XHTML 2.0. In 2006, they decided to cooperate and create a new version of HTML.
Some rules for HTML5 were established:
  • New features should be based on HTML, CSS, DOM, and JavaScript
  • The need for external plugins (like Flash) should be reduced
  • Error handling should be easier than in previous versions
  • Scripting has to be replaced by more markup
  • HTML5 should be device-independent
  • The development process should be visible to the public

The HTML5 <!DOCTYPE>

In HTML5 there is only one DOCTYPE declaration, and it is very simple:
<!DOCTYPE html>

Wednesday, 10 July 2013

Creating Baloon in C Graphics

C Program to Create Baloon using Graphics





#include<dos.h>
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
union REGS in,o;

circ()
{
int i;
for(i=0;i<15;i++)
circle(320,240,i*10);
rectangle(240,160,400,320);
}

bulb()
{
int i=1,c=1;
randomize();
while(!kbhit())
{
if((i%2)==0)
setcolor(c++);
setfillstyle(1,getcolor());
circle(320,240,i*20);
putpixel(320-i+2,240-i+2,1);
floodfill(320-i+2,240-i+2,getcolor());
delay(1000);
i++;
if(i>=5)
i=1;
}
}

dot()
{
int i,j,of=40,wid=5;
setcolor(8);
setfillstyle(1,getcolor());
for(i=of;i<getmaxx();i+=of)
bar(i,0,i+wid,getmaxy());

for(i=of;i<getmaxy();i+=of)
bar(0,i,getmaxx(),i+wid);

for(i=of;i<getmaxx();i+=of)
for(j=of;j<getmaxy();j+=of)
{
setcolor(15);
setfillstyle(1,getcolor());
circle(i+2,j+2,4);
floodfill(i+2,j+2,getcolor());
}

}

void main()
{
int x=0,y=10,gd=DETECT,gm,i;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(YELLOW);
settextstyle(1,0,6);
outtextxy(0,240,"Count the black dots.....");
sleep(4);
cleardevice();
dot();
getch();
cleardevice();
setcolor(YELLOW);
settextstyle(1,0,4);
outtextxy(0,240,"I bet the lines of rectangle are straight.....");
sleep(4);
getch();
cleardevice();
circ();
getch();
closegraph();
}

Friday, 21 September 2012

Creating Car using c Programming

#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<process.h>
void main()
{
   int gd=DETECT,gm;
   initgraph(&gd,&gm,"c:\\tc\\bgi");
int c=12;
setbkcolor(0);
//setlinestyle(0,1,2);
int t;
while(1)
{
settextstyle(3,0,1);
outtextxy(400,250,"Sarvesh");
settextstyle(2,0,5);
outtextxy(100,10,"Press L,H ,T,P");
outtextxy(100,30,"Press 1 for Quit");
as:
setcolor(13);
ellipse(380,127,20,152,130,35);

line(490,109,560,142);
line(560,142,569,142);
line(569,142,582,102);
line(582,102,620,92);
line(593,132,617,125);
line(617,124,627,96);
line(620,92,628,97);
line(472,86,602,96);
line(501,113,575,121);
line(443,77,475,80);
line(443,77,432,93);
line(475,80,472,85);
//setcolor(4);
   line(593,132,593,137);
   line(593,137,600,141);
   line(600,141,600,185);
   line(600,185,608,192);
   line(608,192,608,234);
   line(608,234,586,253);
    line(586,253,577,248);
/////////////////////////           mirror
   line(263,112,363,127);
      line(193,160,263,112);
   line(193,160,220,170);
      line(220,170,280,180);
      line(280,180,320,185);
      line(320,185,363,127);
////////////////////////////////sidemirror
line(340,194,460,169);
 line(460,169,519,152);
ellipse(512,144,300,30,10,10);
ellipse(467,143,28,100,50,30);
line(510,128,521,138);
line(435,116,440,171);
//   setcolor(4);
////////////////////////////////////////cont//
   line(339,194,372,144);
//    line(372,140,386,128);
ellipse(454,208,87,123,128,95);
line(372,144,384,128);
   int b,x,y;
////////////////////////lower
line(365,298,524,264);
line(365,298,330,310);
line(330,310,323,310);

///////////////////////////////bumper
ellipse(162,221,135,190,90,40);
line(96,193,140,174);
line(140,174,160,168);
line(160,168,192,161);
//////////////////////front
ellipse(75,246,95,190,18,18);
line(57,251,57,286);
//setcolor(4);
ellipse(181,178,232,263,200,137);
ellipse(195,180,256,286,200,137);

ellipse(191,171,228,247,200,100);
ellipse(231,198,234,275,200,80);
//setcolor(9);
//ellipse(195,170,256,286,200,137);
//setcolor(12);
ellipse(196,167,228,246,200,90);
ellipse(231,184,234,276,200,80);

ellipse(191,200,228,246,200,90);
ellipse(228,218,234,276,200,80);
ellipse(258,268,180,220,200,40);
ellipse(178,296,244,355,16,10);
ellipse(238,249,227,250,200,60);

/////////////wheel1
ellipse(302,281,320,77,26,45);
ellipse(290,277,65,162,40,45);
ellipse(278,288,144,212,31,45);
/////////////wheel2
//setcolor(5);
ellipse(302+260,229,328,87,26,45);
ellipse(290+280-7,277-50+2,90,162,40,45);
ellipse(278+270,288-50,144,215,27,45);
 b=0;
int v=0;
/////////
ellipse(302+250+v,227+b,295,90,29,41);
ellipse(302+234+v,231+b,245,306,50,40);
//setlinestyle(3,0,3);
ellipse(302+248+v,229+b,0,360,21,30);
ellipse(302+247+v,229+b,0,360,8,10);
setfillstyle(6,11);
//floodfill(302+248+v,230+b,13);
//line(546,201,546,257);
//line(554,201,554,257);
//setcolor(4);
line(546+v,201+b,546+v,220+b);
line(551+v,201+b-2,551+v,220+b);
line(546+v,238+b,546+v,257+b);
line(551+v,238+b+2,551+v,257+b+2);

line(530+v,225+b,541+v,225+b);
line(530+v,230+b,541+v,230);
line(557+v,225+b,570+v,225+b);
line(557+v,230+b,570+v,230+b);

line(563+v,206+b,552+v,222+b);
line(534+v,246+b,543+v,232+b);
line(566+v,210+b,556+v,223+b);
line(536+v,250+b,544+v,238+b);
line(536+v,207+b,546+v,222+b);
line(532+v,213+b,542+v,224+b);
line(556+v,235+b,566+v,247+b);
line(551+v,237+b,563+v,253+b);

////////////////////////////////////////////////////
v=-260;
b=56;
ellipse(302+233+v,221+b,260,60,49,51);
//ellipse(302+234+v,231+b,245,306,50,40);
//setlinestyle(3,0,3);
ellipse(302+243+v,224+b,0,360,28,35);
//  line(249,328,269,328);
ellipse(300+245+v,223+b,0,360,10,12);
ellipse(285+249+v,239+b,210,260,30,33);
//floodfill(285+258+v,230+b,12);
b=45;
v=v-4;
line(546+v,201+b,546+v,220+b+2);
line(551+v,201+b,551+v,220+b+2);
b=b+8;
line(546+v,238+b,546+v,257+b+4);
line(551+v,238+b,551+v,257+b+4);
v=v-2;
line(530+v-6,225+b,541+v,225+b);
line(530+v-6,230+b,541+v,230+b);
v=v+5;
line(557+v,225+b,570+v+3,225+b);
line(557+v-1,230+b,570+v+3,230+b);

b=b-5;
v=v-5;
line(565+v+3,206+b,552+v+4,222+b-2);
b=b+15;
line(534+v,246+b,543+v+3,232+b-5);
b=b-10;
line(566+v+7,210+b-5,556+v+4,220+b);
line(536+v-5,250+b,544+v-2,238+b-4);

line(536+v,207+b-8,545+v,222+b-5);
line(531+v,212+b-8,542+v,224+b-2);
line(556+v,235+b,566+v+3,247+b+5);
line(551+v,237+b,563+v+2,253+b+3);
///////////////////lights
ellipse(199,250,144,345,18,8);
line(185,245,206,230);
//setcolor(4);
ellipse(223,234,340,110,8,5);
line(230,237,217,252);
line(206,230,220,229);
//setfillstyle(1,4);
//floodfill(200,240,12);
/////////////////////////////////////
line(90,223,152,236);
line(152,236,137,254);
line(90,223,90,242);
//setfillstyle(10,9);
//floodfill(91,230,14);
ellipse(240,270,104,136,100,60);
ellipse(185,237,120,160,100,60);
ellipse(80,221,357,134,10,10);
line(152,236,168,228);
///////////////////////////////////////////////
line(435,116,440,171);
//////////////////////////////////////////hp
//line(134,185,220,210);
line(134,185,196,160);
line(214,212,318,185);
/////////////////////////////////////////////////light
//setcolor(14);
ellipse(166,247,99,330,8,8);
ellipse(171,243,310,129,7,7);
putpixel(174,250,13);
putpixel(173,251,13);
putpixel(164,239,13);
putpixel(165,238,13);
/////////////////////////////////////////road/////////////////////
setcolor(13);
line(1,430,639,300);
line(1,445,639,315);
line(1,210,93,194);
line(1,195,194,158);
//line(1,170,639,71);
//line(1,170,229,135);
line(520,90,639,71);
line(478,86,639,56);
   int c=0;
   line(10,194+c,10,208+c);
line(40,189+c,40,204+c);
line(70,183+c,70,198+c);
line(100,176+c,100,190+c);
line(130,170+c,130,177+c);
line(160,166+c,160,168+c);
line(190,160+c,190,161+c);
 line(190+330,78+c,190+330,89+c);
line(190+360,72+c,190+360,85+c);
line(190+390,67+c,190+390,81+c);
line(190+420,62+c,190+420,76+c);
line(190+449,57+c,190+449,71+c);

   c=236;
line(10,192+c,10,208+c);
line(40,189+c-2,40,204+c-3);
line(70,183+c-3,70,198+c-3);
line(100,176+c-2,100,190+c-2);
line(130,170+c-2,130,177+c+5);
line(160,166+c-3,160,168+c+8);
line(190,160+c-4,190,161+c+9);
line(190+30,156+c-5,190+30,170+c-5);

line(190+30+30,156+c-12,190+30+30,170+c-12);
line(190+90,156+c-18,190+90,170+c-17);
line(190+120,156+c-25,190+120,170+c-25);
line(190+150,156+c-30,190+150,170+c-30);
line(190+180,156+c-37,190+180,170+c-36);

line(190+210,156+c-42,190+210,170+c-42);

line(190+240,156+c-48,190+240,170+c-48);

line(190+270,156+c-55,190+270,170+c-54);

line(190+300,156+c-61,190+300,170+c-61);

 line(190+330,78+c+10,190+330,89+c+13);
line(190+360,72+c+11,190+360,85+c+13);
line(190+390,67+c+10,190+390,81+c+10);
line(190+420,62+c+8,190+420,76+c+10);
line(190+449,57+c+8,190+449,71+c+8);


/////////////////road
setcolor(12);          /////////////////////////////1
line(1,310,25,306);
line(6,318,30,315);
line(1,310,6,318);
line(25,306,30,314);
int k,m;
k=13*45+19;
m=16*(-8);
          //2
setcolor(12);
line(605,310-128,629,306-128);
line(610,318-128,634,315-128);
line(605,310-128,610,318-128);
line(629,306-128,634,314-128);
setcolor(12);    //////////////////////////////////3
k=45;
m=-8;
line(46,302,70,298);
line(51,310,75,307);
line(46,302,51,310);
line(70,298,75,306);

setfillstyle(1,0);
floodfill(64,303,12);
setfillstyle(1,14);
floodfill(14,314,12);
floodfill(617,183,12);
setfillstyle(1,0);
floodfill(14,314,12);
floodfill(617,183,12);
setfillstyle(1,14);
floodfill(64,303,12);
t=getch();
if(t=='1')
exit(0);
if(t=='h')
{
sound(710);
delay(500);
nosound();
//break;
}
if(t=='s')
{
while(!kbhit())  {
setfillstyle(1,0);
floodfill(536,213,13);
floodfill(563,213,13);
floodfill(561,244,13);
floodfill(538,244,13);
floodfill(274,295,13);
floodfill(294,295,13);
floodfill(274,265,13);
floodfill(294,265,13);
floodfill(548,250,13);
floodfill(548,214,13);
floodfill(533,228,13);
floodfill(563,228,13);
floodfill(262,281,13);
floodfill(308,281,13);
floodfill(284,251,13);
floodfill(284,295,13);
setfillstyle(1,random(12));
floodfill(200,250,13);
delay(10);
//setfillstyle(1,11);
 floodfill(170,250,13);
 floodfill(80,230,13);

 }
setfillstyle(1,0);
floodfill(200,250,13);
delay(10);
//setfillstyle(1,11);
 floodfill(170,250,13);
 floodfill(80,230,13);
 }

if(t=='l')
{
while(!kbhit())
{
delay(120);
setfillstyle(6,0);         //////////////////////////ty
floodfill(536,213,13);
floodfill(563,213,13);
floodfill(561,244,13);
floodfill(538,244,13);
floodfill(274,295,13);
floodfill(294,295,13);
floodfill(274,265,13);
floodfill(294,265,13);
setfillstyle(1,0);
floodfill(64,303,12);
///////////////////////////////////road
setfillstyle(9,0);       /////////////////////color
floodfill(81-40+5,419+7,13);
floodfill(151-40,409+7,13);
floodfill(211-40,397+7,13);
floodfill(271-40,380+7,13);
floodfill(331-40,368+7,13);
floodfill(396-40,355+7,13);
floodfill(450-40,345+7,13);
floodfill(510-40,335+7,13);
floodfill(570-40,325+7,13);
floodfill(630-40,312+7,13);

//////////////////////
floodfill(50,197,13);
floodfill(110,177,13);
floodfill(166,165,13);
floodfill(527,86,13);
floodfill(587,71,13);


setfillstyle(6,14); //////////////////////////ty
floodfill(548,250,13);
floodfill(548,214,13);
floodfill(533,228,13);
floodfill(563,228,13);
floodfill(262,281,13);
floodfill(308,281,13);
floodfill(284,251,13);
floodfill(284,295,13);
////////////////////////////////////////road
setfillstyle(9,10);///////////////////////////////////color
floodfill(19,429,13);
floodfill(81,419,13);
floodfill(151,409,13);
floodfill(211,397,13);
floodfill(271,380,13);
floodfill(331,368,13);
floodfill(396,355,13);
floodfill(450,345,13);
floodfill(510,335,13);
floodfill(570,325,13);
floodfill(630,312,13);
//////////////////////////////////////
floodfill(20,197,13);
floodfill(80,187,13);
floodfill(133,174,13);
floodfill(517,86,13);
floodfill(557,81,13);
floodfill(627,70,13);
setfillstyle(1,14);
floodfill(14,314,12);
floodfill(617,183,12);
///////////////////////////////////////
setfillstyle(10,4);
floodfill(302+248,230,13);
floodfill(302+248+v,230+b,13);
///light
setfillstyle(6,11);                             ///////////
floodfill(200,250,13);
floodfill(170,250,13);
 floodfill(80,230,13);
delay(120);
setfillstyle(6,0);/////////////////////ty
floodfill(548,250,13);
floodfill(548,214,13);
floodfill(533,228,13);
floodfill(563,228,13);
floodfill(262,281,13);
floodfill(308,281,13);
floodfill(284,251,13);
floodfill(284,295,13);
/////////////////////////////////////road
setfillstyle(9,0);      ///////////////color
floodfill(19,429,13);
floodfill(81,419,13);
floodfill(151,409,13);
floodfill(211,397,13);
floodfill(271,380,13);
floodfill(331,368,13);
floodfill(396,355,13);
floodfill(450,345,13);
floodfill(510,335,13);
floodfill(570,325,13);
floodfill(630,312,13);
///////////////////////////////////////////////////////
floodfill(20,197,13);
floodfill(80,187,13);
floodfill(133,174,13);
floodfill(517,86,13);
floodfill(557,81,13);
floodfill(627,70,13);
/////////////////////////////
setfillstyle(1,0);
floodfill(14,314,12);
floodfill(617,183,12);
setfillstyle(6,10);            /////////////ty
floodfill(536,213,13);
floodfill(563,213,13);
floodfill(561,244,13);
floodfill(538,244,13);
floodfill(274,295,13);
floodfill(294,295,13);
floodfill(274,265,13);
floodfill(294,265,13);
////////////////////////////////////////////////road
setfillstyle(9,14);/////////////////////////////////////////color
floodfill(81-40+5,419+7,13);
floodfill(151-40,409+7,13);
floodfill(211-40,397+7,13);
floodfill(271-40,380+7,13);
floodfill(331-40,368+7,13);
floodfill(396-40,355+7,13);
floodfill(450-40,345+7,13);
floodfill(510-40,335+7,13);
floodfill(570-40,325+7,13);
floodfill(630-40,312+7,13);
/////////////////////////////////////////
floodfill(50,197,13);
floodfill(110,177,13);
floodfill(166,165,13);
floodfill(527,86,13);
floodfill(587,71,13);
setfillstyle(1,14);
floodfill(64,303,12);
setfillstyle(9,4);
floodfill(302+248,230,13);
floodfill(302+248+v,230+b,13);
delay(20);
setfillstyle(1,14);
floodfill(200,250,13);
floodfill(170,250,13);
 floodfill(80,230,13);
 delay(20);
setfillstyle(1,0);
floodfill(200,250,13);
floodfill(170,250,13);
 floodfill(80,230,13);


}          }


if(t=='p')
{
int n=0;
while(!kbhit())
{
if(n<=60)
n++;
setcolor(0);
rectangle(1+1,-10,90-1,-12+n);
delay(14);
setcolor(9);
rectangle(1,-10,90,-10+n);
if(n==60)
{
outtextxy(10,10,"L-LIGHTS");
outtextxy(10,20,"H-HORN");
//outtextxy(10,30,"T-AllOY");
 delay(400);
 }

}
setcolor(0);
rectangle(1,-10,90,-10+n);
rectangle(1,-10,90,-11+n);
outtextxy(10,10,"L-LIGHTS");
outtextxy(10,20,"H-HORN");
//outtextxy(10,30,"T-AllOY");
}
}

circle(300,100,3);
nosound();
getch();
}

Draw image in c++ using Computer Graphics

Draw the image  in c++ using Computer Graphics



#include "newgfx.cpp"
#include <iostream.h>
#include <iostream.h>

bitimage bas= {{-1,-1,-1,2,2,2,2,-1,-1,-1},
     {-1,-1,2,2,2,2,2,2,-1,-1},
     {-1,2,2,2,2,2,2,2,2,-1},
     {2,2,2,2,2,2,2,2,2,2},
     {2,2,2,2,2,2,2,2,2,2},
     {2,2,2,2,2,2,2,2,2,2},
     {2,2,2,2,2,2,2,2,2,2},
     {2,2,2,2,2,2,2,2,2,2},
     {-1,2,2,2,2,2,2,2,2,-1},
     {-1,-1,2,2,2,2,2,2,-1,-1},
     {-1,-1,-1,2,2,2,2,-1,-1,-1}},
   temp={0},
   ship={{-1,-1,-1,-1,25,-1,-1,-1,-1},
     {-1,-1,-1,25,25,25,-1,-1,-1},
     {-1,-1,25,25,105,25,25,-1,-1},
     {-1,25,25,105,105,105,25,25,-1},
     {25,25,25,25,25,25,25,25,25},
     {-1,-1,-1,25,41,25,-1,-1,-1},
     {-1,-1,112,41,41,41,112,-1,-1},
     {-1,-1,-1,112,41,112,-1,-1,-1},
     {-1,-1,-1,-1,112,-1,-1,-1,-1},
     {-1,-1,-1,-1,-1,-1,-1,-1,-1},
     },
   red={{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
      {-1,-1,-1,-1,112,112,-1,-1,-1,-1},
      {-1,-1,112,112,41,41,112,112,-1,-1},
      {-1,112,41,41,105,105,41,41,112,-1},
      {-1,112,41,105,0,0,105,41,112,-1},
      {-1,112,41,41,105,105,41,41,112,-1},
      {-1,-1,112,41,177,177,41,112,-1,-1},
      {-1,-1,112,41,41,41,41,112,-1,-1},
      {-1,-1,-1,112,112,112,112,-1,-1,-1},
      {-1,-1,105,105,105,105,105,105,-1,-1}},
   arrow={{-1,-1,-1,-1,150,-1,-1,-1,-1},
      {-1,-1,-1,150,150,150,-1,-1,-1},
      {-1,-1,140,140,140,140,140,-1,-1},
      {-1,41,41,41,41,41,41,41,-1},
      {-1,140,41,140,41,140,41,140,-1},
      {-1,-1,140,126,140,126,140,-1,-1},
      {-1,-1,-1,140,126,140,-1,-1,-1},
      {-1,-1,-1,-1,140,-1,-1,-1,-1},
      {-1,-1,-1,-1,-1,-1,-1,-1,-1}},
   kalien={{-1,-1,-1,-1,43,-1,-1,-1,-1,-1,},
       {-1,-1,-1,46,4,46,-1,-1,-1,-1},
       {-1,-1,46,27,42,27,46,-1,-1,-1},
       {-1,46,4,56,105,56,4,46,-1,-1},
       {-1,46,4,105,105,105,4,46,-1,-1},
       {-1,-1,46,27,42,27,46,-1,-1,-1},
       {-1,-1,-1,46,4,46,-1,-1,-1,-1},
       {-1,-1,2,-1,2,-1,2,-1,-1,-1},
       {-1,2,-1,2,-1,2,-1,2,-1,-1}},
   square={{-1,-1,-1,140,140,140,140,140,-1,-1},
       {-1,-1,140,120,120,120,120,120,140,-1},
       {-1,-1,140,120,120,140,120,120,140,-1},
       {-1,-1,140,140,140,1,140,140,140,-1},
       {-1,-1,140,120,120,140,120,120,140,-1},
       {-1,-1,140,120,120,120,120,120,140,-1},
       {-1,-1,140,130,130,120,130,130,140,-1},
       {-1,-1,140,120,120,120,120,120,140,-1},
       {-1,-1,-1,140,140,140,140,140,-1,-1}};


struct coord {
int x;
int y;
unsigned char color;
};
struct coord2
{
int x;
int y;
unsigned int on;
};
class alien
{  public :
 int x;
 int y;
 int recx;
 int recy;
 int hitpoints;
 int alienp;
 unsigned int down;
 coord2 fire;
 void drawalien(int change=1);
};
class boss
{
 public :
 int x;
 int y;
 int hitpoints;
 int alienp;
 int rounds; //amount of bullets
 coord2 fire[60]; // ship weapon array
 void drawalien(int change=1);
};

void die();
void explode(int x, int y);

void main()
{
 randomize();
 int rowa=13; //rows of aliens
 int cola= 5; //columns of aliens
 int score=0, level=0; // 0 is 1 and so on
 alien enemy[15][11]={0}; // alien array
 boss ship; // your ship
  ship.rounds=6;
  ship.x=30;
  ship.y=MaxY-13;
  ship.alienp=9;
  ship.hitpoints=10;
  ship.drawalien(); // end of ship
 char tmp; // input from keyboard
 startgfx();
//this is where you put all the new levels
end:
 level++;
 cleargfx(0);
 gotoxy(18, 11);
 cout << "Level " << level;
 delay(2000);
 cleargfx(0);
 for(int x=0; x<15; x++)
  for(int y=0; y<11; y++)
  {
   enemy[x][y].down=0;
   enemy[x][y].fire.on = 0;
  }
if(level==1)
 {
 rowa=11;
 cola= 8;
 for(x=0; x<rowa; x++)
  for( y=0; y<cola; y++)
  {
   enemy[x][y].x = x*12;
   enemy[x][y].y = y*13;// +80;
   enemy[x][y].recy = y*13;
   enemy[x][y].alienp = ((y%2)&&(x%2))?2:3;
   enemy[x][y].hitpoints = ((y%2)&&(x%2))?3:2;
   enemy[x][y].drawalien();
  }
 }
else if(level==2)
 {
 ship.hitpoints++;
 score+=50;
 ship.rounds+=2;
 rowa=10;
 cola= 7;
 for(int x=0; x<rowa; x++)
  for(int y=0; y<cola-1; y++)
    {
   enemy[x][y].x = x*12;
   enemy[x][y].y = y*13;
   enemy[x][y].alienp = 4;
   enemy[x][y].hitpoints = 4;
   enemy[x][y].drawalien();
   }
 }
else if(level==3)
 {
 ship.hitpoints+=2;
 score+=50;
 ship.rounds+=2;
 rowa=10;
 cola= 5;
 for(int x=0; x<rowa; x++)
  for(int y=0; y<cola-1; y++)
    {
   enemy[x][y].x = x*12;
   enemy[x][y].y = y*13;
   enemy[x][y].alienp = 5;
   enemy[x][y].hitpoints = 7;
   enemy[x][y].drawalien();
   }
 }
else if(level==4)
{
 ship.hitpoints+=2;
 score+=50;
 ship.rounds+=2;
 rowa=13;
 cola= 7;
 for(int x=0; x<rowa; x++)
  for(int y=0; y<cola-1; y++)
    {
   enemy[x][y].x = x*12;
   enemy[x][y].y = y*13;
   enemy[x][y].alienp = ((y%2)&&(x%3))?2:(x%2)?3:4;
   enemy[x][y].hitpoints = ((y%2)&&(x%3))?3:(x%2)?4:5;
   enemy[x][y].drawalien();
   }
}

 for(x=0; x<ship.rounds; x++)
  ship.fire[x].on = 0;
 /*
 lr is left and right
 mxleft is the maximum left point
 mxright, mxy, mny are all basically the same
 */
 int lr=1, mxleft=MaxX, mxright=0, mxy=0, mny=MaxY;
 int rcount=0;
 ship.drawalien();
 start:
 while(!kbhit())
 {
 //gets the max x for the alien array and the min x
 //also does damage to alien if laser hits them
  for(x=0; x<rowa; x++)
   for(int y=0; y<cola; y++)
   {
   if(enemy[x][y].fire.on == 0 && enemy[x][y].hitpoints>0)
   {
    if(!(rand()%150)) //this is where the enemy fires
    {
     enemy[x][y].fire.x = enemy[x][y].x+5;
     enemy[x][y].fire.y = enemy[x][y].y+11;
     enemy[x][y].fire.on = 1;
    } // end of fire
    if(!(rand()%3000) && enemy[x][y].down==0)
    {
     enemy[x][y].down = 1;
     enemy[x][y].recy = enemy[x][y].y;
     enemy[x][y].recx = enemy[x][y].x;
    }
   }
   if(!enemy[x][y].down)
   {
    if(enemy[x][y].hitpoints > 0)
     mxleft = mxleft<enemy[x][y].x?mxleft:enemy[x][y].x;
    if(enemy[x][y].hitpoints > 0)
     mxright = mxright>enemy[x][y].x?mxright:enemy[x][y].x;
    if(enemy[x][y].hitpoints > 0)
     mxy = mxy>enemy[x][y].y?mxy:enemy[x][y].y;
    if(enemy[x][y].hitpoints > 0)
     mny = mny<enemy[x][y].y?mxy:enemy[x][y].y;
   }
   enemy[x][y].drawalien(2);
   //this is where your guy's bullets hit the aliens
   //if your shots in the right place
   for(int real=0; real<ship.rounds; real++)
    if(ship.fire[real].on == 1)
     if(ship.fire[real].x >= enemy[x][y].x
      && ship.fire[real].x <= enemy[x][y].x+12
      && ship.fire[real].y >= enemy[x][y].y
      && ship.fire[real].y <= enemy[x][y].y+12
      && enemy[x][y].hitpoints>0)
      {
       enemy[x][y].hitpoints--;
       if(enemy[x][y].hitpoints<1)
       {
        explode(enemy[x][y].x, enemy[x][y].y);
        delay(20);
        enemy[x][y].drawalien(2);
        score++;
        if(enemy[x][y].fire.on == 1)
         {
         pixel(enemy[x][y].fire.x, enemy[x][y].fire.y, 0);
         enemy[x][y].fire.on = 0;
         }
       }
       pixel(ship.fire[real].x, ship.fire[real].y, 0);
       ship.fire[real].on = 0;
       rcount--;
      }
     else pixel(ship.fire[real].x, ship.fire[real].y, YELLOW);
     //end of bullet test
   }
 // end of max, min function
 //start of bullet function for ship, moves bullet
 if(rcount>0)
  {
   for(int real=0; real<ship.rounds; real++)
   {
    if(ship.fire[real].on == 1)
    {
     if(ship.fire[real].y>0)
     {
      pixel(ship.fire[real].x, ship.fire[real].y, 0);
      ship.fire[real].y-=2;
      pixel(ship.fire[real].x, ship.fire[real].y, YELLOW);
     }
     else
     {
      pixel(ship.fire[real].x, ship.fire[real].y, 0);
      ship.fire[real].on = 0;
      rcount--;
     }
    }
   }
  }
 //end of bullet function
 //this is where the aliens move left and right and down
 if(lr==1 && (mxright < MaxX-13))
  for(x=0; x<rowa; x++)
   for(y=0; y<cola; y++)
    if(!enemy[x][y].down)
     enemy[x][y].x++;
    else
    {
     if(enemy[x][y].y<MaxY-13)
     {
      enemy[x][y].y++;
      enemy[x][y].recx++;
     }
     else if(enemy[x][y].recx+11>mxright)
     {
      enemy[x][y].recx++;
      enemy[x][y].y = 0;
     }
     else
     {
      enemy[x][y].x = enemy[x][y].recx+1;
      enemy[x][y].y = enemy[x][y].recy;
      enemy[x][y].down = 0;
     }
    }
 else if(lr == 0 && (mxleft >=1))
  for(x=0; x<rowa; x++)
   for(y=0; y<cola; y++)
    if(!enemy[x][y].down)
     enemy[x][y].x--;
    else
    {
     if(enemy[x][y].y<MaxY-13)
     {
      enemy[x][y].y++;
      enemy[x][y].recx--;
     }
     else if(enemy[x][y].recx<mxleft)
     {
      enemy[x][y].recx--;
      enemy[x][y].y = 0;
     }
     else
     {
      enemy[x][y].x = enemy[x][y].recx-1;
      enemy[x][y].y = enemy[x][y].recy;
      enemy[x][y].down = 0;
     }
    }
 else
 {
  lr = !lr;
//  lr = (lr)?0:1; // reverse lr
  for(x=0; x<rowa; x++)
   for(y=0; y<cola; y++)
   {
   if(enemy[x][y].hitpoints>0)
    if(mxy+20 < MaxY)
     if(enemy[x][y].down)
      enemy[x][y].recy+=10;
     else enemy[x][y].y+=10;
   }
 }
 //this is the end of the function where aliens move left and right and down
 //this function draws the aliens if there alive
 for(x=0; x<rowa; x++)
  for(y=0; y<cola; y++)
  {
   //this tests the range of numbers for the ship compared to the alien
   if(enemy[x][y].hitpoints>0
    &&
    (( enemy[x][y].x > ship.x
    && enemy[x][y].x < ship.x+11)
    || (enemy[x][y].x+11 > ship.x
    && enemy[x][y].x+11 < ship.x+11))
    &&
    (( enemy[x][y].y > ship.y
    && enemy[x][y].y < ship.y+11)
    || (enemy[x][y].y+11 > ship.y
    && enemy[x][y].y+11 < ship.y+11)))
   {
    sound(300);
    if(enemy[x][y].down)
    {
     enemy[x][y].x = enemy[x][y].recx;
     enemy[x][y].y = enemy[x][y].recy;
    }
    ship.hitpoints-= enemy[x][y].hitpoints;
    enemy[x][y].hitpoints=0;
    delay(20);
    nosound();
    if(ship.hitpoints<=0)
     die();
   }
   if(enemy[x][y].hitpoints>0)
    enemy[x][y].drawalien();
   if(enemy[x][y].fire.on == 1)
   {
    //this tests if the alien bullets hit your ship.
    if (enemy[x][y].fire.y < MaxY)
    {
     if(enemy[x][y].fire.x > ship.x
      && enemy[x][y].fire.x < ship.x+11
      && enemy[x][y].fire.y > ship.y
      && enemy[x][y].fire.y < ship.y+6)
     {
      sound(400);
      enemy[x][y].fire.on = 0;
      pixel(enemy[x][y].fire.x, enemy[x][y].fire.y, 0);
      ship.hitpoints--;
      delay(50);
      nosound();
      if(ship.hitpoints>0)
       ship.drawalien();
      else
      {
       // this is if you die from losing all you lives
       die();
      }
     } //end of test
     else //moves the bullet
     {
     pixel(enemy[x][y].fire.x, enemy[x][y].fire.y, 0);
     enemy[x][y].fire.y += (!enemy[x][y].down)?1:3;
     pixel(enemy[x][y].fire.x, enemy[x][y].fire.y, 41);
     }
    }
    else enemy[x][y].fire.on = 0;
   }
  }
 //if there are no more aliens goto the end which takes you to
 //the next level
 if(mxright==0 && mxy ==0 && mxleft == MaxX && mny == MaxY)
  goto end;
 //end of level move
 mxright = mxy = 0;
 mxleft = MaxX;
 mny=MaxY;
 gotoxy(1, 1);
 cout << "Life =" << ship.hitpoints << " Score =" << score;
 ship.drawalien();
 delay(20);
 }
 //end of while loop
 //start of keboard input.
 putpic(ship.x, MaxY-13, temp, 9, 12);
 tmp = getch();
 if(tmp == 0)
  tmp = getch();
 //if button is space bar fire
 if(tmp == 32)
 {
  if(rcount<ship.rounds)
  {
   for(int ggod=0; ggod<ship.rounds; ggod++)
   {
    if(!ship.fire[ggod].on)
    {
     sound(50);
     ship.fire[ggod].on = 1;
     ship.fire[ggod].x = ship.x+4;
     ship.fire[ggod].y = MaxY-15;
     rcount++;
     delay(20);
     nosound();
     goto start;
    }
   }
  }
 } //end of space bar
 else if(int(tmp) == 75 && ship.x > 0)  // left arrow
  ship.x-=5;
 else if(int(tmp) == 77 && ship.x < MaxX-13) // right arrow
  ship.x+=5;
 else if(int(tmp) == 27) // escape button
  exit(1);
 ship.drawalien();
 goto start;
 //the end which adds to the level
}
void explode(int x, int y)
{
int radius=6;
sound(200);
for(int count=radius; count>0; count--)
 {
  circle(x+5, y+5, count, RED);
  delay(.75);
 }
for(count=radius; count>0; count--)
 {
  circle(x+5, y+5, count, 0);
 }
nosound();
}

void boss::drawalien(int change)
{
if(change == 1 && hitpoints > 0)
{
 if(alienp == 9)
  putpic(x, y, ship, 9, 12);
}
else if (change > 1)
 putpic(x, y, temp, 11, 10);
}
void alien::drawalien(int change)
{
if(change == 1 && hitpoints > 0)
{
 if (alienp == 1)
  putpic(x, y, bas, 11, 10);
 else if (alienp == 2)
  putpic(x, y, red, 11, 10);
 else if (alienp == 3)
  putpic(x, y, arrow, 11, 10);
 else if (alienp == 4)
  putpic(x, y, kalien, 11, 10);
 else if (alienp == 5)
  putpic(x, y, square, 11, 10);
}
else if (change > 1)
 putpic(x, y, temp, 11, 10);
}

void die()
{
for(int die=0; die<MaxX; die++)
 {
 if(kbhit())
  exit(1);
 circle(MidX, MidY, die, 1);
 cout << "YOU DIED!";
 delay(5);
 }
getch();
exit(1);
}

Game Programming in C langauge

Create Car Game  in C Langauge



#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <iostream.h>
#include <fstream.h>
#include <string.h>

void main(void)
{
   int gdriver = DETECT, gmode, errorcode;
   void
*body,*food,*tail1,*tail2,*tail3,*tail4,*head1,*head2,*head3,*head4;
   int x, y,X[5000],Y[5000],i=3,
maxx,maxy,speed=100,bo=10,t[10],score=0,hscore=20;
   unsigned int size;
   char a='6',b,scor[4],hs[4];
   int k=2,l,r1,r2,f=0,z=100,first=0,second=1;;
   r1=300;
   r2=350;
   ifstream infile("c:\\tc\\bin\\rattle.txt");
   infile.getline(hs,4);
   infile.close();
   hscore = atoi(hs);

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1); /* terminate with an error code */
   }
   maxx = getmaxx();
   maxy = getmaxy();
   y = 160;
   x = 80;
   for(int j=0; j<=3; j++)
   {
 X[i-j]=x-bo*(j+1);
 Y[i-j]=y;
   }
   //body
   setfillstyle(1,2);
   bar(10,10,20,20);
   setcolor(0);
   setlinestyle(0,1,3);
   line(9,9,21,21);
   line(9,21,21,9);
   size = imagesize(10,10,20,20);
   body = malloc(size);
   getimage(10,10,20,20,body);
   cleardevice();
   setcolor(0);
   //tail1-right
   t[0]=20; t[1]=10;
   t[2]=10; t[3]=10;
   t[4]=20; t[5]=15;
   t[6]=10; t[7]=20;
   t[8]=20; t[9]=21;
   fillpoly(5, t);
   size = imagesize(10,10,20,21);
   tail1 = malloc(size);
   getimage(10,10,20,21,tail1);
   cleardevice();
   //tail2-left
   t[0]=10; t[1]=10;
   t[2]=20; t[3]=10;
   t[4]=10; t[5]=15;
   t[6]=20; t[7]=20;
   t[8]=10; t[9]=21;
   fillpoly(5, t);
   size = imagesize(10,10,20,21);
   tail2 = malloc(size);
   getimage(10,10,20,21,tail2);
   cleardevice();
   //tail3-up
   t[0]=10; t[1]=20;
   t[2]=10; t[3]=10;
   t[4]=15; t[5]=20;
   t[6]=20; t[7]=10;
   t[8]=20; t[9]=21;
   fillpoly(5, t);
   size = imagesize(10,10,20,21);
   tail3 = malloc(size);
   getimage(10,10,20,21,tail3);
   cleardevice();
   //tail4-down
   t[0]=10; t[1]=10;
   t[2]=10; t[3]=21;
   t[4]=15; t[5]=10;
   t[6]=20; t[7]=21;
   t[8]=20; t[9]=10;
   fillpoly(5, t);
   size = imagesize(10,10,20,21);
   tail4 = malloc(size);
   getimage(10,10,20,21,tail4);
   cleardevice();
   //head1-right
   setlinestyle(1,1,1);
   setcolor(2);
   fillellipse(10,10,10,5);
   setcolor(4);
   //eyes
   fillellipse(15,7,1,1);
   fillellipse(15,13,1,1);
   size = imagesize(10,5,20,15);
   head1 = malloc(size);
   getimage(10,5,20,15,head1);
   //head2-left
   //eyes
   fillellipse(5,7,1,1);
   fillellipse(5,13,1,1);
   size = imagesize(0,5,10,15);
   head2 = malloc(size);
   getimage(0,5,10,15,head2);
   cleardevice();
   //head3-up
   //eyes
   setcolor(2);
   fillellipse(12,12,5,10);
   setcolor(4);
   fillellipse(9,6,1,1);
   fillellipse(15,6,1,1);
   size = imagesize(7,2,18,12);
   head3 = malloc(size);
   getimage(7,2,18,12,head3);

   //head4-down
   //eyes
   fillellipse(9,17,1,1);
   fillellipse(15,17,1,1);
   size = imagesize(7,12,18,22);
   head4 = malloc(size);
   getimage(7,12,18,22,head4);
   cleardevice();

   //food
   setcolor(15);
   setfillstyle(1,15);
   fillellipse(10,10,3,5);
   size = imagesize(5,3,15,17);
   food = malloc(size);
   getimage(5,3,15,17,food);
   cleardevice();
    /* repeat until a key is pressed */
   maxx=getmaxx();
   maxy=getmaxy();
   setlinestyle(0,1,3);
   setcolor(9);
   rectangle(0,0,maxx,maxy);
   setlinestyle(0,1,2);
   line(maxx-150,0,maxx-150,maxy);
   setcolor(8);
   setfillstyle(1,8);
   bar(maxx-147,3,maxx-3,63);
   setcolor(12);
   int maze=1;
   if(maze==1)
   {
   setfillstyle(1,6);
   bar(4,4,maxx-154,14);
   bar(4,4,14,maxy-4);
   bar(4,maxy-4,maxx-154,maxy-14);
   bar(maxx-154-10,4,maxx-154,maxy-4);
   }

   settextstyle(0,0,1);
   delay(300);
   outtextxy(maxx-125,30,"RATTLE SNAKE");
   delay(300);
   setcolor(11);
   setlinestyle(0,1,2);
   rectangle(maxx-145,65,maxx-5,205);
   outtextxy(maxx-128,70,"INSTRUCTIONS");
   delay(200);
   setcolor(6);
   outtextxy(maxx-140,90,"Commands     Key");
   delay(300);
   setcolor(8);
   outtextxy(maxx-140,110," Move Up      8");
   delay(50);
   outtextxy(maxx-140,130," Move Down    5");
    delay(50);
   outtextxy(maxx-140,150," Move Right   6");
    delay(50);
   outtextxy(maxx-140,170," Move Left    4");
    delay(50);
   outtextxy(maxx-140,190," Exit         0");
   delay(200);
   setcolor(12);
   setlinestyle(0,1,2);
   rectangle(maxx-145,210,maxx-5,350);
   setcolor(1);
   outtextxy(maxx-130,220,"Player's Name");
   setcolor(15);
   outtextxy(maxx-100,230,"Yellow");
   setcolor(4);
   delay(200);
   itoa(score,scor,10);
   outtextxy(maxx-140,250,"Score");
   outtextxy(maxx-50,250,scor);
   delay(200);
   setcolor(10);
   outtextxy(maxx-140,280,"Level");
   delay(200);
   setcolor(13);
   outtextxy(maxx-140,310,"Maze        1");
   delay(200);
   setcolor(14);
   outtextxy(maxx-140,340,"High Score  ");
   outtextxy(maxx-50,340,hs);
   for(j=0; j<=1000; j++)
   {
 putpixel(random(maxx-150),random(maxy),6);
 delay(1);
   }
   while (a!='0')
   {
       // plot new image
      if(a=='6')
     putimage(x, y, head1, XOR_PUT);
      if(a=='4')
     putimage(x, y, head2, XOR_PUT);
      if(a=='8')
     putimage(x, y, head3, XOR_PUT);
      if(a=='5')
     putimage(x, y, head4, XOR_PUT);
      for(j=0; j<k; j++)
      {
    putimage(X[i-j], Y[i-j], body, XOR_PUT);
      }
      if((X[i-j-1]-X[i-j])<0  && (Y[i-j-1]-Y[i-j])==0)
     putimage(X[i-j], Y[i-j], tail1, XOR_PUT);
      if((X[i-j-1]-X[i-j])>0  && (Y[i-j-1]-Y[i-j])==0)
     putimage(X[i-j], Y[i-j], tail2, XOR_PUT);
      if((X[i-j-1]-X[i-j])==0  && (Y[i-j-1]-Y[i-j])<0)
     putimage(X[i-j], Y[i-j], tail3, XOR_PUT);
      if((X[i-j-1]-X[i-j])==0  && (Y[i-j-1]-Y[i-j])>0)
     putimage(X[i-j], Y[i-j], tail4, XOR_PUT);
      delay(speed);
      if(second==1)
      {
 setcolor(15);
 outtextxy(maxx-140,360,"Press Any Key...");
 getch();
 setcolor(0);
 outtextxy(maxx-140,360,"Press Any Key...");
 a='6';
 second=2;
      }

      if(first==1)
      {
 setcolor(15);
 outtextxy(maxx-140,360,"Congratulations  ");
 sound(100);
 delay(300);
 nosound();
 getch();
 setcolor(0);
 outtextxy(maxx-140,360,"Congratulations  ");
 second++;
 first=2;
      }
 // erase old image
      if(a=='6')
     putimage(x, y, head1, XOR_PUT);
      if(a=='4')
     putimage(x, y, head2, XOR_PUT);
      if(a=='8')
     putimage(x, y, head3, XOR_PUT);
      if(a=='5')
     putimage(x, y, head4, XOR_PUT);

      for(j=0; j<k; j++)
      {
    putimage(X[i-j], Y[i-j], body, XOR_PUT);
      }
      if((X[i-j-1]-X[i-j])<0  && (Y[i-j-1]-Y[i-j])==0)
     putimage(X[i-j], Y[i-j], tail1, XOR_PUT);
      if((X[i-j-1]-X[i-j])>0  && (Y[i-j-1]-Y[i-j])==0)
     putimage(X[i-j], Y[i-j], tail2, XOR_PUT);
      if((X[i-j-1]-X[i-j])==0  && (Y[i-j-1]-Y[i-j])<0)
     putimage(X[i-j], Y[i-j], tail3, XOR_PUT);
      if((X[i-j-1]-X[i-j])==0  && (Y[i-j-1]-Y[i-j])>0)
     putimage(X[i-j], Y[i-j], tail4, XOR_PUT);

      if(f==0)
      {
 putimage(r1,r2,food,XOR_PUT);
 f=1;
      }
      z--;
      if((x>=r1 && y>=r2 && x<=r1+10 && y<=r2+10) || (x<=r1 && y<=r2 &&
x>=r1-10 && y>=r2-10) || z==0)
      {
 if(z!=0)
 {
  sound(800);
  delay(20);
  setcolor(0);
  score += 10;
  outtextxy(maxx-50,250,scor);
  itoa(score,scor,10);
  if(score>hscore)
  {
   strcpy(hs,scor);
   setfillstyle(1,1);
   bar(maxx-140,337,maxx-20,348);
   setcolor(14);
   outtextxy(maxx-50,340,hs);
   outtextxy(maxx-140,340,"High Score  ");
   if(first==0)
   {
   first=1;
   }
  }
  setcolor(4);
  outtextxy(maxx-50,250,scor);
  k++;
 nosound();
 }
 z=100;
 putimage(r1,r2,food,XOR_PUT);
 repr1:
 r1=random(450);
     if(r1<50)
        goto repr1;
 repr2:
 r2=random(400);
     if(r2<50)
  goto repr2;
 f=0;
      }

      i++;
      X[i]=x;
      Y[i]=y;
      b=a;
      if(kbhit())
      {
  rep:
  a=getche();
  if((b=='6' && a=='4') || (b=='4' && a=='6'))
   a=b;
  if((b=='8' && a=='5') || (b=='5' && a=='8'))
   a=b;
  if(a!='6' && a!='4' && a!='8' && a!='0' && a!='5')
   a=b;
      }
 /*     if(x>maxx-170)
 x=0;
      if(y>maxy)
 y=0;*/
      if(a=='8')
 y -= bo;
      if(a=='5')
 y += bo;
      if(a=='4')
 x -= bo;
      if(a=='6')
 x += bo;
      for(j=i+1; j<i-k; j--)
      {
 if((Y[i]>=Y[j] && Y[i]<=Y[j]+10) || (Y[i]<=Y[j] && Y[i]>=X[j]-10))
 {
  if((X[i]>=X[j] && X[i]<=X[j]+10) || (X[i]<=X[j] && X[i]>=X[j]-10))
  {
   a='0';
  }
   outtextxy(maxx-140,360,"C ");

 }
 if((X[i]>=X[j] && X[i]<=X[j]+10) || (X[i]<=X[j] && X[i]>=X[j]-10))
 {
  if((Y[i]>=Y[j] && Y[i]<=Y[j]+10) || (Y[i]<=Y[j] && Y[i]>=X[j]-10))
  {
   a='0';
  }
   outtextxy(maxx-140,360,"C  ");
 }
       }
/*      for(j=i; j<i-k; j--)
      {
 if((y>=Y[j] && y<=Y[j]+10) || (y<=Y[j] && y>=Y[j]-10))
 {
  if((x>=X[j] && x<=X[j]+10) || (x<=X[j] && x>=X[j]-10))
  {
   a='5';
  }
 }
 if((x>=X[j] && x<=X[j]+10) || (x<=X[j] && x>=X[j]-10))
 {
  if((y>=Y[j] && y<=Y[j]+10) || (y<=Y[j] && y>=Y[j]-10))
  {
   a='5';
  }
 }
 if(j==0)
  break;
      }      */

  /* if(x<=0)
 x=maxx-170;
 if(y<=0)
 y=maxy;*/
 if(maze==1)
 {
  if(x<=14 || x>=maxx-184 || y<=14 || y>=maxy-14)
  {
     a='0';
  }
 }
   }
   if(score>hscore)
   {
 ofstream onfile("c:\tc\bin\rattle.txt");
 onfile<<scor;
 onfile.close();
   }
   setcolor(15);
   outtextxy(maxx-140,390,"    Gameover");
   sound(100);
   delay(400);
   nosound();
   getch();
   /* clean up */
   free(body);
   closegraph();
}

Draw Triangle in C

Draw Triangle in C Language using C Graphics











#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
void rotabouty(float *x,float *y,float *z);
void rotaboutx(float *x,float *y,float *z);
void rotaboutz(float *x,float *y,float *z);
 char ch;
   float oldx, oldy, oldz;
   double angle;

int main()
{
   int gdriver=DETECT, gmode=DETECT;
   float x1,y1,z1;
   float x2,y2,z2;
   float x3,y3,z3;
   float x5,y5,z5;
   float x6,y6,z6;
   float x7,y7,z7;

   initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
   setviewport(320,235,639,479,0);
   x1=100;y1=100;z1=-100;
   x2=100;y2=-100;z2=-100;
   x3=-100;y3=-100;z3=-100;

   x5=100;y5=100;z5=100;
   x6=100;y6=-100;z6=100;
   x7=-100;y7=-100;z7=100;

   setcolor(1);
   moveto(x1,y1);
   lineto(x2,y2);
   lineto(x3,y3);
   lineto(x1,y1);
    setcolor(4);
   moveto(x5,y5);
   lineto(x6,y6);
   lineto(x7,y7);
   lineto(x5,y5);
   getch();
   do{
  ch=getch();
  if(ch=='s')
  {

  angle=(-10.0)*.017453; //converts the angle into radians
     rotabouty(&x1,&y1,&z1);
     rotabouty(&x2,&y2,&z2);
     rotabouty(&x3,&y3,&z3);
     rotabouty(&x5,&y5,&z5);
     rotabouty(&x6,&y6,&z6);
     rotabouty(&x7,&y7,&z7);

  }
  if(ch=='a')
  {

 angle=10.0*.017453;
     rotabouty(&x1,&y1,&z1);
     rotabouty(&x2,&y2,&z2);
     rotabouty(&x3,&y3,&z3);
     rotabouty(&x5,&y5,&z5);
     rotabouty(&x6,&y6,&z6);
     rotabouty(&x7,&y7,&z7);
  }
  if(ch=='r')
  {

  angle=(-10.0)*.017453;
     rotaboutx(&x1,&y1,&z1);
     rotaboutx(&x2,&y2,&z2);
     rotaboutx(&x3,&y3,&z3);
     rotaboutx(&x5,&y5,&z5);
     rotaboutx(&x6,&y6,&z6);
     rotaboutx(&x7,&y7,&z7);

  }
  if(ch=='v')
  {
  angle=10.0*.017453;

     rotaboutz(&x1,&y1,&z1);
     rotaboutz(&x2,&y2,&z2);
     rotaboutz(&x3,&y3,&z3);
     rotaboutz(&x5,&y5,&z5);
     rotaboutz(&x6,&y6,&z6);
     rotaboutz(&x7,&y7,&z7);

  }
  if(ch=='e')
  {

  angle=(-10.0)*.017453;
     rotaboutz(&x1,&y1,&z1);
     rotaboutz(&x2,&y2,&z2);
     rotaboutz(&x3,&y3,&z3);
     rotaboutz(&x5,&y5,&z5);
     rotaboutz(&x6,&y6,&z6);
     rotaboutz(&x7,&y7,&z7);

  }
  if(ch=='h')
  {
  angle=10.0*.017453;

     rotaboutx(&x1,&y1,&z1);
     rotaboutx(&x2,&y2,&z2);
     rotaboutx(&x3,&y3,&z3);
     rotaboutx(&x5,&y5,&z5);
     rotaboutx(&x6,&y6,&z6);
     rotaboutx(&x7,&y7,&z7);

  }
   setviewport(0,0,639,479,0);
   clearviewport();
   setviewport(320,235,639,479,0);
   setcolor(YELLOW);
   moveto(x1,y1);
   lineto(x2,y2);
   lineto(x3,y3);
   lineto(x1,y1);

   setcolor(15);
   moveto(x5,y5);
   lineto(x6,y6);
   lineto(x7,y7);
   lineto(x5,y5);

   } while (ch!='p');
   getch();
   closegraph();
   return 0;
}
 void rotabouty(float *x,float *y,float *z)
   {
  oldx=*x;
      oldy=*y;
      oldz=*z;
      *x = (oldx*cos(angle)) - (oldz*sin(angle));
      *y = *y;
      *z =(oldx*sin(angle)) + (oldz*cos(angle));
    }
    void rotaboutx(float *x,float *y,float *z)
    {
      oldx=*x;
      oldy=*y;
      oldz=*z;
      *x=*x;
      *y=(oldz*sin(angle))+(oldy*cos(angle));
      *z=(oldz*cos(angle))-(oldy*sin(angle));
    }
    void rotaboutz(float *x,float *y,float *z)
    {
      oldx=*x;
      oldy=*y;
      oldz=*z;
      *x=(oldx*sin(angle))+(oldy*cos(angle));
      *y=(oldx*cos(angle))-(oldy*sin(angle));
      *z=*z;
    }