void buy_card(struct gameState* p, int not_bought[10], int k[10])
{

    int money = 0, j;
    for(j = 0; j < numHandCards(p); j++)
    {
        if(handCard(j,p) == copper)
        {
            playCard(j, -1, -1, -1, p);
            money++;
        }    
        if(handCard(j,p) == silver)
        {
            playCard(j, -1, -1, -1, p);
            money += 2;
        }
        if(handCard(j,p) == gold)
        {
            playCard(j, -1, -1, -1, p);
            money += 3;
        }
    }
    
    if(money > 7)
    {
        buyCard(province, p);
        printf("%d Bought province\n", p->whoseTurn);
    }
    else if(money > 5)
    {
        for(j = 0; j < 10; j++)
        {
            if(!(bought(not_bought, p, k[j])))
            {
                buyCard(k[j], p);
                printf("%d Bought %s\n", p->whoseTurn, get_name(k[j]));
                j = 10;
            }
        }
    }
    else if(money > 5)
    {
        buyCard(gold, p);
        printf("%d Bought gold\n", p->whoseTurn);
    }
    else if(money > 2)
    {
        buyCard(silver, p);
        printf("%d Bought silver\n", p->whoseTurn);
    }
    else
    {
        buyCard(copper, p);
        printf("%d Bought copper\n", p->whoseTurn);
    }
}
Exemple #2
0
void Game:: waitendturn ()
{
	char msg [1024];

	char trash [10];
	char nick [20];
	int amount = -1;
	int price = -1;

	do {
		strcpy (msg, q.gettype ('&'));

		if ( strncmp (msg, "& BOUGHT", 8) == 0) {
			sscanf ( msg, "%s%s%s%d%d", trash, trash, 
					nick, &amount, &price);
			if ( amount == - 1 || price == -1 ) {
				perror ("Syntax error in BOUGHT.\n");
			}
			bought (nick, amount, price);
		} else if ( strncmp (msg, "& SOLD", 6) == 0) {
			sscanf ( msg, "%s%s%s%d%d", trash, trash, 
					nick, &amount, &price);
			if ( amount == - 1 || price == -1 ) {
				perror ("Syntax error in SOLD.\n");
			}
			sold (nick, amount, price);
		} else if ( strncmp (msg, "& BANKRUPT", 10) == 0) {
			sscanf (msg, "%s%s%s", trash, trash, nick);
			bankrupt (nick);
		}
	} while ( strncmp (msg, "& ENDTURN", 9) != 0 );

	lp->month_expense ();

	++ month;

//	printf ("NEXT TURN. Now will start %dth month.\n", month);
}