void Function::printBody() { // TODO: cleanup printBodyHeader(); g_exprGen.setVarStack(&localVars); g_currentTabCount++; coutLine("cout << \"Hello world!\" << '\\n';"); localScopes.push_back(Scope()); localVars.setScope(&localScopes.back()); for (unsigned i = 0; i < 10; i++) { SupportedType randType = getRandType(); coutLine(g_typeStrings[randType] + " " + localVars.newVar(randType) + " = " + getRandValue(randType) + ";"); } for (unsigned i = 0; i < 20; i++) { SupportedType randType = getRandType(); string arithmicExprStr = g_exprGen.genArithmeticExpr(randType); coutLine(g_typeStrings[randType] + " " + localVars.newVar(randType) + " = " + arithmicExprStr + ";"); } coutLine("return 0;"); g_currentTabCount--; printBodyFooter(); cleanupCurrScope(); }
void Items::generateItemNow( Vector2D pos, Vector2D vel ) { if ( pos.getX() < 10 ) pos.setX( 10 ); if ( pos.getX() > SCREEN_WIDTH-10 ) pos.setX( SCREEN_WIDTH-10 ); if ( pos.getY() < 100 && vel.getY() < 5 ) vel.setY( 5 ); int itemType; // 10 tries for a correct item for ( int i = 0; i < 10; i++ ) { itemType = getRandValue( ITEM_APPEAR_CHANCES, NR_ITEM_TYPES ); if ( ( racers->isShipTypeActive( LIGHT_FIGHTER ) && racers->isShipTypeActive( HEAVY_FIGHTER ) ) || ( racers->isShipTypeActive( LIGHT_FIGHTER ) && ( itemType == ITEM_PRIMARY_UPGRADE || itemType == ITEM_DUMBFIRE_DOUBLE || itemType == ITEM_KICK_ASS_ROCKET || itemType == ITEM_HELLFIRE || itemType == ITEM_MACHINE_GUN || itemType == ITEM_HEALTH || itemType == ITEM_HEATSEEKER || itemType == ITEM_NUKE || itemType == ITEM_ENERGY_BEAM ) ) || ( racers->isShipTypeActive( HEAVY_FIGHTER ) && ( itemType == ITEM_PRIMARY_UPGRADE || itemType == ITEM_DUMBFIRE_DOUBLE || itemType == ITEM_KICK_ASS_ROCKET || itemType == ITEM_HEALTH || itemType == ITEM_HEATSEEKER || itemType == ITEM_NUKE || itemType == ITEM_DEFLECTOR || itemType == ITEM_LASER ) ) ) { Item *item = new Item( pos, vel, (ItemTypes)itemType ); addItem( item ); break; } } }