1
int main()
{ srand(time(NULL));
Card c;
Card *Pc;
Pc = new Card [52];
Card ** someHands;
// typedef Card * Hand;
// Hand *someHands;
CardtoArray(c,Pc);
printDeckofCards(Pc,c);
}
Card GenerateCards(Card c)
{
int CardNum;
CardNum=rand() % 13 + 1;
int colour =rand() % 4 + 1;
switch(CardNum)
{
case 1: c.rank= Ace;
break;
case 2: c.rank= Two;
break;
case 3: c.rank= Three;
break;
case 4: c.rank= Four;
break;
case 5: c.rank= Five;
break;
case 6: c.rank= Six;
break;
case 7: c.rank= Seven;
break;
case 8: c.rank= Eight;
break;
case 9: c.rank= Nine;
break;
case 10: c.rank= Ten;
break;
case 11: c.rank= Jack;
break;
case 12: c.rank= Queen;
break;
case 13: c.rank= King;
break;
}
switch(colour)
{
case 1:c.color="Diamond";
break;
case 2:c.color="Club";
break;
case 3:c.color="Heart";
break;
case 4:c.color="Spade";
break;
}
return c;
}
//打印一張卡,此功能是要調入功能// printsdeckofcards工作 無效printCard(卡C) {
cout<<*c.color;
if(c.rank==Ace)
cout<<"A";
else if(c.rank==Two)
cout<<"2";
else if(c.rank==Three)
cout<<"3";
else if(c.rank==Four)
cout<<"4";
else if(c.rank==Five)
cout<<"5";
else if(c.rank==Six)
cout<<"6";
else if(c.rank==Seven)
cout<<"7";
else if(c.rank==Eight)
cout<<"8";
else if(c.rank==Nine)
cout<<"9";
else if(c.rank==Ten)
cout<<"10";
else if(c.rank==Jack)
cout<<"J";
else if(c.rank==Queen)
cout<<"Q";
else if(c.rank==King)
cout<<"K";
}
//生成和插入卡52也調用函數samecard,以檢查是否已經產生 //智能卡被複制,並且如果之前,所以再生一個新//插入到陣列 無效CardtoArray(卡& C,卡* PC) {
Card *origin;
origin=Pc;
for(int i=0;i<52;i++)
{
c=GenerateCards(c);
if(SameCard(c,origin)==false)
{
*Pc=c;
Pc++;
}
else
i--;
}
}
void printDeckofCards(Card *Pc,Card c)
{
for(int i=0;i<52;i++)
{
printCard(*Pc);
cout<<" ";
Pc++;
}
}
bool SameCard(Card c,Card *Pc)
{ bool check;
for(int i=0; i<52; i++)
{
if(Pc->color==c.color && Pc->rank==c.rank)
{
check = true;
}
else
{
check = false;
}
Pc++;
}
return check;
}
塊引用
而且哪裏的東西「不行」? –
我的檢查函數無法檢查我的卡是否在插入指針數組之前被複制過,總是有重複的結果 –
您可能會喜歡閱讀:[如何調試小程序](https://ericlippert.com/2014/ 03/05/how-to-debug-small-programs /) – alk