test.c
contest/standalone/test.c · 3.3 KB
From the archive contest.tgz.1
Download the archive « Back to the archive contents
/******************************************************************************
Copyright 2005 Richard Woolcock. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "card.h"
#include "deck.h"
#include "hand.h"
int main( void )
{
deck_t *pDeck = DeckCreate();
hand_t *pHand = HandCreate();
if ( pDeck != NULL && pHand != NULL )
{
card_t Card;
int i; /* Loop counter */
/* Display the deck */
printf( "\n\rDeck contains %d cards, as follows:\n\r", DeckCountCards(pDeck) );
printf( DeckShow(pDeck, eTrue, eTrue) );
/* Shuffle the deck */
printf( "\n\rShuffling the deck...\n\r" );
DeckShuffle( pDeck );
/* Display the deck */
printf( "\n\rDeck contains %d cards, as follows:\n\r", DeckCountCards(pDeck) );
printf( DeckShow(pDeck, eTrue, eTrue) );
/* Remove 6 cards from the deck and add them to the hand */
printf( "\n\rDrawing 6 cards: " );
for ( i = 0; i < 6; ++i )
{
Card = DeckDrawCard(pDeck);
HandAddCard( pHand, Card );
printf( "%s ", CardValue(Card) );
}
/* Display the deck */
printf( "\n\r\n\rDeck contains %d cards, as follows:\n\r", DeckCountCards(pDeck) );
printf( DeckShow(pDeck, eTrue, eTrue) );
/* Remove the last card from the hand and put it back in the deck */
printf( "\n\rPutting the card '%s' back on the bottom of the deck.\n\r", CardValue(Card) );
HandRemoveCard(pHand,Card);
DeckReturnCard(pDeck,Card);
/* Display the deck */
printf( "\n\rDeck contains %d cards, as follows:\n\r", DeckCountCards(pDeck) );
printf( DeckShow(pDeck, eTrue, eTrue) );
/* Display the hand, both values and graphical */
printf( "\n\rHand contains %d cards, as follows: ", HandCountCards(pHand) );
printf( "%s\n\r\n\r", HandShow(pHand, eFalse) );
printf( "%s\n\r", HandShow(pHand, eTrue) );
}
return 0;
}