void ComponentSkill::onMessage(const Message& message)
{
	Message newMessage;
	switch (message.type)
	{
	case Message::TRY_BUY:
		canBuy(message.value, message.gameObject);
		break;
	case Message::ADD_EXPERIENCE:
		jade += message.value*2/3;
		newMessage.type = Message::JADE_CHANGED;
		newMessage.value = jade;
		parent->broadcastMessage(newMessage);
		break;
	case Message::USE_SKILL:
		useSkill(message.value);
		break;
	case Message::LEVEL_CHANGED:
		addLevel(message.value);
		break;
	case Message::DEATH:
		down = true;
		for(size_t i = 0;i < skills.size();i++)
		{
			skills[i]->deselect();
		}
		break;
	case Message::REPAIRED:
		down = false;
		break;
	}

}
Beispiel #2
0
// Very basic strategy:
// - Sell if the price is >= 4
// - Buy if the price is <= 2
// - Lower price if combined opponents have more stock than I do
// - Otherwise raise price by as little as possible
void makeMove() {
  int die1, die2;
  scanf("%d %d", &die1, &die2);

  if (turnCounter == CRASH_AT_TURN) {
    fprintf(stderr, "Oh no, I crashed!\n");
    exit(42);
  } else if (turnCounter == LOOP_AT_TURN) {
    while (true);
  } else if (turnCounter == BAD_MOVE_AT_TURN) {
    raise(MAX_DIE + 1 - die1, die2);
    printf("R %d %d\n", MAX_DIE + 1 - die1, die2);
  } else if (canSell(die1, die2)) {
    sell(me, die1, die2);
    printf("S %d %d\n", die1, die2);
  } else if (canSell(die2, die1)) {
    sell(me, die2, die1);
    printf("S %d %d\n", die2, die1);
  } else if (canBuy(die1, die2)) {
    buy(me, die1, die2);
    printf("B %d %d\n", die1, die2);
  } else if (canBuy(die2, die1)) {
    buy(me, die2, die1);
    printf("B %d %d\n", die2, die1);
  } else if (canLower(die1, die2)) {
    lower(die1, die2);
    printf("L %d %d\n", die1, die2);
  } else if (canLower(die2, die1)) {
    lower(die2, die1);
    printf("L %d %d\n", die2, die1);
  } else if (die1 < die2) {
    raise(die1, die2);
    printf("R %d %d\n", die1, die2);
  } else {
    raise(die2, die1);
    printf("R %d %d\n", die2, die1);
  }
  fflush(stdout);
}
void LLCurrencyUIManager::buy(const std::string& buy_msg)
{
	if (!canBuy())
	{
		return;
	}

	LLUIString msg = buy_msg;
	msg.setArg("[LINDENS]", llformat("%d", impl.mUserCurrencyBuy));
	msg.setArg("[LOCALAMOUNT]", getLocalEstimate());
	LLConfirmationManager::confirm(impl.mSiteConfirm,
								   msg,
								   impl,
								   &LLCurrencyUIManager::Impl::startCurrencyBuy);
}
void LLCurrencyUIManager::buy(const std::string& buy_msg)
{
	if (!canBuy())
	{
		return;
	}

	LLUIString msg = buy_msg;
	msg.setArg("[LINDENS]", llformat("%d", impl.mUserCurrencyBuy));
	msg.setArg("[USD]", llformat("%#.2f", impl.mSiteCurrencyEstimatedCost / 100.0));
	LLConfirmationManager::confirm(impl.mSiteConfirm,
								   msg,
								   impl,
								   &LLCurrencyUIManager::Impl::startCurrencyBuy);
}
void LLCurrencyUIManager::buy(const std::string& buy_msg)
{
	if (!canBuy())
	{
		return;
	}

	LLUIString msg = buy_msg;
	msg.setArg("[LINDENS]", llformat("%d", impl.mUserCurrencyBuy));
	msg.setArg("[CURRENCY]", gHippoGridManager->getConnectedGrid()->getCurrencySymbol());
	msg.setArg("[USD]", llformat("%#.2f", impl.mSiteCurrencyEstimatedCost / 100.0));
	msg.setArg("[REALCURRENCY]", gHippoGridManager->getConnectedGrid()->getRealCurrencySymbol());
	LLConfirmationManager::confirm(impl.mSiteConfirm,
								   msg,
								   impl,
								   &LLCurrencyUIManager::Impl::startCurrencyBuy);
}
int main() {
	struct gameState G;
	FILE *out;
	int nplayers = 0, ntests=0,i=0,j=0,k[10],redo = 1,seed, currentp=0, actions =0, *played, turn, ncoins=0, buyA = -1;
	out = fopen("gameResults.out","w");
	srand(time(NULL));
	
	nplayers = rand() % 3 + 2;
	// iterate through multiple tests
	while(ntests < MAX_TESTS) {
		turn = 1;
		seed = rand();
		printf("random seed %d ", seed);
		printf("in tests\n");
		fprintf(out, "Initializing game: %d\n", ntests);
		//pick cards
		for(i=0;i < 10; i++){
			printf("stuck picking cards\n");
			//kingdom cards unique no repeats
			do {
			redo = 0;
			k[i] = rand() % 20 + 7;
			printf("%d ", k[i]);
				for(j=0; j < i; j++) {
					if(k[i] == k[j]){
						redo = 1;
					} 
				}
			} while(redo);
		}
		fprintf(out, "Kingdom cards: \n");
		for(i=0; i < 10; i++) {
			fprintf(out,"%s, ", numName(k[i]));
		}
		fprintf(out,"\n");
		initializeGame(nplayers, k, seed, &G);
		printf("past init games\n");
		//Print player hands
		/*fprintf(out, "Player hands: \n");
		for(i=0; i < nplayers; i++) {
			fprintf(out,"P%d: {\n",i);
			for(j=0; j < numHandCards(&G); j++) {
				//fprintf(out, "\tC%d: %s\n", j, numName(handCard(j, &G)));
				//debug
				fprintf(out, "\tC%d: %d\n", j, handCard(j, &G));
			}
			fprintf(out, "}\n");
		}
		*/
		
		while(!isGameOver(&G)) {
			//printf("stuck in game\n");
			currentp = whoseTurn(&G);
			//Print turn player cards and info
			fprintf(out, "-- P%d turn %d --\n Current hand: {", currentp,turn);
			for(i=0; i < numHandCards(&G); i++) {
				fprintf(out, "C%d: %s ", i, numName(handCard(i, &G)));
			}
			fprintf(out, "}\n <-- Action Phase -->\n");
			//start action phase
			actions = 0;
			ncoins = coins(&G);
			G.coins = ncoins;
			for(i=0;i < G.numActions;i++) {
				fprintf(out, "#A: %d\n", G.numActions);
				played = playing(k, &G);
				if(played == 0) {
					fprintf(out, "No playable cards\n");
					break;
				}
				fprintf(out, "Playing: %s\n Choices: %d, %d, %d\n", numName(played[0]), played[1], played[2], played[3]);
				
				if(playCard(played[0], played[1], played[2], played[3], &G) == -1)
					fprintf(out, "\tFailure to play %s\n", numName(played[0]));
			}
			
			//start buy phase
			fprintf(out, "<-- Buy Phase --> \n");
			for(i=0; i < G.numBuys; i++) {
				buyA = canBuy(k, &G);
				fprintf(out, "Buying a %s\n", numName(buyA));
				if(buyCard(buyA, &G) == -1)
					fprintf(out, "\tFailed to buy\n");
				G.coins -= getCost(buyA);
			}
			
			//end of turn
			//fprintf(out, "-- End P%d turn --\n", currentp);
			endTurn(&G);
			free(played);
			turn++;
		}
		
	
	ntests++;
	turn = 1;
	}
	fclose(out);
	return 0;
}
void PurchasableVirtualItem::buy(const std::string& payload) {
    if (not canBuy()) {
        return;
    }
    getPurchaseType()->buy(payload);
}