DOWNLOAD C++ SOURCE CODE FOR PYRAMID SOLITAIRE

 

C++ SOURCE CODE FOR BEGINNERS LEVEL GAME PYRAMID SOLITAIRE: 

This is Pyramid Solitaire beginners level source code written in C++.You can download it by clicking the download button.Or you can copy paste from here.

Happy Coding!

 

#include<iostream>
#include<cstdlib>
#include<string>
#include<Windows.h>
#include<ctime>
#include<iomanip>


using namespace std;



//this function will generate random number cards
int randomnumber()
{//start of random number function

    int randomnumber= 1+rand() % 13;

    if (randomnumber==1)
        randomnumber=65;
    else if (randomnumber==11)
    randomnumber=74;
    else if (randomnumber==12)
    randomnumber=81;
    else if (randomnumber==13)
        randomnumber=75;

    return randomnumber;
}//end of random number function


int timecounter()
{//start of time function
           time_t now = time(0);
 tm *ltm = localtime(&now);
    int timmer;


 timmer= 1 + ltm->tm_min ;

    return timmer;
}//end of time function



//this function will converte characters in to their game value
int characterarray(int number)
{
        if (number==65)
        number=1;
    else if (number==74)
        number=11;
    else if (number==81)
        number=12;
    else if (number==75)
        number=13;
    return number;
}


int drawboard(char array[8][24])
{//start of drawboard function
    cout<<"DRAW PILE:"<<endl<<endl;
    cout<<"     ";

    for(int h=0;h<=11;h++)
    {//start for
        cout<<"col"<<h<<" ";
    }//end for

cout<<endl;
    for (int i=0;i<=0;i++)
{//start for
    cout<<"row"<<i;
        for (int j=0;j<=11;j++)
    {//start for

         if (array[i][j]==65 || array[i][j]==74 || array[i][j]==81 || array[i][j]==75 || array[i][j]==46)
         cout<<setw(5)<<static_cast <char> (array[i][j]);
        else
        cout<<setw(5)<<static_cast <int> (array[i][j]);

    }//end for
        cout<<endl<<endl<<endl;
}//end for



    cout<<"     ";

    for(int h=12;h<=23;h++)
    {//start for
        cout<<"col"<<h<<" ";
    }//end for

cout<<endl;
    for (int i=0;i<=0;i++)
{//start for
    cout<<"row"<<i;
        for (int j=12;j<=23;j++)
    {//start for

         if (array[i][j]==65 || array[i][j]==74 || array[i][j]==81 || array[i][j]==75 || array[i][j]==46)
         cout<<setw(6)<<static_cast <char> (array[i][j]);
        else
        cout<<setw(6)<<static_cast <int> (array[i][j]);

    }//end for
        cout<<endl<<endl<<endl;
}//end for   
    return 0;
}//end of drawboard function




int cardsboard(char array[8][24],int score,int timeremaining)
{//start of board function
int cardcounter=0;

cout<<"CARDS:"<<setw(60)<<"score="<<score<<endl<<endl;
cout<<"       ";
    for(int h=0;h<=6;h++)
    {//start for
        cout<<"colm"<<h<<" ";
    }//end for
cout<<setw(25)<<"time remaining="<<timeremaining<<"min"<<endl;
     for (int i=1;i<=7;i++)
     {
    cout<<"row"<<i;
         for (int j=0;j<=cardcounter;j++)
         {

         if (array[i][j]==65 || array[i][j]==74 || array[i][j]==81 || array[i][j]==75 || array[i][j]==46)
         cout<<setw(6)<<static_cast <char> (array[i][j]);
        else
        cout<<setw(6)<<static_cast <int> (array[i][j]);
         }




     cout<<endl<<endl<<endl;
     cardcounter++;
     }


    return 0;
}//end of board function

//this function will input row number
int rowfunction()
{//start of row function
    int row;
    cout<<endl<<"enter row number:";
    cin>>row;

    return row;
}//end of row function


//this function will input column number
int columnfunction()
{//start of column function
    int column;
    cout<<endl<<"enter column number:";
    cin>>column;

    return column;
}//end of row function


//this function will check whether all cards are finished or not
bool checkfunction(char array[8][24])
{//start of check function
    int checkcounter=0;
    int checkadder=0;
    bool checkcondition=true;

        for (int i=1;i<=7;i++)
     {
         for (int j=0;j<=checkcounter;j++)
         {
         if (array[i][j]=='.')
             checkadder++;
         }

     checkcounter++;

     }
        if (checkadder==28)
        {
            checkcondition=false;
        }

    return checkcondition;
}//end of check function


//this function will update the score
int scorecounter(int score)
{//start of score counter
    score=score+5;

    return score;
}//end of score counter



int pyramidsolitaire()
{//start of  function
    srand(time(0));

    char array[8][24];
    int frequency[14];
    int counter=0;
    int number;
    int arraynumber;
    bool frequencycounter=true;
    char input;


//this  will initialize the frequency of cards
    for (int i=1;i<=13;i++)
    {//stat for
        frequency[i]=0;
    }//end for


//start of assigning random number to draw pile
for (int i=0;i<=0;i++)
{//start for
        for (int j=0;j<=23;j++)
    {//start for

            arraynumber=randomnumber();
            number=characterarray(arraynumber);
            frequency[number]++;
            if (frequency[number]>4)
            {
                if (j>0)
                {
                    j--;
               continue;
                }
            }
        array[i][j]=arraynumber;

    }//end for
}//end for

 //end of assigning random number to draw pile


//start of assigning random number to cards

    for (int i=1;i<=7;i++)
     {
         for (int j=0;j<=counter;j++)
         {


                     arraynumber=randomnumber();            
                         number=characterarray(arraynumber);
                         frequency[number]++;
                         if (frequency[number]>4)
                         {
                             if (j>0)
                             {
                                 j--;
                             continue;
                             }
                         }
             array[i][j]=arraynumber;

       
        }//end for
     counter++;

     }
    //end of assigning random number to cards

bool condition=true;
int rowcard1;
int columncard1;
int rowcard2;
int columncard2;
int numb1;
int numb2;
int sum;
int score=0;
int count;
int timediff;
int timeremaining;
int time=timecounter();
bool excel=false;

while(condition==true)
{//start of while
    if (condition==true)
    {//start if
     system("cls");//this will clear the screen

     count=timecounter();
     timediff=count-time;
     if (timediff>=5)
     {//start if
     system("cls");
     cout<<"\n\n\n\n\n\n\n"<<setw(25)<<"score="<<score;
     Sleep(1000);
     system("cls");
     condition=false;
     }//end if
     timeremaining=5-timediff;

    drawboard(array);//this function will print draw pile
    cardsboard(array,score,timeremaining);//this function will print cards



    cout<<"CARD1:"<<endl;
    rowcard1=rowfunction();
    columncard1=columnfunction();
    numb1=characterarray(array[rowcard1][columncard1]);
    sum=numb1;



    if (sum!=13)
    {//start if
    cout<<endl<<"CARD2:"<<endl;
    rowcard2=rowfunction();
    columncard2=columnfunction();
    numb2=characterarray(array[rowcard2][columncard2]);
    sum=sum+numb2;
    excel=true;
    }//end


    if (sum==13)
    {//start if
        if (rowcard1==0 || rowcard1==7)
        {//start if
        array[rowcard1][columncard1]='.';
        score=scorecounter(score);
        }//end if

        else if (array[rowcard1+1][columncard1]=='.')
        {//start if
            array[rowcard1][columncard1]='.';
            score=scorecounter(score);
        }//end if

        if (excel==true)
        {//start if
            if (rowcard1==0 || rowcard1==7)
            {//start if
                array[rowcard2][columncard2]='.';
                score=scorecounter(score);
            }//end if

            else if (array[rowcard1+1][columncard1]=='.')
            {//start if
                array[rowcard2][columncard2]='.';
                score=scorecounter(score);
            }//end if
        }//end if

    }//end if





//this condition will check whether all cards are finished
if (checkfunction(array)==false)
{//start if
     system("cls");
     cout<<"\n\n\n\n\n\n\n"<<setw(25)<<"score="<<score;
     cout<<"\n"<<setw(25)<<"YOU WIN";
      Sleep(1000);
     system("cls");
    condition=false;
}//end if



}//start if
}//end of while

    return 0;
}//end of  function




int main()
{//start of main function

    int enter;
    bool switchcondition=true;

cout<<"PYRAMID SOLITAIRE BY:\n1.AZEEM ABBAS<<endl<<endl<<endl;
    while(switchcondition==true)
    {//start while
   
        cout<<"ENTER 1 TO START OR 0 TO EXIT:" ;
        cin>>enter;
        switch (enter)
        {//start of switch
        case 1 :
            pyramidsolitaire();//this will start the game
            cout<<endl<<endl;
            break;

        case 0 :
            switchcondition=false;

            break;

        default :
            cout<<endl<<"YOU HAVE ENTERED WRONG INPUT"<<endl<<endl;
        }//end of switch
    }//end while

    system("pause");

    return 0;
}//end of main function

 

DOWNLOAD THE CODE WITH EXECUTABLE FILE:

 


No comments:

Post a Comment