Friday 7 February 2014

DIFFERENT GAME

TO LEARN ABOUT THE C_LANGUAGE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


FIRST OF ALL THE PROGRAMMING LANGUAGE IS VERY EASY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include<time.h>
#include<ctype.h>
#include <time.h>
#include <windows.h>
#include <process.h>

#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77

int length;
int bend_no;
int len;
char key;
void record();
void load();
int life;
void Delay(long double);
void Move();
void Food();
int Score();
void Print();
void gotoxy(int x, int y);
void GotoXY(int x,int y);
void Bend();
void Boarder();
void Down();
void Left();
void Up();
void Right();
void ExitGame();
int Scoreonly();

struct coordinate{
    int x;
    int y;
    int direction;
};

typedef struct coordinate coordinate;

coordinate head, bend[500],food,body[30];

int main()
{

    char key;

    Print();

    system("cls");

    load();

    length=5;

    head.x=25;

    head.y=20;

    head.direction=RIGHT;

    Boarder();

    Food(); //to generate food coordinates initially

    life=3; //number of extra lives

    bend[0]=head;

    Move();   //initialing initial bend coordinate

    return 0;

}

void Move()
{
    int a,i;

    do{

        Food();
        fflush(stdin);

        len=0;

        for(i=0;i<30;i++)

        {

            body[i].x=0;

            body[i].y=0;

            if(i==length)

            break;

        }

        Delay(length);

        Boarder();

        if(head.direction==RIGHT)

            Right();

        else if(head.direction==LEFT)

            Left();

        else if(head.direction==DOWN)

            Down();

        else if(head.direction==UP)

            Up();

        ExitGame();

    }while(!kbhit());

    a=getch();

    if(a==27)

    {

        system("cls");

        exit(0);

    }
    key=getch();

    if((key==RIGHT&&head.direction!=LEFT&&head.direction!=RIGHT)||(key==LEFT&&head.direction!=RIGHT&&head.direction!=LEFT)||(key==UP&&head.direction!=DOWN&&head.direction!=UP)||(key==DOWN&&head.direction!=UP&&head.direction!=DOWN))

    {

        bend_no++;

        bend[bend_no]=head;

        head.direction=key;

        if(key==UP)

            head.y--;

        if(key==DOWN)

            head.y++;

        if(key==RIGHT)

            head.x++;

        if(key==LEFT)

            head.x--;

        Move();

    }

    else if(key==27)

    {

        system("cls");

        exit(0);

    }

    else

    {

        printf("\a");

        Move();

    }
}

void gotoxy(int x, int y)
{

 COORD coord;

 coord.X = x;

 coord.Y = y;

 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}
void GotoXY(int x, int y)
{
    HANDLE a;
    COORD b;
    fflush(stdout);
    b.X = x;
    b.Y = y;
    a = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(a,b);
 }
void load(){
    int row,col,r,c,q;
    gotoxy(36,14);
    printf("loading...");
    gotoxy(30,15);
    for(r=1;r<=20;r++){
    for(q=0;q<=100000000;q++);//to display the character slowly
    printf("%c",177);}
    getch();
}
void Down()
{
    int i;
    for(i=0;i<=(head.y-bend[bend_no].y)&&len<length;i++)
    {
        GotoXY(head.x,head.y-i);
        {
            if(len==0)
                printf("v");
            else
                printf("*");
        }
        body[len].x=head.x;
        body[len].y=head.y-i;
        len++;
    }
    Bend();
    if(!kbhit())
        head.y++;
}
void Delay(long double k)
{
    Score();
    long double i;
    for(i=0;i<=(10000000);i++);
}
void ExitGame()
{
    int i,check=0;
    for(i=4;i<length;i++)   //starts with 4 because it needs minimum 4 element to touch its own body
    {
        if(body[0].x==body[i].x&&body[0].y==body[i].y)
        {
            check++;    //check's value increases as the coordinates of head is equal to any other body coordinate
        }
        if(i==length||check!=0)
            break;
    }
    if(head.x<=10||head.x>=70||head.y<=10||head.y>=30||check!=0)
    {
        life--;
        if(life>=0)
        {
            head.x=25;
            head.y=20;
            bend_no=0;
            head.direction=RIGHT;
            Move();
        }
        else
        {
            system("cls");
            printf("All lives completed\nBetter Luck Next Time!!!\nPress any key to quit the game\n");
            record();
            exit(0);
        }
    }
}
void Food()
{
    if(head.x==food.x&&head.y==food.y)
    {
        length++;
        time_t a;
        a=time(0);
        srand(a);
        food.x=rand()%70;
        if(food.x<=10)
            food.x+=11;
        food.y=rand()%30;
        if(food.y<=10)

            food.y+=11;
    }
    else if(food.x==0)/*to create food for the first time coz global variable are initialized with 0*/
    {
        food.x=rand()%70;
        if(food.x<=10)
            food.x+=11;
        food.y=rand()%30;
        if(food.y<=10)
            food.y+=11;
    }
}
void Left()
{
    int i;
    for(i=0;i<=(bend[bend_no].x-head.x)&&len<length;i++)
    {
        GotoXY((head.x+i),head.y);
       {
                if(len==0)
                    printf("<");
                else
                    printf("*");
        }
        body[len].x=head.x+i;
        body[len].y=head.y;
        len++;
    }
    Bend();
    if(!kbhit())
        head.x--;

}
void Right()
{
    int i;
    for(i=0;i<=(head.x-bend[bend_no].x)&&len<length;i++)
    {
        //GotoXY((head.x-i),head.y);
        body[len].x=head.x-i;
        body[len].y=head.y;
        GotoXY(body[len].x,body[len].y);
        {
            if(len==0)
                printf(">");
            else
                printf("*");
        }
        /*body[len].x=head.x-i;
        body[len].y=head.y;*/
        len++;
    }
    Bend();
    if(!kbhit())
        head.x++;
}
void Bend()
{
    int i,j,diff;
    for(i=bend_no;i>=0&&len<length;i--)
    {
            if(bend[i].x==bend[i-1].x)
            {
                diff=bend[i].y-bend[i-1].y;
                if(diff<0)
                    for(j=1;j<=(-diff);j++)
                    {
                        body[len].x=bend[i].x;
                        body[len].y=bend[i].y+j;
                        GotoXY(body[len].x,body[len].y);
                        printf("*");
                        len++;
                        if(len==length)
                            break;
                    }
                else if(diff>0)
                    for(j=1;j<=diff;j++)
                    {
                        /*GotoXY(bend[i].x,(bend[i].y-j));
                        printf("*");*/
                        body[len].x=bend[i].x;
                        body[len].y=bend[i].y-j;
                        GotoXY(body[len].x,body[len].y);
                        printf("*");
                        len++;
                        if(len==length)
                            break;
                    }
            }
        else if(bend[i].y==bend[i-1].y)
        {
            diff=bend[i].x-bend[i-1].x;
            if(diff<0)
                for(j=1;j<=(-diff)&&len<length;j++)
                {
                    /*GotoXY((bend[i].x+j),bend[i].y);
                    printf("*");*/
                    body[len].x=bend[i].x+j;
                    body[len].y=bend[i].y;
                    GotoXY(body[len].x,body[len].y);
                        printf("*");
                   len++;
                   if(len==length)
                           break;
               }
           else if(diff>0)
               for(j=1;j<=diff&&len<length;j++)
               {
                   /*GotoXY((bend[i].x-j),bend[i].y);
                   printf("*");*/
                   body[len].x=bend[i].x-j;
                   body[len].y=bend[i].y;
                   GotoXY(body[len].x,body[len].y);
                       printf("*");
                   len++;
                   if(len==length)
                       break;
               }
       }
   }
}
void Boarder()
{
   system("cls");
   int i;
   GotoXY(food.x,food.y);   /*displaying food*/
       printf("F");
   for(i=10;i<71;i++)
   {
       GotoXY(i,10);
           printf("!");
       GotoXY(i,30);
           printf("!");
   }
   for(i=10;i<31;i++)
   {
       GotoXY(10,i);
           printf("!");
       GotoXY(70,i);
       printf("!");
   }
}
void Print()
{
   //GotoXY(10,12);
   printf("\tSANKE GAME MADE BY ADNAN SHAHID(LOVEING CODING)\n\t STARING GAME PLEASE WAIT");
   sleep(3000);
   printf("\n\tWelcome to the mini Snake game.(press any key to continue)\n");
  getch();
   system("cls");
   printf("\tGame instructions:\n");
   printf("\n-> Use arrow keys to move the snake.\n\n-> You will be provided foods at the several coordinates of the screen which you have to eat. Everytime you eat a food the length of the snake will be increased by 1 element and thus the score.\n\n-> Here you are provided with three lives. Your life will decrease as you hit the wall or snake's body.\n\n-> YOu can pause the game in its middle by pressing any key. To continue the paused game press any other key once again\n\n-> If you want to exit press esc. \n");
   printf("\n\nPress any key to play game...");
   if(getch()==27)
   exit(0);
}
void record(){
   char plname[20],nplname[20],cha,c;
   int i,j,px;
   FILE *info;
   info=fopen("record.txt","a+");
   getch();
   system("cls");
   printf("Enter your name\n");
   scanf("%[^\n]",plname);
   //************************
   for(j=0;plname[j]!='\0';j++){ //to convert the first letter after space to capital
   nplname[0]=toupper(plname[0]);
   if(plname[j-1]==' '){
   nplname[j]=toupper(plname[j]);
   nplname[j-1]=plname[j-1];}
   else nplname[j]=plname[j];
   }
   nplname[j]='\0';
   //*****************************
   //sdfprintf(info,"\t\t\tPlayers List\n");
   fprintf(info,"Player Name :%s\n",nplname);
    //for date and time

   time_t mytime;
  mytime = time(NULL);
  fprintf(info,"Played Date:%s",ctime(&mytime));
     //**************************
     fprintf(info,"Score:%d\n",px=Scoreonly());//call score to display score
     //fprintf(info,"\nLevel:%d\n",10);//call level to display level
   for(i=0;i<=50;i++)
   fprintf(info,"%c",'_');
   fprintf(info,"\n");
   fclose(info);
   printf("wanna see past records press 'y'\n");
   cha=getch();
   system("cls");
   if(cha=='y'){
   info=fopen("record.txt","r");
   do{
       putchar(c=getc(info));
       }while(c!=EOF);}
     fclose(info);
}
int Score()
{
   int score;
   GotoXY(20,8);
   score=length-5;
   printf("SCORE : %d",(length-5));
   score=length-5;
   GotoXY(50,8);
   printf("Life : %d",life);
   return score;
}
int Scoreonly()
{
int score=Score();
system("cls");
return score;
}
void Up()
{
   int i;
   for(i=0;i<=(bend[bend_no].y-head.y)&&len<length;i++)
   {
       GotoXY(head.x,head.y+i);
       {
           if(len==0)
               printf("^");
           else
               printf("*");
       }
       body[len].x=head.x;
       body[len].y=head.y+i;
       len++;
   }
   Bend();
   if(!kbhit())
       head.y--;
}
///////////////made by adnan shahid




QUIZ GAME!!!!!!!!!!!!!!!!!

#include<stdio.h>
#include<conio.h>
#include <windows.h>
#include<ctype.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>

void displayscore()
 {
 char name[20];
 float s;
 FILE *f;
 system("cls");
 f=fopen("score.txt","r");
 fscanf(f,"%s%f",&name,&s);
 printf("\n\n\t\t ");
 printf("\n\n\t\t %s has secured the Highest Score %.2f",name,s);
 printf("\n\n\t\t ");
 fclose(f);
 getch();
 }



void help()
 {
 system("cls");
 printf("\n\n\n\tThis game is very easy to play. You'll be asked some general");
 printf("\n\n\tknowledge questions and the right answer is to be chosen among");
 printf("\n\n\tthe four options provided. Your score will be calculated at the");
 printf("\n\n\tend. Remember that the more quicker you give answer the more");
 printf("\n\n\tscore you will secure. Your score will be calculated and displayed");
 printf("\n\n\tat the end and displayed. If you secure highest score, your score");
 printf("\n\n\twill be recorded. So BEST OF LUCK.");
 }
void writescore(float score, char plnm[20])
 {
 float sc;
 char nm[20];
 FILE *f;
 system("cls");
 f=fopen("score.txt","r");
 fscanf(f,"%s%f",&nm,&sc);
 if (score>=sc)
   { sc=score;
     fclose(f);
     f=fopen("score.txt","w");
     fprintf(f,"%s\n%.2f",plnm,sc);
     fclose(f);
   }
 }
int main()
     {
     int countq,countr;
     int r,i;
     int pa;int nq[6];int w;
     float score;
     char choice;
     char playername[20];
     time_t initialtime,finaltime;
     system("cls");
   
     //randomize();
     mainhome:
     system("cls");
     puts("\n\t\t WELCOME TO QUIZ MADE BY ADNAN SHAHID LOVING CODING  \n\n") ;
     puts("\n\t\t-------------------------------");
     puts("\n\t\t Enter 'S' to start game       ");
     puts("\n\t\t Enter 'V' to view high score  ");
     puts("\n\t\t Enter 'H' for help            ");
     puts("\n\t\t Enter 'Q' to quit             ");
     printf("\n\t\t-------------------------------\n\n\t\t  ");
     choice=toupper(getch());
     if (choice=='V')
 {
 displayscore();
 goto mainhome;
 }
     else if (choice=='Q')
 exit(1);
     else if (choice=='H')
 {
 help();
 getch();
 goto mainhome;
 }
    else if(choice=='S'){
     system("cls");

     printf("\n\n\n\t\t\tEnter your name...");
     printf("\n\t\t\t(only one word)\n\n\t\t\t");
     gets(playername);

     home:
     system("cls");
     initialtime=time(NULL);
     countq=countr=0;
     i=1;
     start:
     srand ( time(NULL) );
     r=rand()%23+1;
     nq[i]=r;
     for (w=0;w<i;w++)
 if (nq[w]==r) goto start;

     switch(r)
  {
  case 1:
  printf("\n\nWhat is the maximum no. of asymptotes of the curve x^4+2x+6=0?");
  printf("\n\nA.4\tB.3\n\nC.none\tD.infinite\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.4");break;}

  case 2:
  printf("\n\n\nHow many points are possible in a compound pendulum about which");
  printf("time period is same?");
  printf("\n\nA.4\tB.2\n\nC.none\tD.infinite\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         printf("\n\nWrong!!! The correct answer is A.4");
  break;

  case 3:
  printf("\n\n\nWho was the first US President?");
  printf("\n\nA.Richard Nikson\tB.Abraham Linkon\n\nC.John F. Kennedy\tD.George Washington\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.George Washington");break;}


  case 4:
  printf("\n\n\nWho was awarded the 'Man of the Tournament' of ICC WORLD CUP 2007?");
  printf("\n\nA.Glen Magrath\tB.Mahela Jawardan\n\nC.Mathew Hayden\tD.Sachin Tendulkar\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Glen Magrath");break;}


  case 5:
  printf("\n\n\nWhich country won the Fifa World Cup 1998?");
  printf("\n\nA.France\tB.Brazil\n\nC.Italy\tD.England\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.France");break;}

  case 6:
  printf("\n\n\nWhich syllabe is stressed in the word 'democracy'?");
  printf("\n\nA.1st\tB.2nd\n\nC.3rd\tD.4th\n\n");
  countq++;
  if (toupper(getch())=='B' )
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is B.2nd");break;}


  case 7:
  printf("\n\n\nWhich country was the winner of Cricket World Cup 1987?");
  printf("\n\nA.West Indies\tB.India\n\nC.Australia\tD.England\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Australia");break;}


  case 8:
  printf("\n\n\nWhat is the height of Mount everest in feet?");
  printf("\n\nA.8648\tB.6648\n\nC.8884\tD.8848\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.8848");break;}


  case 9:
  printf("\n\n\nWhat is the capital of Denmark?");
  printf("\n\nA.Copenhagen\tB.Helsinki\n\nC.Rome\t\tD.Madrid\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Copenhagen");break;}


  case 10:
  printf("\n\n\nWhich syllabe is stressed in the word 'instanteneous'?");
  printf("\n\nA.1st\tB.2nd\n\nC.3rd\tD.4th\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.3rd");break;}


  case 11:
  printf("\n\n\nWho was the only player to score 6 successive sixes in an over?");
  printf("\n\nA.Adam Gilchrist\tB.M.S.Dhoni\n\nC.Herschel Gibbs\tD.Sanath Jayasurya\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Herschel Gibbs");break;}

  case 12:
  printf("\n\n\nWho was the only player to take 4 successive wickets?");
  printf("\n\nA.Malinga Bandara\tB.Lasith Malinga\n\nC.Bret Lee\tD.Murali Daran\n\n");
  countq++;
  if (toupper(getch())=='B')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is B.Lasith Malinga");break;}

  case 13:
  printf("\n\n\nWhich country is hosting the Fifa World Cup 2010?");
  printf("\n\nA.South Africa\tB.Italy\n\nC.Argentina\tD.Spain\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.South Africa");break;}

  case 14:
  printf("\n\n\nWho is the author of 'Pulpasa Cafe'?");
  printf("\n\nA.Narayan Wagle\tB.Lal Gopal Subedi\n\nC.B.P. Koirala\tD.Khagendra Sangraula\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Narayan Wagle");break;}

  case 15:
  printf("\n\n\nWhich country is Maria Sarapova from?");
  printf("\n\nA.Russia\tB.Switzerland\n\nC.Argentina\tD.Spain\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Russia");break;}

  case 16:
  printf("\n\n\nWho was awarded the youngest player award in Fifa World Cup 2006?");
  printf("\n\nA.Wayne Rooney\tB.Lucas Podolski\n\nC.Lionel Messi\tD.Christiano Ronaldo\n\n");
  countq++;
  if (toupper(getch())=='B')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is B.Lucas Podolski");break;}


  case 17:
  printf("\n\n\nWhat is the smallest district of Nepal?");
  printf("\n\nA.Lalitpur\tB.Karnali\n\nC.Bhaktapur\tD.Gulmi\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Bhaktapur");break;}

  case 18:
  printf("\n\n\nWhat is the headquarter of Western Development Region?");
  printf("\n\nA.Dhankuta\tB.Kathmandu\n\nC.Dhangadhi\tD.Pokhara\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.Pokhara");break;}

  case 19:
  printf("\n\n\nWhich place is called 'The Cherrapunji of Nepal'?");
  printf("\n\nA.Dharan\tB.Kathmandu\n\nC.Pokhara\tD.Butwal\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Pokhara");break;}

  case 20:
  printf("\n\n\nWhich city is known at 'The City of Seven Hills'?");
  printf("\n\nA.Rome\tB.Vactican City\n\nC.Madrid\tD.Berlin\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Rome");break;}

  case 21:
  printf("\n\n\nWho was the F1 racing champion of 2006?");
  printf("\n\nA.Louis Hamilton\tB.Felipe Massa\n\nC.Fernando Alonso\tD.Michael Schumaker\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Fernanda Alonso");break;}

  case 22:
  printf("\n\n\nWho won the Women Australian Open 2007?");
  printf("\n\nA.Martina Hingis\tB.Maria Sarapova\n\nC.Kim Clijster\tD.Serena Williams\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.Serena Williams");break;}

  case 23:
  printf("\n\n\nName the country where there no mosquito is found?");
  printf("\n\nA.Germany\tB.Spain\n\nC.Japan\tD.France\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.France");break;}



  }
 i++;
 if (i<=5) goto start;
 finaltime=time(NULL);
 score=(float)countr/countq*100-difftime(finaltime,initialtime)/3;
 if (score<0) score=0;
 printf("\n\n\nYour Score: %.2f",score);
 if (score==100) printf("\n\nEXCELLENT!!! KEEP IT UP");
 else if (score>=80 && score<100) printf("\n\nVERY GOOD!!");
 else if (score>=60 &&score<80) printf("\n\nGOOD! BUT YOU NEED TO KNOW MORE.");
 else if (score>=40 && score<60) printf("\n\nSATISFACTORY RESULT, BUT THIS MUCH IS MUCH SUFFICIENT.");
 else printf("\n\nYOU ARE VERY POOR IN G.K.,WORK HARD");
 puts("\n\nNEXT PLAY?(Y/N)");
 if (toupper(getch())=='Y')
  goto home;
 else
  {
  writescore(score,playername);
  goto mainhome;
  }
 }
     else
 {
 printf("\n\n\t\t  Enter the right key\n\n\t\t  ");
 Sleep(700);
 goto mainhome;
 }
 getch();
}



FIGHTING GAME!!!!!!!!!!!!!!!!!!!!!!!!


#include<iostream>
#include<windows.h>
#include<conio.h>
#include<cmath>
#include<ctime>
#include<cstdlib>

using namespace std;
void loading();
void help1();
void gotoxy(int x,int y);
void drawchar(int);
void clschar(int);
void showhpmp();
int longp0p1();
void config();
void functionkey(char);
void endgame(int);
void startgame();
void help();
void help1();
void help2();
void help3();
void effect(int,int);
void clseffect(int);

char name[2][8];
int ti[2][3]= {{0,0,0},{0,0,0}};
int p[2];
int d[2]= {15,65};
int hp[2]= {100,100},mp[2]= {100,100};
int pr=0;
int ui=0;
int r=0;
bool firstload=true;
time_t start,end;


int main()
{
    system("title THE FIGHT");
    int dif;
    if(ui==0)
    {
        loading();
        time (&start);
        ui++;
    }
    int lastdif;
    startgame();
    while(1)
    {
        Sleep(5);
        if(hp[0]<=0||hp[1]<=0)
        {
            gotoxy(30,10);
            if(hp[0]<=0) cout<<"P1 is won";
            else cout<<"P0 is won";
            Sleep(4000);
            gotoxy(30,10);
            cout<<"Restarting...";
            Sleep(2000);
            config();
        }
        time (&end);
        dif = difftime(end,start);
        if(dif%10==0&&lastdif!=dif)
        {
            mp[0]+=10;
            mp[1]+=10;
            hp[0]+=5;
            hp[1]+=5;
            if(hp[pr]>100) hp[pr]=100;
            if(hp[!pr]>100) hp[!pr]=100;
            if(mp[pr]>100) mp[pr]=100;
            if(mp[!pr]>100) mp[!pr]=100;
            lastdif=dif;
            showhpmp();
        }
        gotoxy(0,6);
        cout<<"Distance "<<longp0p1()<<" ";
        if(false&&dif>0){
            gotoxy(0,7);
            cout<<"FPS "<<(r++)/dif<<" ";
        }

        gotoxy(25,0);
        cout << "Cooldown\t"<<"P0\t"<<"P1";


        /*
        gotoxy(25,1);
        tt1 = 0-(time(&end)-ti[0][0]);
        tt2 = 0-(time(&end)-ti[1][0]);
        cout << "Attack\t\t"<<(tt1<0?0:tt1)<<"\t"<<(tt2<0?0:tt2);
        */

        int tt1,tt2;
        gotoxy(25,2);
        tt1 = 5-(time(&end)-ti[0][1])+1;
        tt2 = 5-(time(&end)-ti[1][1])+1;
        cout << "Skill 1\t"<<(tt1<0?0:tt1)<<"\t"<<(tt2<0?0:tt2);
        tt1 = 10-(time(&end)-ti[0][2])+1;
        tt2 = 10-(time(&end)-ti[1][2])+1;
        gotoxy(25,3);
        cout << "Skill 2\t"<<(tt1<0?0:tt1)<<"\t"<<(tt2<0?0:tt2);

        if(kbhit())
        {
            //drawchar(!pr);
            clschar(pr);
            clschar(!pr);
            clseffect(pr);
            char c=getch();
            if(c=='q'||c=='e'||c=='z'||c=='x'||c=='c')
            {
                pr=0;
                if(c=='q') d[pr]--;
                else if(c=='e') d[pr]++;
                else if(c=='z'&&longp0p1()<2&&(time(&end)-ti[pr][0])>0&&mp[pr]>=2 )
                {
                    gotoxy(0,7);
                    for(int i=0; i<80; i++) cout<<" ";
                    gotoxy(0,7);
                    cout<<"P0 Attacked";
                    ti[pr][0]=time(&end);
                    if(d[pr]>=d[!pr]) d[!pr]-=1;
                    else d[!pr]+=1;
                    hp[!pr]-=2;
                    mp[pr]-=2;
                    mp[!pr]-=1;
                    if(mp[pr]<0) mp[pr]=0;
                    else if(mp[!pr]<0) mp[pr]=0;
                    showhpmp();
                }
                else if(c=='x'&&longp0p1()<3&&(time(&end)-ti[pr][1])>5&&mp[pr]>=15 )
                {
                    effect(pr,1);
                    gotoxy(0,7);
                    for(int i=0; i<80; i++) cout<<" ";
                    gotoxy(0,7);
                    cout<<"P0 Used Skill 1";
                    ti[pr][1]=time(&end);
                    if(d[pr]>=d[!pr]) d[!pr]-=5;
                    else d[!pr]+=5;
                    hp[!pr]-=15;
                    mp[pr]-=15;
                    mp[!pr]-=8;
                    if(mp[pr]<0) mp[pr]=0;
                    else if(mp[!pr]<0) mp[pr]=0;
                    showhpmp();
                    effect(pr,1);
                }
                else if(c=='c'&&longp0p1()<5&&(time(&end)-ti[pr][2])>10&&mp[pr]>=20 )
                {
                    effect(pr,2);
                    gotoxy(0,7);
                    for(int i=0; i<80; i++) cout<<" ";
                    gotoxy(0,7);
                    cout<<"P0 Used Skill 2";
                    ti[pr][2]=time(&end);
                    if(d[pr]>=d[!pr]) d[!pr]-=10;
                    else d[!pr]+=10;
                    hp[!pr]-=30;
                    mp[pr]-=20;
                    mp[!pr]-=10;
                    if(mp[pr]<0) mp[pr]=0;
                    else if(mp[!pr]<0) mp[pr]=0;
                    showhpmp();
                    effect(pr,2);
                }
            }
            else if(c=='p'||c==']'||c=='/'||c=='.'||c==',')
            {
                pr=1;
                if(c=='p') d[pr]--;
                else if(c==']') d[pr]++;
                else if(c=='/'&&longp0p1()<2&&(time(&end)-ti[pr][0])>0&&mp[pr]>=2 )
                {
                    gotoxy(0,7);
                    for(int i=0; i<80; i++) cout<<" ";
                    gotoxy(0,7);
                    cout<<"P1 Attacked";
                    ti[pr][0]=time(&end);
                    if(d[pr]>=d[!pr]) d[!pr]-=1;
                    else d[!pr]+=1;
                    hp[!pr]-=2;
                    mp[pr]-=2;
                    mp[!pr]-=1;
                    if(mp[pr]<0) mp[pr]=0;
                    else if(mp[!pr]<0) mp[pr]=0;
                    showhpmp();
                }
                else if(c=='.'&&longp0p1()<3&&(time(&end)-ti[pr][1])>5&&mp[pr]>=15 )
                {
                    effect(pr,1);
                    gotoxy(0,7);
                    for(int i=0; i<80; i++) cout<<" ";
                    gotoxy(0,7);
                    cout<<"P1 Used Skill 1";
                    ti[pr][1]=time(&end);
                    if(d[pr]>=d[!pr]) d[!pr]-=5;
                    else d[!pr]+=5;
                    hp[!pr]-=15;
                    mp[pr]-=15;
                    mp[!pr]-=8;
                    if(mp[pr]<0) mp[pr]=0;
                    else if(mp[!pr]<0) mp[pr]=0;
                    showhpmp();
                    effect(pr,1);
                }
                else if(c==','&&longp0p1()<5&&(time(&end)-ti[pr][2])>10&&mp[pr]>=20 )
                {
                    effect(pr,2);
                    gotoxy(0,7);
                    for(int i=0; i<80; i++) cout<<" ";
                    gotoxy(0,7);
                    cout<<"P1 Used Skill 2";
                    ti[pr][2]=time(&end);
                    if(d[pr]>=d[!pr]) d[!pr]-=10;
                    else d[!pr]+=10;
                    hp[!pr]-=30;
                    mp[pr]-=20;
                    mp[!pr]-=10;
                    if(mp[pr]<0) mp[pr]=0;
                    else if(mp[!pr]<0) mp[pr]=0;
                    showhpmp();
                    effect(pr,2);
                }
            }
            else if(c==0) functionkey(getch());
            else if(c==27) endgame(difftime (end,start));
            if(d[pr]<0) d[pr]=0;
            else if(d[pr]>79) d[pr]=79;
            else if(d[!pr]<0) d[!pr]=0;
            else if(d[!pr]>79) d[!pr]=79;
            drawchar(pr);
            drawchar(!pr);
        }
    }
    return 0;
}
void gotoxy(int x,int y)
{
    COORD coord;
    coord.X=x;
    coord.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
void drawchar(int pr)
{
    gotoxy(d[pr],18);
    cout<<char(197);
    gotoxy(d[pr],18-1);
    cout<<(pr==0?char(1):char(2));
    if(d[pr]==d[!pr])
    {
        gotoxy(d[pr],18-2);
        cout<<"2";
    }
    else
    {
        gotoxy(d[pr],18-2);
        cout<<" ";
    }
}
void clschar(int pr)
{
    gotoxy(d[pr],18);
    cout<<" ";
    gotoxy(d[pr],18-1);
    cout<<" ";
}
void help1()
{
    gotoxy(0,21);
    cout<<"Help\n";
    gotoxy(0,22);
    cout<<"Attack an enemy and use skills ,skill uses MP and have distance ";
    cout<<"to attack. Before use skills again it has a delays";
    system("pause>nul");
    gotoxy(0,22);
    for(int i=0; i<160; i++) cout<<" ";
    gotoxy(0,22);
    cout<<"When attack, enemy will be turned back";
    cout<<". MP increase 1 per/sec. and HP 0.5 per/sec. When get hit from enemy MP will decrease half of skill use";
    system("pause>nul");
    gotoxy(0,22);
    for(int i=0; i<160; i++) cout<<" ";
    gotoxy(0,22);
    cout<<"Details for normal attack\nCooldown Time 1 secound, Distance 1, Use 2 MP, Decrease 2 HP";
    system("pause>nul");
    gotoxy(0,22);
    for(int i=0; i<160; i++) cout<<" ";
    gotoxy(0,22);
    cout<<"Details for Skill 1\nCooldown Time 5 Secounds, Distance 2, Use 15 MP, Decrease 15 HP";
    system("pause>nul");
    gotoxy(0,22);
    for(int i=0; i<160; i++) cout<<" ";
    gotoxy(0,22);
    cout<<"Details for Skill 2\nCooldown Time 10 Secounds, Distance 4, Use 20 MP, Decrease 30 HP";
    system("pause>nul");
    gotoxy(0,21);
    for(int i=0; i<240; i++) cout<<" ";
}
void help2()
{
    gotoxy(0,21);
    cout<<"Control\n";
    cout<<"P0 q=Left e=Rigth z=Attack x=Skill1 c=Skill2\n";
    cout<<"P1 p=Left ]=Rigth ,=Attack .=Skill1 /=Skill2\n";
    getch();
    gotoxy(0,21);
    for(int i=0; i<240; i++) cout<<" ";
}
void help3()
{
    gotoxy(0,21);
    cout<<"Creator\n";
    cout<<"Watsan > This game has created by me, Twitter @metins884\n\t\t\t\t\t\t\t\tOct 10 2012";
    getch();
    gotoxy(0,21);
    for(int i=0; i<240; i++) cout<<" ";
}
void showhpmp()
{
    int t;
    if(firstload){
        t=80;
        firstload = false;
    }else{
        t=0;
    }
    gotoxy(0,0);
    cout<<"P0 "<<char(1);Sleep(t);
    gotoxy(0,1);
    cout<<"HP "<<hp[0]<<"   ";Sleep(t);
    gotoxy(0,2);
    cout<<"MP "<<mp[0]<<"   ";Sleep(t);
    gotoxy(70,0);
    cout<<"P1 "<<char(2);Sleep(t);
    gotoxy(70,1);
    cout<<"HP "<<hp[1]<<"   ";Sleep(t);
    gotoxy(70,2);
    cout<<"MP "<<mp[1]<<"   ";Sleep(t);
}
int longp0p1()
{
    int x=d[1]-d[0];
    if(x>=0) return x;
    else return x*-1;
}
void config()
{
    for(int i=0; i<2; i++)
    {
        for(int j=0; j<3; j++)
            ti[i][j]=0;
    }
//p[2];
    d[0]=15;
    d[1]=65;
    hp[0]=hp[1]=100;
    mp[0]=mp[1]=100;
    pr=0;
    system("cls");
    main();
}
void functionkey(char c)
{
    drawchar(pr);
    drawchar(!pr);
    if(c==59)
    {
        help1();
    }
    else if(c==60) help2();
    else if(c==61) help3();
}
void startgame()
{
    firstload = true;
    int i;
    gotoxy(0,19);
    for(i=0; i<160; i++)
        cout<<char(177);
    showhpmp();
    help();
    drawchar(pr);
    drawchar(!pr);
}
void endgame(int t)
{
    gotoxy(30,10);
    cout<<"Quite game? Enter/ESC";
    char c=getch();
    if(c==13)
    {
        system("cls");
        gotoxy(27,10);
        cout<<"Total time runed "<<t<<" Secound" << (t>1?"s":"");
        Sleep(4000);
        exit(0);
    }
    else if(c==27)
        gotoxy(30,10);
    cout<<"                        ";

}
void help()
{
    gotoxy(0,24);
    cout<<"F1=Help, F2=Control, F3=Creator, ESC=Exit";
}
void effect(int pr,int c)
{
    char e;
    if(c==1) e='*';
    else if(c==2) e='O';
    gotoxy(d[pr]-1,18);
    cout<<e;
    gotoxy(d[pr]+1,18);
    cout<<e;
    gotoxy(d[pr]-1,18-1);
    cout<<e;
    gotoxy(d[pr]+1,18-1);
    cout<<e;
}
void clseffect(int pr)
{
    gotoxy(d[pr]-1,18);
    cout<<" ";
    gotoxy(d[pr]+1,18);
    cout<<" ";
    gotoxy(d[pr]-1,18-1);
    cout<<" ";
    gotoxy(d[pr]+1,18-1);
    cout<<" ";
}
void loading()
{
    srand(time(NULL));
    cout<<"The Fight";
    gotoxy(0,20);
    cout<<"By Watsan by C & Cpp";
    for(int i=0; i<=100; i++)
    {
        gotoxy(30,10);
        cout<<"Loading ";
        cout<<i<<" %";
        Sleep(5);
    }
    Sleep(400);
    gotoxy(30,10);
    cout<<"                 ";
    gotoxy(30,10);
    cout<<"Starting...";
    Sleep(2000);
    system("cls");
}


TIE-TAK GAME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/*MADE BY:ADNAN SHAHID*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include <windows.h>



int board[10] = {2,2,2,2,2,2,2,2,2,2};
int turn = 1,flag = 0;
int player,comp;

void menu();
void go(int n);
void start_game();
void check_draw();
void draw_board();
void player_first();
void put_X_O(char ch,int pos);
 COORD coord={0,0}; // this is global variable
                                    //center of axis is set to the top left cornor of the screen
void gotoxy(int x,int y)
{
    coord.X=x;
    coord.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}



main()
{
system("cls");
menu();
getch();

}

void menu()
{
int choice;
system("cls");
printf("\n\t\t*************************************************");
printf("\n\t\t**->    MADE BY:ADNAN SHAHID LOVELY CODING   <-**");
printf("\n\t\t*************************************************");
sleep(3000);
printf("\n--------MENU--------");
printf("\n1 : Play with X");
printf("\n2 : Play with O");
printf("\n3 : Exit");
printf("\nEnter your choice:>");
scanf("%d",&choice);
turn = 1;
switch (choice)
{
case 1:
player = 1;
comp = 0;
player_first();
break;
case 2:
player = 0;
comp = 1;
start_game();
break;
case 3:
exit(1);
default:
menu();
}
}

int make2()
{
if(board[5] == 2)
return 5;
if(board[2] == 2)
return 2;
if(board[4] == 2)
return 4;
if(board[6] == 2)
return 6;
if(board[8] == 2)
return 8;
return 0;
}

int make4()
{
if(board[1] == 2)
return 1;
if(board[3] == 2)
return 3;
if(board[7] == 2)
return 7;
if(board[9] == 2)
return 9;
return 0;
}

int posswin(int p)
{
// p==1 then X   p==0  then  O
int i;
int check_val,pos;

if(p == 1)
check_val = 18;
else
check_val = 50;

i = 1;
while(i<=9)//row check
{
if(board[i] * board[i+1] * board[i+2] == check_val)
{
if(board[i] == 2)
return i;
if(board[i+1] == 2)
return i+1;
if(board[i+2] == 2)
return i+2;
}
i+=3;
}

i = 1;
while(i<=3)//column check
{
if(board[i] * board[i+3] * board[i+6] == check_val)
{
if(board[i] == 2)
return i;
if(board[i+3] == 2)
return i+3;
if(board[i+6] == 2)
return i+6;
}
i++;
}

if(board[1] * board[5] * board[9] == check_val)
{
if(board[1] == 2)
return 1;
if(board[5] == 2)
return 5;
if(board[9] == 2)
return 9;
}

if(board[3] * board[5] * board[7] == check_val)
{
if(board[3] == 2)
return 3;
if(board[5] == 2)
return 5;
if(board[7] == 2)
return 7;
}
return 0;
}

void go(int n)
{
if(turn % 2)
board[n] = 3;
else
board[n] = 5;
turn++;
}

void player_first()
{
int pos;

check_draw();
draw_board();
gotoxy(30,18);
printf("Your Turn :> ");
scanf("%d",&pos);

if(board[pos] != 2)
player_first();

if(pos == posswin(player))
{
go(pos);
draw_board();
gotoxy(30,20);
//textcolor(128+RED);
printf("Player Wins");
getch();
exit(0);
}

go(pos);
draw_board();
start_game();
}

void start_game()
{
// p==1 then X   p==0  then  O
if(posswin(comp))
{
go(posswin(comp));
flag = 1;
}
else
if(posswin(player))
go(posswin(player));
else
if(make2())
go(make2());
else
go(make4());
draw_board();

if(flag)
{
gotoxy(30,20);
//textcolor(128+RED);
printf("Computer wins");
getch();
}
else
player_first();
}

void check_draw()
{
if(turn > 9)
{
gotoxy(30,20);
//textcolor(128+RED);
printf("Game Draw");
getch();
exit(0);
}
}

void draw_board()
{
int j;

for(j=9;j<17;j++)
{
gotoxy(35,j);
printf("|       |");
}
gotoxy(28,11);
printf("-----------------------");
gotoxy(28,14);
printf("-----------------------");

for(j=1;j<10;j++)
{
if(board[j] == 3)
put_X_O('X',j);
else
if(board[j] == 5)
put_X_O('O',j);
}
}

void put_X_O(char ch,int pos)
{
int m;
int x = 31, y = 10;

m = pos;

if(m > 3)
{
while(m > 3)
{
y += 3;
m -= 3;
}
}
if(pos % 3 == 0)
x += 16;
else
{
pos %= 3;
pos--;
while(pos)
{
x+=8;
pos--;
}
}
gotoxy(x,y);
printf("%c",ch);
}










No comments:

Post a Comment