Beispiel #1
0
Node* CopyDeck(Node *head){
    int newDeckSize = DeckSize(head);
    return CreateDeck(newDeckSize);
}
Beispiel #2
0
int main(int argc, const char * argv[])
{
    int game = 0;
    char ch,response;
    while(game==0)//continues until user choses not to continue anymore
    {
        printf("Do you want a new name? (Y or N)");
        scanf("%c",&ch);//scans for whether new name or not
        fflush(stdin);
        if(ch=='Y'||ch=='y')
        {
            printf("Enter new name: ");
            scanf("%s",username);//scans for new name
            fflush(stdin);
        }
        printf("\n\nGame begins between Computer and %s\n\n",username);
        srand((int)time(NULL));
        printf("Deck of Cards\n\n");
        CreateDeck();
        for(i=1;i<=4;i++)
        {
            for(j=1;j<=13;j++)
            {
                if(deck.suit[j+(i*13)] == 'C' && deck.face[j+(i*13)]== 12)//removes queen of clubs
                {
                    deck.suit[j+(i*13)] = NULL;
                    deck.face[j+(i*13)] = 0;
                }
            }
        }
        printf("Deck of Cards after one queen is removed\n\n");
        for(i=0;i<4;i++)
        {
            for( j=1;j<=13;j++)
            {
                if(deck.face[j+(i*13)]!=0)
                    printf("%c%d ",deck.suit[j+(i*13)],deck.face[j+(i*13)]);//prints new deck without C12
            }
        }
        printf("\n\n");
        ShuffleDeck();//calls shuffle deck function
        DealCards();//calls deal cards function
        RemovePairs();//calls remove pairs function
        PairSearch();//calls pair search function
        c=0;
        wins=fopen("wins.txt","w");//opens wins.txt for writing
        for(i=0;i<k;i++)
        {
            if(user.face[i]!=0)//if user has a card c updates
                c++;
        }
        if(c==0)
        {
            fprintf(wins,"%s\tWins\n",username);//prints name	 wins in wins.txt
            printf("Computer loses. %s Win!!!\n\n",username);//prints computer loses and player wins in program
        }
        else
        {
            fprintf(wins,"%s\tLoses\n",username);
            printf("%s loses. Computer Wins!!!\n\n",username);
        }
        fclose(wins);
        printf("Would you like to play again?(Y or N)");//asks if want to play again
        scanf("%c", &response);
        if(response== 'Y'||response=='y')//if yes stays in while loop
        {
            game=0;
        }
        else//if no exits while loop
        {
            game =1;
        }
        fflush(stdin);
    }
    return 0;
}