//class TestScene
void TestScene::init()
{
	button.setPosition(ftVec2(320, 260));
	button.setRectSize(ftVec2(130, 50));
	button.setId(9);
	mainCamera.setViewport(fountain::getWinRect());
	customInit();
}
bool OgroInvasion::onBeforeRun()
{
	auto window = Director::getInstance()->getWindow();

	if (!window)
	{
		window = Director::getInstance()->createDefaultWindow();
		window->setGLVersion(3, 3);
		window->createWindow("ImageLoader", 512, 512);
		bool result = window->initGL();
		if (!result)
			return false;

		Director::getInstance()->setWindow(window);
	}

	customInit();

	return true;
}
Exemple #3
0
bool HelloGLSL::onBeforeRun()
{
    auto window = Director::getInstance()->getWindow();

    if (!window)
    {
        window = Director::getInstance()->createDefaultWindow();
        window->setGLVersion(3, 3);
        window->createWindow("Hello", 640, 480);
        bool result = window->initGL();
        if (!result)
            return false;

        Director::getInstance()->setWindow(window);
    }

    customInit();

    return true;
}
Exemple #4
0
bool Application::init()
try
{
    // initialize resources
#if !defined(DESKTOP)
    Q_INIT_RESOURCE(keyboard);
    Q_INIT_RESOURCE(rotation);
    Q_INIT_RESOURCE(eink);
#if defined(EINK)
    setCursorFlashTime(0);
#endif
#endif

    QString logFile( Platform::get()->getUserSettingsPath() + QDir::separator() + applicationName() + ".log.txt" );
    g_pLog = new Log( QFile::encodeName(logFile).constData(), 1, 1 );

    g_pConfig = new Config(applicationName());
    int logLevel = g_pConfig->readInt("log_level", -1);
    if ( -1 == logLevel )
    {
        logLevel = qgetenv("VLASOVSOFT_LOG").toInt();
    } 
    if ( logLevel < 0 ) logLevel = 0;
    if ( logLevel > 2 ) logLevel = 2;
    g_pLog->setLevel( logLevel );

    g_pLog->write(1, Log::MT_I, "Program started, version: %s.%s", VERSION, REVISION);

    // set default application font
    QFont fnt = font();
    fnt.setPointSize(Platform::get()->getDefaultFontSize());
    setFont(fnt);

#if defined(EINK)
    // set palette
    QPalette pal = palette();
    pal.setColor(QPalette::Window, Qt::white);
    pal.setColor(QPalette::Highlight, Qt::black);
    setPalette(pal);
#endif

#if defined(ANDROID) || defined(SIMPLE) || defined(IOS)
    QPalette pal = palette();
    pal.setColor(QPalette::Highlight, Qt::darkBlue);
    pal.setColor(QPalette::HighlightedText, Qt::white);
    setPalette(pal);
#endif

#if !defined(DESKTOP)
    StyleEbook* pStyle = new StyleEbook(style());
    int bSize = g_pConfig->readInt( "button_size", 40 ); // 40 = 1 cm
    QSize size( getSizePx( QSize(bSize, bSize), 5 ) );
    pStyle->setButtonIconSize(qMax( size.width(), size.height() ));
    setStyle(pStyle);
#endif

#if defined(Q_WS_QWS)
    QWSServer::setBackground(QBrush(Qt::black));
    setNavigationMode( Qt::NavigationModeKeypadDirectional );
#endif

#if defined(ANDROID)
    installEventFilter(&kf);
#endif

    loadTranslations();

    customInit();

    return true;
}
catch(const Exception& e)
{
    if ( g_pLog != NULL )
        g_pLog->write(1, Log::MT_F, "Fatal error: %s", e.what());
    ::messageBox(0, QMessageBox::Critical, qApp->translate("main", "Error:"), QString::fromLocal8Bit(e.what()) );
    return false;
}
catch(...)
{
    if ( g_pLog != NULL )
        g_pLog->write(1, Log::MT_F, "Fatal error!");
    ::messageBox(0, QMessageBox::Critical, qApp->translate("main", "Error:"), "Fatal error!" );
    return false;
}
Exemple #5
0
int main() {

	printf("TEST: SCOREFOR\n\n");
	srand(RSEED);

	int players, numCurse, numEstate, numDuchy, numProvince, numGardens, numGreatHall, victoryCount, curseCount;
	players = rand() % (MAX_PLAYERS - 2) + 2;

	if (players == 2) {
		victoryCount = 8;
		curseCount = 10;
	}
	else if (players == 3) {
		victoryCount = 12;
		curseCount = 20;
	}
	else {
		victoryCount = 12;
		curseCount = 30;
	}


	struct gameState state;
	int cards[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
	customInit(players, cards, &state);
	printf("TEST: Cards in hand\n");

	int i, j, k;
	for (i = 0; i < players; i++) {
		printf("Player %d\n", i + 1);
		numCurse = rand() % (curseCount + 1);
		printf("Curse: %d\n", numCurse);
		numEstate = rand() % (victoryCount + 1);
		printf("Estate: %d\n", numEstate);
		numDuchy = rand() % (victoryCount + 1);
		printf("Duchy: %d\n", numDuchy);
		numProvince = rand() % (victoryCount + 1);
		printf("Province: %d\n", numProvince);
		numGardens = rand() % (victoryCount + 1);
		printf("Gardens: %d\n", numGardens);
		numGreatHall = rand() % (victoryCount + 1);
		printf("Great Hall: %d\n", numGreatHall);

		k = 0;
		j = 0;
		while (j < numCurse) {
			state.hand[i][k] = curse;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numEstate) {
			state.hand[i][k] = estate;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numDuchy) {
			state.hand[i][k] = duchy;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numProvince) {
			state.hand[i][k] = province;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numGardens) {
			state.hand[i][k] = gardens;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numGreatHall) {
			state.hand[i][k] = great_hall;
			state.handCount[i]++;
			j++;
			k++;
		}
		j = 0;

		int deck = state.deckCount[i] + state.handCount[i] + state.discardCount[i];
		printf("Total deck: %d\n", deck);
		int internalsum = internalPointsCalc(numCurse, numEstate, numDuchy, numProvince, numGardens, numGreatHall, deck);
		int score = scoreFor(i, &state);
		printf("Expected score: %d\n", internalsum);
		printf("Calculated score: %d\n", score);
		if (internalsum == score)
			printf("PASSED\n");
		else
			printf("FAILED\n");

	}

	customInit(players, cards, &state);
	printf("TEST: Cards in deck\n");
		for (i = 0; i < players; i++) {
		printf("Player %d\n", i + 1);
		numCurse = rand() % (curseCount + 1);
		printf("Curse: %d\n", numCurse);
		numEstate = rand() % (victoryCount + 1);
		printf("Estate: %d\n", numEstate);
		numDuchy = rand() % (victoryCount + 1);
		printf("Duchy: %d\n", numDuchy);
		numProvince = rand() % (victoryCount + 1);
		printf("Province: %d\n", numProvince);
		numGardens = rand() % (victoryCount + 1);
		printf("Gardens: %d\n", numGardens);
		numGreatHall = rand() % (victoryCount + 1);
		printf("Great Hall: %d\n", numGreatHall);

		k = state.deckCount[i];
		j = 0;
		while (j < numCurse) {
			state.deck[i][k] = curse;
			state.deckCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numEstate) {
			state.deck[i][k] = estate;
			state.deckCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numDuchy) {
			state.deck[i][k] = duchy;
			state.deckCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numProvince) {
			state.deck[i][k] = province;
			state.deckCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numGardens) {
			state.deck[i][k] = gardens;
			state.deckCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numGreatHall) {
			state.deck[i][k] = great_hall;
			state.deckCount[i]++;
			j++;
			k++;
		}
		j = 0;

		
		int deck = state.deckCount[i] + state.handCount[i] + state.discardCount[i];
		printf("Total deck: %d\n", deck);
		int internalsum = internalPointsCalc(numCurse, numEstate, numDuchy, numProvince, numGardens, numGreatHall, deck);
		int score = scoreFor(i, &state);

		printf("Expected score: %d\n", internalsum);
		printf("Calculated score: %d\n", score);
		if (internalsum == score)
			printf("PASSED\n");
		else
			printf("FAILED\n");

	}

	customInit(players, cards, &state);
	printf("TEST: Cards in discard\n");
		for (i = 0; i < players; i++) {
		printf("Player %d\n", i + 1);
		numCurse = rand() % (curseCount + 1);
		printf("Curse: %d\n", numCurse);
		numEstate = rand() % (victoryCount + 1);
		printf("Estate: %d\n", numEstate);
		numDuchy = rand() % (victoryCount + 1);
		printf("Duchy: %d\n", numDuchy);
		numProvince = rand() % (victoryCount + 1);
		printf("Province: %d\n", numProvince);
		numGardens = rand() % (victoryCount + 1);
		printf("Gardens: %d\n", numGardens);
		numGreatHall = rand() % (victoryCount + 1);
		printf("Great Hall: %d\n", numGreatHall);

		k = 0;
		j = 0;
		while (j < numCurse) {
			state.discard[i][k] = curse;
			state.discardCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numEstate) {
			state.discard[i][k] = estate;
			state.discardCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numDuchy) {
			state.discard[i][k] = duchy;
			state.discardCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numProvince) {
			state.discard[i][k] = province;
			state.discardCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numGardens) {
			state.discard[i][k] = gardens;
			state.discardCount[i]++;
			j++;
			k++;
		}
		j = 0;
		while (j < numGreatHall) {
			state.discard[i][k] = great_hall;
			state.discardCount[i]++;
			j++;
			k++;
		}
		j = 0;

		
		int deck = state.deckCount[i] + state.handCount[i] + state.discardCount[i];
		printf("Total deck: %d\n", deck);
		int internalsum = internalPointsCalc(numCurse, numEstate, numDuchy, numProvince, numGardens, numGreatHall, deck);
		int score = scoreFor(i, &state);

		printf("Expected score: %d\n", internalsum);
		printf("Calculated score: %d\n", score);
		if (internalsum == score)
			printf("PASSED\n");
		else
			printf("FAILED\n");

	}

	customInit(players, cards, &state);
	printf("TEST: random distribution\n");
		for (i = 0; i < players; i++) {
		printf("Player %d\n", i + 1);
		numCurse = rand() % (curseCount + 1);
		printf("Curse: %d\n", numCurse);
		numEstate = rand() % (victoryCount + 1);
		printf("Estate: %d\n", numEstate);
		numDuchy = rand() % (victoryCount + 1);
		printf("Duchy: %d\n", numDuchy);
		numProvince = rand() % (victoryCount + 1);
		printf("Province: %d\n", numProvince);
		numGardens = rand() % (victoryCount + 1);
		printf("Gardens: %d\n", numGardens);
		numGreatHall = rand() % (victoryCount + 1);
		printf("Great Hall: %d\n", numGreatHall);

		for (j = 0; j < numCurse; j++) {
			k = rand() % 3;
			if (k == 0) {
				state.deck[i][state.deckCount[i]] = curse;
				state.deckCount[i]++;
			}
			else if (k == 1) {
				state.discard[i][state.discardCount[i]] = curse;
				state.discardCount[i]++;
			}
			else {
				state.hand[i][state.handCount[i]] = curse;
				state.handCount[i]++;
			}
		}

		for (j = 0; j < numEstate; j++) {
			k = rand() % 3;
			if (k == 0) {
				state.deck[i][state.deckCount[i]] = estate;
				state.deckCount[i]++;
			}
			else if (k == 1) {
				state.discard[i][state.discardCount[i]] = estate;
				state.discardCount[i]++;
			}
			else {
				state.hand[i][state.handCount[i]] = estate;
				state.handCount[i]++;
			}
		}

		for (j = 0; j < numDuchy; j++) {
			k = rand() % 3;
			if (k == 0) {
				state.deck[i][state.deckCount[i]] = duchy;
				state.deckCount[i]++;
			}
			else if (k == 1) {
				state.discard[i][state.discardCount[i]] = duchy;
				state.discardCount[i]++;
			}
			else {
				state.hand[i][state.handCount[i]] = duchy;
				state.handCount[i]++;
			}
		}

		for (j = 0; j < numProvince; j++) {
			k = rand() % 3;
			if (k == 0) {
				state.deck[i][state.deckCount[i]] = province;
				state.deckCount[i]++;
			}
			else if (k == 1) {
				state.discard[i][state.discardCount[i]] = province;
				state.discardCount[i]++;
			}
			else {
				state.hand[i][state.handCount[i]] = province;
				state.handCount[i]++;
			}
		}

		for (j = 0; j < numGardens; j++) {
			k = rand() % 3;
			if (k == 0) {
				state.deck[i][state.deckCount[i]] = gardens;
				state.deckCount[i]++;
			}
			else if (k == 1) {
				state.discard[i][state.discardCount[i]] = gardens;
				state.discardCount[i]++;
			}
			else {
				state.hand[i][state.handCount[i]] = gardens;
				state.handCount[i]++;
			}
		}

		for (j = 0; j < numGreatHall; j++) {
			k = rand() % 3;
			if (k == 0) {
				state.deck[i][state.deckCount[i]] = great_hall;
				state.deckCount[i]++;
			}
			else if (k == 1) {
				state.discard[i][state.discardCount[i]] = great_hall;
				state.discardCount[i]++;
			}
			else {
				state.hand[i][state.handCount[i]] = great_hall;
				state.handCount[i]++;
			}
		}
		

		
		int deck = state.deckCount[i] + state.handCount[i] + state.discardCount[i];
		printf("Total deck: %d\n", deck);
		int internalsum = internalPointsCalc(numCurse, numEstate, numDuchy, numProvince, numGardens, numGreatHall, deck);
		int score = scoreFor(i, &state);

		printf("Expected score: %d\n", internalsum);
		printf("Calculated score: %d\n", score);
		if (internalsum == score)
			printf("PASSED\n");
		else
			printf("FAILED\n");

	}	
	return 0;
}