Showing posts with label HTML/CSS. Show all posts
Showing posts with label HTML/CSS. Show all posts

Tuesday, 13 July 2021

Snake game using C++

 Snake game using C++ Code.

#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("o");

   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("\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--;

}


This Image show your game Interface.


Also Click this link you play game.


Sunday, 11 July 2021

Admission Form Create by Html and Css

Admission Form Create By Html And Css 


HTML CODE

<html>

<head> <link rel="stylesheet" href="Mid paper project.css"> 

</head>

<body>

    

<div style="display: flex;justify-content: center;">

    <span class="logo" > <img src="logo.png" width="200px" height="200px" alt="University logo"></span>

    <div class="add">

    <p>Riphah International<br>

        University, FSD

    </p>

</div>

    <div class="img">

        <input type="image" src="img_submit.jpg" alt="photograph" width="200px" height="200px">

    </div>

   

</div>

<div class="emp">EMPLOYEES APPLICATION</div>


<div class="set">

    <div class="j">

        Form submission date :<input type="date">

        </div>

<!--EMPLOYEES profile-->

    <div class="di">

       <p>Employees Profile</p>

    </div>

   

<div class="ep">

Name:<input type="text" size="30">

Gender:<input type="radio">Male

<input type="radio">Female<br>

Father/Guardian Name:<input type="text"size="30">

CNIC:<input type="number"size="30"><br>

Address:<input type="text" size="30">

Permanent Address:<input type="text" size="30"><br>

Phone no <input type="number" size="30">

Mobile No.<input type="number" size="30"><br>

D.O.B.<input type="text" size="30">

Nationality:<input type="text" size="30">

Blood Group<input type="text" size="30"><br>

Father/Guardian CNIC:<input type="number" size="30"> 

Religion:<input type="text" size="30">

</div>


                   <!--Academic Details-->

<div class="di">

    <p>Academic Details(optional)</p>


</div>

<table border="1" cellspacing="0" class="t">

    <tr>

        <th style="background: #666363;">Exam passed</th> 

        <th style="background: #666363;">Institute</th>

        <th style="background: #666363;">Passing year</th>

        <th style="background: #666363;">Total Marks</th> 

        <th style="background: #666363;">Obtained Marks</th>

        <th style="background: #666363;">Marks in %</th> 

        <th style="background: #666363;">Board</th>  

</tr>

<tr>

   <td style="background: rgb(176,226,243);">Matric</td>

   <td></td>

   <td></td>

   <td></td>

   <td></td>

   <td></td>

   <td></td>

   

</tr>

<tr>

    <td style="background: rgb(176,226,243);">F.Sc/F.A</td>

    <td></td>

   <td></td>

   <td></td>

   <td></td>

   <td></td>

   <td></td>

   

</tr>

<tr>

    <td style="background: rgb(176,226,243);">B.A/BSC</td>

    <td></td>

   <td></td>

   <td></td>

   <td></td>

   <td></td>

   <td></td>

   

</tr>

<tr>

    <td style="background: rgb(176,226,243);">Other</td>

    <td></td>

   <td></td>

   <td></td>

   <td></td>

   <td></td>

   <td></td>

   

</tr>

</table>


 <div style="margin-top: 1%;">

            <div style="float: left;"><span class="Name "><b>Witness 1</b>:</span><br/><br/>

            <span class="Name ">Name:<input type="text"size="40">,<br></br>

            <span class="Name ">CNIC:<input type="number"size="40"><br></br>

            <span class="Name ">Sign:<input type="text"size="40">

            </div>     

<div style="float: right; margin-right: 10%;" >

                <span class="Name "><b>Witness 2</b></span><br/><br/>

                <span class="Name ">Name:<input type="text"size="40">,<br></br>

                <span class="Name ">CNIC:<input type="number"size="40"><br></br>

                <span class="Name ">Sign:<input type="text"size="40">

            </div>

        </div><br/><br/><br/><br/><br/><br/><br/><br/>

        <div>

            <h2>Required Documents:</h2>

            <ol>

                <div style="float: left;">

                <li>Passport Size Picture <b>* 1</b></li>

                <li>Copy of CNIC</li>

                <li>Copy of Father/ Guardian CNIC </li>

                <li>Academic Documents</li>

            </div>

            <div style="float: right;margin-right: 40%;">

                <li>Medical Certificate</li>

                <li>CV</li>

                <li>Certificates</li>

            </div>

 </ol>

<br/><br/><br/><br/><br/><br/><br/>

<hr class="h">

<div class="fo">

    <p>FOR OFFICE USE</p>

</div>

Date:<input type="date">

<div class="d">

<h4>Manager Signature:<hr style="width: 150px; margin-right: 1000px; margin-top:50px"></h4>

</div>

<div class="a">

    <h4> Director Name:</h4>

    <h4> sign:</h4>

</div>


<div class="rf">

    <h1> Contact us: Riphah International University, Faisalabad Campus<br>

        Satayana Road, near Fish Farm,<br>

        Faisalabad, Pakistan</h1>

</div>

</body>

</html>


CSS CODE

.logo

                {


    display: inline;

        }


.add

{

            border: 1px solid black;

            text-align: center;

            width: 500px;           

            color: white;

            background-color: #990012;

            font-weight: 900;

            font-family:  Roboto,'Segoe UI', Tahoma, sans-serif;

            font-size: 40px ;

    }

.img

{       

            border: 1px solid black;

            

        }

  

.emp

         {

    writing-mode: vertical-lr;

    font-size: 40px;

    display: flex;

    background-color:#B6B6B4;

    color: red;

    padding:15px;

    word-spacing: 2px;

    letter-spacing: 1.2px;

    transform: rotate(180deg);

    font-weight: 900;

    box-shadow: 0px 0px 1px 1px black;   

    height: 800px;   

    padding-top: 150px;

    margin-bottom: 50px;


    }

.set     

               {

    margin-left: 100px;

    margin-top: -1000px;

         }

.j

               {

    font-size: 30px;

  display: inline;

  margin-top: 20px;

     }


.di         {

            text-align: center;

            color: white;

            background-color:  #990012;

            width: 1100px;

            height: 30px;

            font-size: 20px;

            margin-top: 10px;

            

    }

.t

{

    width: 1100px;

    margin-top: 15px;

    }

.ep        

                 {

    margin-top: 20px;

    }

        .h

{

    border-top:  1px dashed black;

    width: 1100px;

    }

.fo    

                 {

    border: 2px solid black;

     width: 180px;

     text-align: center;

     font-weight: 800;

     margin-left: 550px;

     box-shadow: 5px 10px rgb(59, 56, 56) ;

    }

.a

                {

    margin-left: 900px ;

    border: 1px solid black;

    width :300px;

    margin-top: -100px;

    margin-bottom: 5px;

    padding-left: 10px;

    }


.rf

                {

    background-color: #990012;

    color:white;

    border:1px solid  #990012;

    text-align: center;

     }

Friday, 2 July 2021

Google Front page with HTML/CSS

GOOGLE FRONT PAGE 

HTML CODE.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width,intial-scale=1.0">

<meta http-equiv="X-UA-Compatiable"content="ie=edge">

<link rel="stylesheet"href="style.css">

<title>Google</title>

</head>

<body>

<div id="navbar">

<a href="#" id="about">About</a>

<a href="#" id="store">Store</a>

<a href="#" id="gmail">Gmail</a>

<a href="#" id="image">Image</a>

<a href="#" id="menu"><img src="menu.jpg" height="30px" width="30px" ></a>

<a href="#" id="sign-in">Sign in</a>

</div>


<div id="main">

<a href="#" id="logo"><img src="h.png"></a>

<input type="text" id ="search">

<div id="flexbox">

<button id="google-search-btn">Google search</button> <button id="random-search-btn">I'm Feeling Lucky</button>

</div>

<p id="google-text">Google Offered in:<a href="#" id="pakistan">Pakistan</a></p>

</div>


<div id="footer">

<a href="#" id="advertising">Advertising</a>

<a href="#" id="business">Business</a>

<a href="#" id="hsw">How search works</a>

<a href="#" id="Privacy">Privacy</a>

<a href="#" id="terms">Terms</a>

<a href="#" id="settings">settings</a>

</div>

</body>

</html>


CSS CODE


html

{

height: 100%;

width:100%;


}

#navbar

{

display: grid;


grid-template-columns: 50px 50px 1fr 50px 50px 50px 60px;

grid-template-rows: 50px;

grid-template-areas:

"about store.gmail image menu sign-in";

margin:0 20px 0 10px;

}


a,p

{

text-decoration:none;

color:rgba(0,0,0,0,87);

font-family:Arial,Helyetica, sans-serif;

font-size:13px;

}

a:hover{

text-decoration:underline;

}


#about

{

grid-area:about;

justify-self:center;

align-self:center;

}

#store

{

grid-area:store;

justify-self:center;

align-self:center;

}

#gmail

{

grid-area:gmail;

justify-self:center;

align-self:center;

}

#image

{

grid-area:image;

justify-self:center;

align-self:center;

}


#menu

{

grid-area:menu;

justify-self:center;

align-self:center;

margin-right:10px;

}

#sign-in

{

grid-area:sign-in;

justify-self:center;

align-self:center;

background-color:#4683ea;

height:30px;

width:65px;

color:white;

font-weight:bold;

text-align:center;

border:1px solid #4285f4;

line-height:30px;

}

#main

{

min-height: 100%;

display:grid;

grid-template-columns:1fr 1fr 1fr;

grid-template-rows:250px 70px 70px 250px;

grid-template-areas:

".logo."

".search."

".flexbox."

".google-text.";

}

#logo

{

grid-area:logo;

justify-self:center;

align-self:end;

}

#search

{

grid-area:search;

height:30px;

width:80%;

justify-self:center;

align-self:center;

border: 1px solid rgba(0,0,0,0.151);

border-radius:30px;

}

#search:focus

{

box-shadow:1px 1px 5px grey;

}

#search:hover

{

box-shadow:1px 1px 5px grey;

}

#flexbox{

display:flexbox;

grid-area:flexbox;

justify-self:center;

align-self:center;

}

#google-search-btn

{

border:none;

font-size:15px;

color:#5F6368;

border-radius:3px;

margin-right:10px;

padding:7px 15px 7px 15px;


}

#random-search-btn{

border:none;

font-size:15px;

color:#5F6368;

padding:7px 15px 7px 15px;

border-radius:3px;

margin-right:10px;

}

#google-search-btn:hover

{

border:1px solid rgba(0,0,0,0.226);

;

}

#random-search-btn:hover

{ border:1px solid rgba(0,0,0,0.226);

}


#google-text

{

grid-area:google-text;

justify-self:center;

}

#pakistan

{

color:blue;

}

#footer

{


position:relative;

bottom:0;

display:grid;

grid-template-columns:100px 100px 150px 1fr 70px 70px 70px;

grid-template-rows:50px;

grid-template-areas:

    "advertising business hsw . Privacy terms settings";

}

#advertising

{

grid-area:advertising;

justify-self:center;

align-self:center;

}

#business

{

grid-area:business;

justify-self:center;

align-self:center;

}

#hsw

{

grid-area:hsw;

justify-self:center;

align-self:center;

}

#Privacy

{

grid-area:Privacy;

justify-self:center;

align-self:center;

}

#terms

{

grid-area:terms;

justify-self:center;

align-self:center;

}

#settings

{

grid-area:settings;

justify-self:center;

align-self:center;

}