473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

solitaire game

i m designing a solitaire ame in c++......i dont have to use graphics....just use data structure n cmd for out....for the game....i m done with the making of all the classes to b used n the basic functions...now i have to start where the game deals n onwars....think smebody can give me an idea.......help would be highly appreciated.......any idea about how to deal n onwards.....thanx
Sep 29 '06 #1
1 9142
i m designing a solitaire ame in c++......i dont have to use graphics....just use data structure n cmd for out....for the game....i m done with the making of all the classes to b used n the basic functions...now i have to start where the game deals n onwars....think smebody can give me an idea.......help would be highly appreciated.......any idea about how to deal n onwards.....thanx
besides i m having an error n i m working on it for two days....think somebody can help me remove it......



#include<iostream>
using namespace std;
/*****CLASS PLAYING CARD*****/
class PlayingCard
{
private:
int rank;//integer 1-13
int suit;//integer0-3
char color;//red('r') or black('b')
public:
PlayingCard(int,int);
PlayingCard();
void display();
~PlayingCard();
const static int diamond;
const static int heart;
const static int spade;
const static int club;
};
/***** CLASS MAKING PILE OF CARDS*****/
class PileofCards
{
private:
PlayingCard *pile;//pointer to array of playing cards
int top;//last element added to array
int size;//no. of cards in pile
int position;//position of pile amongst others
public:
PileofCards(int,int);
~PileofCards();
PlayingCard Peek();
PlayingCard Remove();
void display();
void Add(PlayingCard);
bool IsEmpty();
bool IsFull();
};

/***** CLASS DECK OF CARDS*****/
class Deck
{
private:
PlayingCard *deck[52];
int size;
public:
Deck();
int getSize();
bool IsEmpty();
PlayingCard getCard(int i);
void Display();
PlayingCard removeCard(int i);
~Deck();
};
/*****CLASS SOLITIRE*****/
class Solitire{

private:
Deck deckofCards;
PileofCards shuffled;
public:
Solitire();
void shuffle();
void display();
};
Solitire::Solitire():shuffled(52,1)
{}

/*****INITIALIZING*****/
const int PlayingCard::diamond=0;
const int PlayingCard::heart=1;
const int PlayingCard::spade=2;
const int PlayingCard::club=3;
/*****CONSTRUCTOR PLAYING CARD*****/
PlayingCard::PlayingCard(int X,int Y)
{
rank=X;
suit=Y;
if(Y==0 || Y==1)
{
color='r';
}
else if(Y==2 || Y==3)
{
color='b';
}
else
{
cout<<"invalid suit,object not created"<<endl;
}
}
/*****CONSTRUCTOR OVERLOADED*****/
PlayingCard::PlayingCard()
{
}
/*****destructor*****/
PlayingCard::~PlayingCard()
{
}

/*****CONSTRUCTOR PILE OF CARDS*****/
PileofCards::PileofCards(int X,int Y)
{
size=X;
position=Y;
pile= new PlayingCard[size];
top=-1;//empty array
}
/*****DESTRUCTOR*****/
PileofCards::~PileofCards()
{
delete [] pile;
}
/*****IS EMPTY*****/
bool PileofCards::IsEmpty()
{
if(top==-1)
{
cout<<"pile empty"<<endl;
return true;
}
else
{
return false;
}
}
/*****IS FULL*****/
bool PileofCards::IsFull()
{
if(top==size-1)
{
cout<<"sorry cannot add since pile is full"<<endl;
return true;
}
else
{
return false;
}


}
/*****ADDING PLAYING CARD TO THE PILE*****/
void PileofCards::Add(PlayingCard X)
{
if(!IsFull())
{
pile[top+1]=X;
top++;
}
}
/*****REMOVING CARD FROM THE PILE*****/
PlayingCard PileofCards::Remove()
{
if(!IsEmpty())
{
top--;
}
return pile[top+1];
}
/*****PEEKING TOP OF THE PILE*****/
PlayingCard PileofCards::Peek()
{
return pile [top];
}
/*****DISPLAY....PLAYING CARD*****/
void PlayingCard::display()
{
cout<<rank<<" "<<suit<<" "<<color<<endl;
}
/*****CONSTRUCTOR DECK*****/
Deck::Deck()
{ int j=0;
for(int i=1;i<=13;i++)
{
deck[j]=new PlayingCard(i,PlayingCard::spade);
j++;
}

for(int k=1;k<=13;k++)
{
deck[j]=new PlayingCard(k,PlayingCard::diamond);
j++;
}

for(int l=1;l<=13;l++)
{
deck[j]=new PlayingCard(l,PlayingCard::heart);
j++;
}

for(int m=1;m<=13;m++)
{
deck[j]=new PlayingCard(m,PlayingCard::club);
j++;
}
size=52;
}
/*****DESTRUCTOR DECK*****/

Deck::~Deck()
{
if(!IsEmpty())
{
for(int i=0;i<size;i++)
{
if(deck[i]!=NULL)
{
delete deck[i];
}
}
}
else
{
delete [] deck;
}
}
/*****GET SIZE*****/
int Deck::getSize()
{
return size;
}
/*****IS EMPTY....DECK*****/
bool Deck::IsEmpty()
{
if(getSize()==0)
{
return true;
}
else
return false;
}
/*****GETCARD*****/
PlayingCard Deck::getCard(int j)
{
return *deck[j];
}
/*****DISPLAY....DECK*****/
void Deck::Display()
{
for(int i=0;i<size;i++)
{
deck[i]->display();
}

}
/*****REMOVE...DECK*****/
PlayingCard Deck::removeCard(int i)
{

PlayingCard temp;
temp=getCard(i);

delete deck[i];
if(!IsEmpty())
{
for(int j=i;j<size;j++)
{
deck[j]=deck[j+1];
}

}

size--;

return temp;
}
/*****SHUFFLE*****/
void Solitire::shuffle()
{
int i;
while (!deckofCards.IsEmpty())
{
i = rand()%deckofCards.getSize();
// cout<<"Remove Card \n";
shuffled.Add(deckofCards.removeCard(i));

}

}
/*****DISPLAY...SOLITIRE*****/
void Solitire::display()
{

if(!shuffled.IsEmpty())
{
shuffled.display();
}

}
/*****DISPLAY...PILE OF CARDS*****/
void PileofCards::display()
{
int i=0;
while(i<=top)
{
pile->display();
i++;
pile++;
}
cout<<i<<endl;
}
/*****MAIN*****/
int main()
{
PlayingCard A(3,PlayingCard::spade);
PlayingCard B(2,PlayingCard::spade);
PlayingCard C(4,PlayingCard::heart);
PlayingCard D(5,PlayingCard::club);
PlayingCard E(3,PlayingCard::diamond);

PlayingCard temp (3,PlayingCard::heart);

PileofCards pile1(5,1);

//cout<<"blah"<<endl;

pile1.Add(A);
pile1.Add(B);
pile1.Add(C);
pile1.Add(D);
pile1.Add(E);

pile1.Add(temp);//displays error

//cout<<"blah"<<endl;
temp=pile1.Remove();
temp.display();

temp=pile1.Remove();
temp.display();

temp=pile1.Remove();
temp.display();

temp=pile1.Remove();
temp.display();

temp=pile1.Remove();
temp.display();

temp=pile1.Remove();//displays error

Deck D1;
PlayingCard F(1,1);
cout<<"original deck"<<endl;
D1.Display(); // Original Deck- 52 cards should be displayed

cout<<"removed cards"<<endl;//index from 0-51
F = D1.removeCard(1);
F.display();
F = D1.removeCard(1);
F.display();
F = D1.removeCard(1);
F.display(); // three cards removed

cout<<"final deck after removal"<<endl;
D1.Display(); //49 cards should be displayed now. 3 cards are already removed
cout<<"loop empties deck"<<endl;
int i=0;
while(!D1.IsEmpty())
{
A = D1.removeCard(i);
A.display();
}
cout<<"emptied"<<endl;
Solitire S;
S.display(); //shuffled pile is empty- nothing should be displayed
S.shuffle();
S.display(); //Shuffled pile now contains 52 shuffled cards.

return 0;
}




I SHALL B THANKFUL TO EVERYONE WHO WUD GIVE IT A LOOK N HELP ME FIND THE ERROR
Sep 29 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: BlackHawke | last post by:
My name is Nick Soutter, I own a small game development company (www.aepoxgames.net) making our first game (www.andromedaonline.net) in java. I am writing because we are having a very...
138
by: theodp | last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml Microsoft Patents Saving The Name Of A Game Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM from the...
7
by: Brandon J. Van Every | last post by:
Anyone know of any "good" open source C# game projects out there? Something that actually has a game engine and some content done, so I can just fiddle with it and do interesting / goofy things. ...
1
by: fowle040 | last post by:
I underlined and bold print my files. I need to know how to make this code into a working game. The object of the game is to have two players 1- belle and 2-beast. I want them to lose and gain...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
5
by: Kraken | last post by:
Hi, i have a bit of a problem here. I have an assignment to do an animal guessing game using an original database and updating it as the user enters new animals in it. The program enters the file...
2
by: LilMeechc20 | last post by:
Hello, I have a group assignment that I have to do. We have to write a Tic Tac Toe game. One person in my group has managed to write the code for a multiplayer (human -vs- human) game and I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.