示例#1
0
int main( void )
{
    InitAll();
    curGS = CreateGameState();
    BuildResources (curGS->res);
    LoadUnlockProfile(curGS);
    BuildMainMenu(curGS);
    RunGameState(curGS);
    FreeGameState(curGS);
    return 0;
}
//Random test for adventurer
int main() {
	
	int i, j, acard, foundTreasure, totalCards, prevHandCount, prevDeckDiscardCount, playerTreasure, numFailed;
	struct gameState g;
	char cardName[MAX_STRING_LENGTH];
	
	//Create gameStates with random properties
	for (i = 0; i < NUMTESTS; i++) {
		
		CreateGameState(&g);
		
		/*
		-- Now we have everything setup, lets start testing!
		-- We will check for these conditions:
		--		- Handcount increases by number of treasure found
		--		- Deck + Discard count descreases by number of treasure found
		--		- Check that the cards in the hand contain the treasure found
		--
		*/
		
		foundTreasure = 0;
		totalCards = CountCards(&g);
		prevHandCount = g.handCount[0];
		prevDeckDiscardCount = g.deckCount[0] + g.discardCount[0];
		playerTreasure = CountTreasure(&g);
		for (j = 0; j < g.deckCount[0]; j++) {
			if (g.deck[0][j] == copper || g.deck[0][j] == silver || g.deck[0][j] == gold) {
				if (foundTreasure >= 2)
					break;
				foundTreasure++;
			}
		}
		for (j = 0; j < g.discardCount[0]; j++) {
			if (g.discard[0][j] == copper || g.discard[0][j] == silver || g.discard[0][j] == gold) {
				if (foundTreasure >= 2)
					break;
				foundTreasure++;
			}
		}

		playCard(0, 0, 0, 0, &g);
		
		if (g.handCount[0] != prevHandCount + foundTreasure - 1) {
			printf("Test %d:Incorrect hand count. %d treasure in player's deck. Handcount is %d but should be %d\n", i, foundTreasure, g.handCount[0], prevHandCount + foundTreasure - 1);
			numFailed++;
			if (foundTreasure = 0) {
				printHand2(g, 0);
			}
		}
		if (g.deckCount[0] + g.discardCount[0] != prevDeckDiscardCount - foundTreasure) {
			printf("Test %d:Incorrect deck and discard count. %d treasure in player's deck. Deck + discard count is %d but should be %d\n", i, foundTreasure, g.deckCount[0] + g.discardCount[0], prevDeckDiscardCount - foundTreasure);
			numFailed++;
		}
		if (foundTreasure == 2) {
			//Treasure cards are going to be in first and last indicies
			acard = g.hand[0][g.handCount[0] - 1];
			if (acard != copper && acard != silver && acard != gold) {
				strcpy(cardName,"");
				cardNumToName(acard, cardName);
				printf("Test %d:Incorrect cards at position %d. %d treasure in player's deck. Last card in hand should be %s, %s, or %s, is %s\n", i, g.handCount[0] - 1, foundTreasure, "copper", "silver", "gold", cardName);
				printHand2(g, 0);
				numFailed++;
			}
			acard = g.hand[0][0];
			if (acard != copper && acard != silver && acard != gold) {
				strcpy(cardName,"");
				cardNumToName(acard, cardName);
				printf("Test %d:Incorrect cards at position %d. %d treasure in player's deck. First card in hand should be %s, %s, or %s, but is %s\n", i, 0, foundTreasure, "copper", "silver", "gold", cardName);
				printHand2(g, 0);
				numFailed++;
			}
		}
		else if (foundTreasure == 1) {
			acard = g.hand[0][0];
			if (acard != copper && acard != silver && acard != gold) {
				strcpy(cardName,"");
				cardNumToName(acard, cardName);
				printf("Test %d:Incorrect cards at position %d. %d treasure in player's deck. First card in hand should be %s, %s, or %s, but is %s\n", i, 0, foundTreasure, "copper", "silver", "gold", cardName);
				printHand2(g, 0);
				numFailed++;
			}
		}
	}
	
	printf("%d of %d test were successful.\n", NUMTESTS - numFailed, NUMTESTS);
	
	return 0;
}