Classic Car Game (C with Graphics)

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

#define RIGHT 19712
#define LEFT 19200
#define UP 18432
#define DOWN 20480

int carArr[5][2];
unsigned long int score = 0;

//to draw the path
void drawPath() {
   bar(210,40,222,440);
   bar(318,40,322,440);
   bar(418,40,430,440);
}

//this function will draw the car at given position and in given color
void drawCar( int row, int col, int last, int color ) {
   int r = row,c = col;
   switch( last ) {
  case LEFT  : c = col + 1;

        break;
  case RIGHT : c = col - 1;
        break;
  case UP    : r = row + 1;
        break;
  case DOWN  : r = row - 1;
        break;
      }
   setfillstyle( SOLID_FILL, BLACK ); // to erase
   bar( 260 + c * 100 , 40 + r * 80 , 280 + c * 100 , 60 + r * 80 );
   bar( 240 + c * 100 , 60 + r * 80 , 300 + c * 100 , 80 + r * 80  );
   bar( 260 + c * 100 , 80 + r * 80 , 280 + c * 100 , 100 + r * 80  );
   bar( 240 + c * 100 , 100 + r * 80 , 300 + c * 100 , 120 + r * 80  );
   setfillstyle( SOLID_FILL, color );  // to draw
   bar( 260 + col * 100 , 40 + row * 80 , 280 + col * 100 , 60 + row * 80 );
   bar( 240 + col * 100 , 60 + row * 80 , 300 + col * 100 , 80 + row * 80  );
   bar( 260 + col * 100 , 80 + row * 80 , 280 + col * 100 , 100 + row * 80  );
   bar( 240 + col * 100 , 100 + row * 80 , 300 + col * 100 , 120 + row * 80  );
   carArr[row][col] = 1;
   carArr[r][c] = 0;
}

//this function will erase the car and place it in new position
//when we make a move
void eraseBottom( int c ) {
   int r = 4;
   setfillstyle( SOLID_FILL, BLACK ); // to erase
   bar( 260 + c * 100 , 40 + r * 80 , 280 + c * 100 , 60 + r * 80 );
   bar( 240 + c * 100 , 60 + r * 80 , 300 + c * 100 , 80 + r * 80  );
   bar( 260 + c * 100 , 80 + r * 80 , 280 + c * 100 , 100 + r * 80  );
   bar( 240 + c * 100 , 100 + r * 80 , 300 + c * 100 , 120 + r * 80  );
   carArr[r][c] = 0;
}

//this function will tell where we have to place the enemy car
void enemy( int row, int col) {
   if(  carArr[ row ][ col ] == 0 ) {
      if( row < 5 ) {
  drawCar( row++, col , DOWN, WHITE );
      }
   } else if( carArr[ row ][ col ] == 1 ) {
      gotoxy(1,1);
      printf("You Lost The Game!!!!");
      getch();
      exit(0);
   }
}
//this is the master of all functions
//this will generate the random numbers and positions for enemy cars
//this function will instruct the action to be done according to the players
//move!!
//Here speed will be increasing gradually when score increases
void play() {
   int key;
   int row = 4, col = 0;
   int r = row,c = col;
   unsigned int last;
   int ctr1 = 0, ctr2 = -2;
   int col1, col2, col3;
   col1 = rand() % 2;
   col2 = rand() % 2;
   col3 = rand() % 2;
   drawCar( row, col, RIGHT, RED );

   while( key != 283 ) {
      while( bioskey( 1 ) == 0 ) {
  while( kbhit() == 0 ) {
     gotoxy(1,5);
     printf("Score : %lu", score);
     if( ctr1 < 5 ) {
        enemy( ctr1 , col1 );
        enemy( ctr2 , col2 );
        if( ctr1 == 4 ) {
    enemy( 0 , col3 );
        }
     } else {
        score += 100;
        gotoxy(1,5);
        printf("Score : %lu", score);
        eraseBottom(col1);
        ctr1 = ctr2;
        ctr2 = 1;
        col1 = col2;
        col2 = col3;
        col3 = rand() % 2;
        enemy( ctr1 , col1 );
        enemy( ctr2 , col2 );
     }
     ctr1++;
     ctr2++;
     //delay(500);
     if( score < 1000 )
        delay(750);
     else if( score < 2000 )
        delay(500);
     else if( score < 3000 )
        delay(400);
     else if( score < 4000 )
        delay( 350 );
     else if( score < 5000 )
        delay(300);

  }
      }
      key = bioskey( 0 );

      switch( key ) {
  case LEFT  : c = col - 1;
        last = LEFT;
        break;
  case RIGHT : c = col + 1;
        last = RIGHT;
        break;
  case UP    : r = row - 1;
        last = UP;
        break;
  case DOWN  : r = row + 1;
        last = DOWN;
        break;
      }
      if( c < 0 )   c = 0;
      if( r < 0 )   r = 0;
      if( c > 1 )   c = 1;
      if( r > 4 )   r = 4;

      if( carArr[r][c] != 0 ) {
  gotoxy(1,1);
  printf("You Lost The Game!!!!");
  getch();
  exit(0);
      }
      drawCar(r,c,last, RED);
      row = r;
      col = c;
   }
}

// and ofcourse... this is the main function() ;)
void main() {
   int gdriver = DETECT, gmode;
   initgraph( &gdriver, &gmode, "c:\\turboc3\\bgi" );
   drawPath();
   play();
   closegraph();
}


Posted by Unknown

DirectX Components

 

 
 

DirectDraw

DirectDraw is a software interface that provides direct access to display devices while maintaining compatibility with the Windows graphics device interface (GDI).

Direct3D

An API for manipulating and displaying three-dimensional objects. Developed by Microsoft, Direct3D provides programmers with a way to develop 3-D programs that can use whatever graphics acceleration device is installed in the machine. Virtually all 3-D accelerator cards for PCs support Direct3D.

DirectSound

 

 DirectSound enables the playing of sounds with very low latency and gives applications a high level of control over hardware resources.

DirectMusic

In combination with Microsoft DirectSound, DirectMusic provides a complete solution for playing music and sound effects in games and other applications.

DirectInput

DirectInput enables an application to retrieve data from input devices even when the application is in the background. It also provides full support for any type of input device, as well as for force feedback.

DirectPlay

DirectPlay is a media-independent networking API that provides networking services at the transport protocol and session protocol levels. DirectPlay sessions can be run on TCP/IP networks, IPX networks, and over directly connected modems and serial cables.

DirectShow

DirectShow is an architecture for streaming media on a Windows platform. It provides high-quality capture and playback of multimedia streams.


Donwload Link:http://www.mediafire.com/download/y0g9ctgqqme518e/directx_Jun2010_redist.exe
Posted by Unknown

Change Your IP Address


1. Click on "Start" in the bottom left hand corner of screen
2. Click on "Run"
3. Type in "cmd" and hit ok You should now be at an
MSDOS prompt screen.
4. Type "ipconfig /release" just like that, and hit "enter"
5. Type "exit" and leave the prompt
6. Right-click on "Network Places" or "My Network Places"
on your desktop.
7. Click on "properties" You should now be on a screen
with something titled "Local Area Connection", or
something close to that, and, if you have a network
hooked up, all of your other networks.
8. Right click on "Local Area Connection" and click
"properties"
9. Double-click on the "Internet Protocol (TCP/IP)" from
the list under the "General" tab
10. Click on "Use the following IP address" under the
"General" tab 11. Create an IP address (It doesn't matter
what it is. I just type 1 and 2 until i fill the area up).
12. Press "Tab" and it should automatically fill in the
"Subnet Mask" section with default numbers.
13. Hit the "Ok" button here
14. Hit the "Ok" button again
You should now be back to the "Local Area Connection"
screen.
15. Right-click back on "Local Area Connection" and go to
properties again.

16. Go back to the "TCP/IP" settings
17. This time, select "Obtain an IP address automatically"

18. Hit "Ok"
19. Hit "Ok" again
20. You now have a new IP address With a little practice,
you can easily get this process down to 15 seconds.
Posted by Unknown

How to bypass android pattern lock

You'll need:
Linux distro of your choice
Android phone
Android USB Data cable
Android ADB
Execution:
1. Connect your phone to your PC
using USB cable.
2. Install ADB via terminal
Boot into any Linux distro you have.
Open up terminal and type :
sudo apt-get install android-tools-a
db

This will install ADB.
To disabling the pattern lock via
terminal
adb devices
adb shell
cd data/system
su
rm *.key

Disconnect your phone and reboot.
Unlock pattern should be here. Just
try some random gesture and it will
unlock.
Posted by Unknown

Sudoku Game(C++ Program)

 
 
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
int a[9][9],b[9][9],r[60][2];
int row, col, icount, mode;
char solh;
void main()
{
void readvalues(void), display(void),generate(void);
int solve(),checkmat(), checkrow(), checkcolumn(),check(),isfixed();
int i,j,error;
char c;
clrscr();
printf("\n\n\n\n\t\tEnter '1' to play SuDoKu Puzzle\n\n\t\tEnter any other key to generate SuDoKu\n\n\n\n\t\tEnter: ");
scanf("%c",&c);
if(c=='1')
    {
    getchar();
    generate();
    if(solh=='y' || solh=='Y')
    readvalues();
    for(i=0;i<9;i++)
    for(j=0;j<9;j++)
    a[i][j]=b[i][j];
    clrscr();
    display();
    getchar();
    getchar();
    exit(0);
    }
clrscr();
printf("\n\n\t\t\tHOW TO ENTER ELEMENTS\n");
printf("\n\n1.Enter the elements by specifying the row and column number of\n  corresponding location");
printf("\n\n2.Each row and column start from 1 and end at 9 (not from 0 to 8)");
printf("\n\n3.After finishing entering the elements, enter zeroes (0)\n  for row or column");
printf("\n\n4.If an element entered in a wrong location has to be deleted,\n  enter zero in that location");
printf("\n\n\n\n\t\t\t  Enter any key to continue");
getchar();
read:
icount=0;
row=0; col=0;
for(i=0;i<9;i++)
for(j=0;j<9;j++)
a[i][j]=0;
for(i=0;i<60;i++)
    {
    r[i][0]=20; r[i][1]=20;
    }
    clrscr();
    readvalues();
    getchar();
    clrscr();
    ask:
    display();
    printf("\n\nEnter 'm' to MODIFY\nEnter 'r' to RE-ENTER\nEnter any other key for SUDOKU Solution: ");
    scanf("%c",&c);
    if(c=='r' || c=='R')
        {
        clrscr();
        goto read;
        }
    if(c=='m' || c=='M')
        {
        printf("\n\n");
        readvalues();
        clrscr();
        getchar();
        goto ask;
        }
    next:
    error=solve();
    clrscr();
    display();
    if(error==0)
    printf("\n\n\n\n\rNO SUOLUTION or TOO MANY MODIFICATIONS");
    cprintf("\n\n\n\n\n\rEnter c to continue and any other key to exit: ");
    scanf("%c",&c);
    if(c=='c')
    goto read;
    getchar();
}

/*FUNTION TO READ ELEMENTS*/

void readvalues()
{
int i=icount,j,x,y,chek;
void display(void);
int check(int,int);
clrscr();
do
{
display();
printf("\n");
row:
printf("\n\nEnter row: ");
scanf("%d",&r[i][0]);
if(r[i][0]==0)
    {
    r[i][0]=100; r[i][1]=100;
    break;
    }
if(r[i][0]>10 || r[i][0]<0)
    {
    printf("\nInvalid size\nEnter again");
    r[i][0]=20; r[i][1]=20;
    getchar();
    goto row;
    }
column:
printf("Enter column: ");
scanf("%d",&r[i][1]);
if(r[i][1]==0)
    {
    r[i][0]=100; r[i][1]=100;
    break;
    }
if(r[i][1]<0 || r[i][1]>10)
    {
    printf("\nInvalid size\nEnter again\n\n");
    r[i][0]=20; r[i][1]=20;
    getchar();
    goto column;
    }
r[i][0]=r[i][0]-1; r[i][1]=r[i][1]-1;
x=r[i][0]; y=r[i][1];
if(solh=='y' || solh=='Y')
for(j=0;j<icount;j++)
    {
    if(x==r[j][0] && y==r[j][1])
        {
        printf("This location is fixed and cannot be changed");
        goto row;
        }
    else
        r[i][0]=20; r[i][1]=20;
    }
scan:
printf("Enter the corresponding number: ");
scanf("%d",&a[x][y]);
if(a[x][y]==0)
    {
    for(j=0;j<icount;j++)
        {
        if(x==r[j][0] && y==r[j][1])
            {
            r[j][0]=20; r[j][1]=20;
            goto end;
            }
        if(solh=='y' || solh=='Y')
            {
            r[i][0]=20; r[i][1]=20;
            goto end;
            }
        }
    }
if(a[x][y]>9 || a[x][y]<=0)
    {
     printf("\nNumber out of range\nEnter again\n\n");
     a[x][y]=0;
     goto scan;
     }
else
{
chek=check(x,y);
if(chek==0)
    {
    printf("\nInconsistent number\nEnter again");
    a[x][y]=0; r[i][0]=20; r[i][1]=20;
    goto row;
    }
}
if(solh!='y' && solh!='Y')
    {
    icount++; i++;
    }
end:
clrscr();
}while(r[i-1][0]!=-1 || r[i-1][1]!=-1);
}

isfixed(int count, int m, int n)
{
int i;
for(i=0;i<count;i++)
if(m==r[i][0] && n==r[i][1])
return(1);
return(0);
}

/*FUNCTION TO DISPLAY SUDOKU*/

void display()
{
int i,j,k,fixed;
gotoxy(6,0);
for(i=0;i<10;i++)
    {
    if(i%3==0)
        {
        textcolor(WHITE);
        if(i!=0)
        printf("\n");
        printf("\t\t");
        for(k=0;k<45;k++)
        cprintf("*");
        if(i==9)
        goto end;
        }
    if(i%3!=0)
        {
        textcolor(WHITE);
        printf("\n\t\t");
        printf("|\t\t\b|\t\t\b\b|\t\t\t\b\b\b\b|");
        printf("\n\t\t");
        }
    else
    printf("\n\t\t");
    for(j=0;j<9;j++)
        {
        if(j%3==0)
            {
            if(a[i][j]==0)
                {
                textcolor(WHITE);
                cprintf("|");
                for(k=0;k<4;k++)
                printf(" ");
                }
            else
                {
                textcolor(WHITE);
                cprintf("| ",a[i][j]);
                fixed=isfixed(icount,i,j);
                if(fixed==1)
                textcolor(LIGHTRED);
                else
                textcolor(LIGHTGREEN);
                cprintf("%d  ",a[i][j]);
                }
            }
        else
            {
            if(a[i][j]==0)
            for(k=0;k<5;k++)
            printf(" ");
            else
                {
                fixed=isfixed(icount,i,j);
                if(fixed==1)
                textcolor(LIGHTRED);
                else
                textcolor(LIGHTGREEN);
                cprintf("  %d  ",a[i][j]);
                }
            }
        }textcolor(WHITE);
        cprintf("\b|");
    }end:
}


int checkmat(int m, int n)
{
int x,y;
for(x=(m/3)*3;x<((m/3)*3+3);x++)
for(y=(n/3)*3;y<((n/3)*3+3);y++)
    {
    if(m!=x && n!=y)
    if(a[m][n]==a[x][y])
    return(0);
    }
return(1);
}


int checkrow(int m, int n)
{
int x;
for(x=0;x<9;x++)
    {
    if(x!=n)
    if(a[m][n]==a[m][x])
    return(0);
    }
return(1);
}


int checkcolumn(int m, int n)
{
int x;
for(x=0;x<9;x++)
    {
    if(x!=m)
    if(a[m][n]==a[x][n])
    return(0);
    }
return(1);
}

/*FUNCTION TO CHECK CONSISTENCY OF AN ELEMENT*/

int check(int m,int n)
{
int c;
c=checkmat(m,n);
if(c==1)
c=c*checkrow(m,n);
else
return(c);
if(c==1)
c=c*checkcolumn(m,n);
else
return(c);
return(c);
}

/*FUNCTION TO SOLVE SUDOKU*/

solve()
{
int i,m=0,n=0,number,c,fixed;

mainallot:

for(m=row;m<9;m++)
    {
    n=col;
    while(n<9)
        {
        number=1;
        fixed=isfixed(icount,m,n);
        if(fixed==0)
            {
            allot:
            a[m][n]=number;
            c=check(m,n);
            if(c==0)
                {
                number++;
                if(number>9)
                    {
                    a[m][n]=0;
                    if(n==0)
                        {
                        row=m-1; col=8;
                        if(row<0)
                        return(0);
                        goto backadjust;
                        }
                    else
                        {
                        row=m; col=n-1;
                        if(row<0 || col<0)
                        return(0);
                        goto backadjust;
                        }
                    }
                goto allot;
                }
            }
        n++;
        if(n>8)
        col=0;
        }
    }
return(1);

backadjust:

fixed=isfixed(icount,row,col);
if(fixed==0)
    {
    number=a[row][col];
    allot1:
    number++;
    a[row][col]=number;
    if(number>9)
        {
        a[row][col]=0;
        if(col==0)
            {
            row--; col=8;
            if(row<0)
            return(0);
            goto backadjust;
            }
        else
            {
            col--;
            if(col<0)
            return(0);
            goto backadjust;
            }
        }
    c=check(row,col);
    if(c==0)
    goto allot1;
    else
        {
        if(col==8)
            {
            row++;
            if(row>8)
            return(0);
            col=0;
            goto mainallot;
            }
        else
            {
            col++;
            if(col>8)
            return(0);
            goto mainallot;
            }
        }
    }
else
    {
    if(col==0)
        {
        row--; col=8;
        if(row<0)
        return(0);
        goto backadjust;
        }
    else
        {
        col--;
        if(col<0)
        return(0);
        goto backadjust;
        }
    }
}

/*FUNCTION TO GENERATE SODOKU*/

void generate()
{
int c,i,m,n,count=1,fixed,error;
char choice;
randomize();
generate:
for(m=0;m<9;m++)
for(n=0;n<9;n++)
a[m][n]=0;
for(i=0;i<60;i++)
    {
    r[i][0]=20; r[i][1]=20;
    }
clrscr();
printf("\n\n\n\n\t\tEnter your choice of difficulty");
printf("\n\n\n\t\t1.VERY EASY\n\n\t\t2.EASY\n\n\t\t3.MEDIUM\n\n\t\t4.HARD\n\n\n\t\tENTER: ");
scanf("%c",&choice);
switch(choice)
    {
    case '1': mode=34+random(4);
          break;
    case '2': mode=29+random(4);
          break;
    case '3': mode=27+random(2);
          break;
    case '4': mode=25+random(2);
          break;
    default : getchar();
              goto generate;
    }
a[0][0]=1+random(8); r[0][0]=0; r[0][1]=0;
for(count=1;count<10;count++)
    {
    choose:
    m=random(9); n=random(9);
    fixed=isfixed(icount,m,n);
    if(fixed==1)
    goto choose;
    r[count][0]=m; r[count][1]=n;
    allot:
    a[m][n]=1+random(9);
    if(a[m][n]==0)
    goto allot;
    c=check(m,n);
    if(c==0)
    goto allot;
    }
icount=count;
error=solve();
for(m=0;m<9;m++)
for(n=0;n<9;n++)
b[m][n]=a[m][n];
row=0; col=0;
for(i=0;i<60;i++)
    {
    r[i][0]=20; r[i][1]=20;
    }
if(error==0)
goto generate;
for(count=0;count<mode/2;count++)
    {
    choose2:
    m=random(9); n=random(5);
    fixed=isfixed(count,m,n);
    if(fixed==1)
    goto choose2;
    r[count][0]=m; r[count][1]=n;
    r[count+mode/2][0]=8-m;
    r[count+mode/2][1]=8-n;
    }
for(m=0;m<9;m++)
for(n=0;n<9;n++)
    {
    fixed=isfixed(mode,m,n);
    if(fixed!=1)
    a[m][n]=0;
    }
icount=mode;
clrscr();
display();
getchar();
printf("\n\n\nEnter 'y' to solve by yourself\nEnter 's' for solution\nEnter 'm' to generate more sudoku puzzles");
printf("\nAnd any other key to exit: ");
scanf("%c", &solh);
if(solh=='y' || solh=='Y' || solh=='s' || solh=='S')
return;
getchar();
if(solh=='m' || solh=='M')
goto generate;
exit(0);
}
 

Posted by Unknown

Differrence Between Intel CoreI3,Intel Core I5 and Intel Core I7.

-> Core i3:
* Entry level processor.
* 2-4 Cores * 4 Threads
* Hyper-Threading (efficient use of processor
resources)
* 3-4 MB Cache
* 32 nm Silicon (less heat and
energy)




-> Core i5: Mid range processor.
* 2-4 Cores
* 4 Threads
* Turbo Mode (turn off core if
not used)
* Hyper-Threading (efficient use of processor
resources)
* 3-8 MB Cache
* 32-45 nm Silicon (less heat
and energy)



Core i7: High end processor.
* 4 Cores
* 8 Threads
* Turbo Mode (turn off core if
not used)
* Hyper-Threading (efficient use of processor
resources)
* 4-8 MB Cache
* 32-45 nm Silicon (less heat
and energy)


Posted by Unknown

C++ program to find whether a number is an Armstrong number

What is an Armstrong number?
A number is armstrong if the sum of cubes of individual digits of a number is equal to the number itself. For example 153 is an armstrong number as 1 + 125 + 27 = 153.


‪int main()
{
int n,m=0,x,y;
cout<<"Enter any three digit number:";
cin>>n;
y=n;

while(n!=0)
{
x=n%10;
m+=(x*x*x);
n=n/10;
}

if(y==m)
cout<<"The number is an Armstrong number";
else
cout<<"The number is not an Armstrong number";

return 0;
}






Posted by Unknown

© Information Technology