voidcreate();// Includes create toplist, boardlists and foundlists
voidcreate_toplist();
voidcreate_boardlists();
voidcreate_foundlists();
voidprintkart(Card_Node*kart);// prints datas of one kart node
voidprintlists();// Prints all lists
voidprintmenu();//Prints choice menu
booladdcardtolist(List_Node*selectedlist,Card_Node*transferedcard,intwhichlisttype);//Adds transferedcard to selectedlist, whichlisttype is entered by program
voidgoster_TopToFoundation();//Gets input and calls related function
voidTopToFoundation(chars_color,chars_suit,ints_value);// Moves a card top list to foundation list
voidgoster_TopToBoard();//Gets input and calls related function
voidTopToBoard(intlistindex,chars_color,chars_suit,ints_value);//Moves a card from top list to board list
voidgoster_BoardToBoard();//Gets input and calls related function
voidBoardToBoard(intfromwhere,inttowhere,chars_color,chars_suit,ints_value);//Moves a card(s) from a fromwhere.list to towhere.list
voidgoster_BoardToFoundation();//Gets input and calls related function
voidBoardToFoundation(intfromwhere);//Moves a last card in fromwhere.list of boardlist to foundation list
voidislem_yap();//Wants user to select choice from menu, and calls related functions
boolistopempty,isboardempty;// For controlling end of game
voidclear_screen();//Clears screen both windows and linux system
voidclose();//Deletes all linked lists and linkedlists's all nodes, closes read txt file
};
Listislem;
usingnamespacestd;
intmain()
{
charsecim;
islem.create();
if(!islem.fptr)//If cannot find solitaire.txt file, close the program
return0;
islem.istopempty=false;//If the top list is empty, this value will be true
islem.isboardempty=false;//If the board list is empty, this value will be true
while(1){
islem.printlists();
islem.printmenu();
cin>>secim;
cin.ignore(10000,'\n');
if(secim=='1'){
islem.goster_TopToFoundation();
cin.ignore(10000,'\n');
getchar();
}
elseif(secim=='2'){
islem.goster_TopToBoard();
cin.ignore(10000,'\n');
getchar();
}
elseif(secim=='3'){
islem.goster_BoardToBoard();
cin.ignore(10000,'\n');
getchar();
}
elseif(secim=='4'){
islem.goster_BoardToFoundation();
cin.ignore(10000,'\n');
}
elseif(secim=='9'){
islem.close();
printf("\n\nThe game is closed and all cards are deleted from memory.Press enter to exit");
cin.ignore(10000,'\n');
getchar();
break;
}
else
cout<<"Invalid choice"<<endl;
if(!islem.top_head)// checking top list empty or not
cout<<"The 'solitaire.txt' file cannot be found. Program will be closed."<<endl;
getchar();
return;
}
fseek(fptr,0,SEEK_SET);
create_toplist();
create_boardlists();
create_foundlists();
}//end create function
voidList::create_toplist(){
Card_Node*newnode,*final;
chartempcolor,tempsuit,tempvalue[4],tempisup[4],garbage[10];//temporary values of color,suit,isup. value will be changed to integer and isup(Up or Down) will be changed to boolean variables
top_head=NULL;
while(1){//This while creates top_list with linked list
newnode=newCard_Node;
newnode->next=NULL;
fscanf(fptr,"%c",&tempcolor);
if(tempcolor=='*'){//first star has read
fscanf(fptr,"%6c",garbage);//passes other five stars and goes new line
printf("\n");//if at least one card is not null: go new line
else
break;// if all cards in line are null: break outer for loop
}//end outer for
printf("\n\n");
}//end function
voidList::printmenu(){
cout<<"Choose an operation:"<<endl;
cout<<"\t1. Select from Top List to Foundation Lists"<<endl;
cout<<"\t2. Select from Top List to Board Lists"<<endl;
cout<<"\t3. Move on the Board Lists"<<endl;
cout<<"\t4. Move from Board List to Foundation List"<<endl;
cout<<"Please enter your choice (1, 2, 3, or 4), (enter 9 to exit):";
}
boolList::addcardtolist(List_Node*selectedlist,Card_Node*transferedcard,intwhichlisttype){//whichlisttype is not related with user, it is automatically entered by progra
Card_Node*cardtraverser;
cardtraverser=selectedlist->cards;
if(whichlisttype==1){//whichlisttype is 1 for top to board list
if(cardtraverser==NULL&&transferedcard->value==13){// if list is empty card's value must be K=13
selectedlist->cards=transferedcard;
transferedcard->next=NULL;
returntrue;
}
if(!cardtraverser)// cardtraverse cannot be null here, can be null only for value K=13
returnfalse;
while(cardtraverser->next)
cardtraverser=cardtraverser->next;
if(!cardtraverser->isup){// if the card is down, color and value between two cards are not important
cardtraverser->next=transferedcard;
transferedcard->next=NULL;
returntrue;
}
if(cardtraverser->isup)// if the card is up, color and value between two cards are important
if(!(transferedcard->color==cardtraverser->color))// if colors between two adjacent cards are different
if(cardtraverser->value-transferedcard->value==1){//list's last value - transfered card's value - must be 1
cardtraverser->next=transferedcard;
transferedcard->next=NULL;
returntrue;
}
}
if(whichlisttype==2){// whichlisttype is 2 for moving top to foundation list
if(cardtraverser==NULL&&transferedcard->value==1){// if list is empty card's value must be A=1
selectedlist->cards=transferedcard;
transferedcard->next=NULL;
returntrue;
}
if(!cardtraverser)// cardtraverse cannot be null here, can be null only for value A=1
returnfalse;
while(cardtraverser->next)
cardtraverser=cardtraverser->next;
if(transferedcard->value-cardtraverser->value==1){//if list is not empty, list's last value - card's value must be 1
cardtraverser->next=transferedcard;
transferedcard->next=NULL;
returntrue;
}
}
if(whichlisttype==3){//whichlisttype is 3 for board to board list
if(cardtraverser==NULL&&transferedcard->value==13){// if list is empty card's value must be K=13
selectedlist->cards=transferedcard;
returntrue;
}
if(!cardtraverser)// cardtraverse cannot be null here, can be null only for value K=13
returnfalse;
while(cardtraverser->next)
cardtraverser=cardtraverser->next;
if(!cardtraverser->isup){// if the card is down, color and value between two cards are not important
cardtraverser->next=transferedcard;
returntrue;
}
if(cardtraverser->isup)// if the card is up, color and value between two cards are important
if(!(transferedcard->color==cardtraverser->color))// if colors between two adjacent cards are different
if(cardtraverser->value-transferedcard->value==1){//list's last value - transfered card's value - must be 1
cardtraverser->next=transferedcard;
returntrue;
}
}
if(whichlisttype==4){// whichlisttype is 4 for moving board to foundation list
if(cardtraverser==NULL&&transferedcard->value==1){// if list is empty card's value must be A=1
selectedlist->cards=transferedcard;
transferedcard->next=NULL;
returntrue;
}
if(!cardtraverser)// cardtraverse cannot be null here, can be null only for value A=1
returnfalse;
while(cardtraverser->next)
cardtraverser=cardtraverser->next;
if(transferedcard->value-cardtraverser->value==1){//if list is not empty, list's last value - card's value must be 1
cardtraverser->next=transferedcard;
transferedcard->next=NULL;
returntrue;
}
}
returnfalse;
}
voidList::goster_TopToFoundation(){// wants input from use