コード例 #1
0
void
Controller::Moderator::onTilePlaced
(
	boost::signals2::connection const & inConnection,
	TilePlacement const & inTilePlacement
)
{
	inConnection.disconnect();
	if ( isValidPlacement( *mNextTile, inTilePlacement ) )
	{
		Model::TileOnBoard const tileToPlace( *mNextTile, inTilePlacement.rotation );
		mBoard.placeValidTile( tileToPlace, inTilePlacement.location );

		requestPiecePlacement( inTilePlacement.location );
	}
	else
	{
		// TODO: give player a warning.
		requestTilePlacement();
	}
}
コード例 #2
0
void
Controller::Moderator::onPiecePlaced
(
	boost::signals2::connection const & inConnection,
	Utils::Location const & inLocation,
	boost::optional< Model::PlacedPiece > const & inPiecePlacement
)
{
	inConnection.disconnect();
	if ( inPiecePlacement )
	{
		if ( mCurrentPlayer->hasPiece( inPiecePlacement->getType() ) && isValidPlacement( inLocation, *inPiecePlacement ) )
		{
			mCurrentPlayer->takePiece( inPiecePlacement->getType() );
			mBoard.placeValidPiece( *inPiecePlacement, inLocation );
		}
		else
		{
			// TODO: give player a warning.
			// TODO: should player get a second chance?
		}
	}
	endTurn( inLocation );
}
コード例 #3
0
ファイル: Building.cpp プロジェクト: jimmyxgong/final-project
/* creates a building with a base, center and a top 
 * the rules:
 * Bot can be type of {BLOCK, PILLARS_V PYRAMID} 1/10 of y_dim
 * Mid can be type of {BLOCK, PILLAR_V, PYRAMID, PILLAR_H} up to 4 middle piece spanning 7/10 of y_dim,
 *  (mid can have multiple mid pieces)
 * Top can be type of {BLOCK, ELLIPSE, PYRAMID} 2/10 of y_dim 
 *  (top may inrease the current x_dim and z_dim to create a lip of a roof)
 *
 * no PILLARS_V can immediately succede PILLARS_V
 * no PILLARS_V can immediately succede PILLARS_H
 * no BLOCK of shape CUBE can immediately succede PYRAMID of shape CYLINDER
 * no BLOCK of shape CUBE can immediately succede BLOCK of shape CYLINDER
 * no PILLAR_H can immediately succede PYRAMID
 * no PILLAR_H can immediately succede PILLAR_V
 * no PYRAMID of shape CUBE can immediately succede PYRAMID of shape CYLINDER
 * no PYRAMID of shape CUBE can immediately succede BLOCK of shape CYLINDER
 * no ELLIPSE can immediately succede PILLARS_H
 *
 * pieces of type of {BLOCK, PILLARS_V, PILLARS_H, PYRAMID} can be shape {CYLINDER, CUBE}
 * 
 *
 *
 * notes:
 * buildings are always built from the bottom up.
 * each Create call builds on top of the next pieces (or on the sides of with PILLARS_H)
 *  and modifies the dimensions of the building
 */
transform_group Building::CreateRandomBuilding() {
    transform_group building = share<Transform>();

    int bot_type = rand()%3;
    int bot_shape = rand()%2;
    float bot_height = y_dim/10;
    
    transform_group bot;
    if (bot_type == 0){ //BLOCK
        bot = CreateBlock(bot_height, randomMaterial(), bot_shape);
    }
    else if (bot_type == 1){ //PILLARS_V
        bot = CreatePillarsVertical(bot_height, randomMaterial(), bot_shape);

    }
    else if (bot_type == 2){ //PYRAMID
        int steps = (int)(bot_height/pyramid_step_height); //height to steps conversion, # of steps rounded down
        bot = CreatePyramid(steps, randomMaterial(), bot_shape);
    }
    building->addChild(bot);

    
    int mid_types[] = {BLOCK, PILLARS_V, PYRAMID, PILLARS_H,PILLARS_H,PILLARS_H,PILLARS_H};
    for (int i = 0, loop = rand()%6+4, remaining_mid_space = 7;
         i<loop && remaining_mid_space > 0;
         i++) {
        int mid_type = rand()%7;
        int mid_shape = rand()%2;
        if (!isValidPlacement(mid_types[mid_type], mid_types[mid_shape])) {
            --i; //repeat the iteration
            continue;
        }
        int how_many_tenths = rand() % remaining_mid_space + 1;;
        int mid_height = y_dim/10*how_many_tenths;
        if (i == loop-1)
            mid_height = y_dim/10*remaining_mid_space;
        
        transform_group mid;
        if (mid_type == 0){ //BLOCK
            mid = CreateBlock(mid_height, randomMaterial(), mid_shape);
        }
        else if (mid_type == 1){ //PILLARS_V
            mid = CreatePillarsVertical(mid_height, randomMaterial(), mid_shape);
            
        }
        else if (mid_type == 2){ //PYRAMID
            int steps = (int)(mid_height/pyramid_step_height); //height to steps conversion, # of steps rounded down
            if (mid_height-steps*pyramid_step_height < 1) {
                --i; //repeat the iteration
                continue;
            }
            mid = CreatePyramid(steps, randomMaterial(), mid_shape);
        }
        else if (mid_type >= 3){ //PILLARS_H
            if (i == loop-1) {
                --i; //repeat the iteration
                continue;
            }
            remaining_mid_space += how_many_tenths; // add the height chang b/c no height change
            mid = CreatePillarsHorizontal(randomMaterial(), mid_shape);
        }
        
        remaining_mid_space -= how_many_tenths;
        building->addChild(mid);
    }
    
    
    int top_type, top_shape;
    int top_types[4] = {BLOCK, ELLIPSE, PYRAMID};

    float top_height = 2*y_dim/10;
    do {
        top_type = rand()%3;
        top_shape = rand()%2;
        if (top_types[top_type] == ELLIPSE && prev_block_height < y_dim/20) // prevents thin domes
            continue;
    } while (!(isValidPlacement(top_types[top_type], top_shape) && top_types[top_type] != ELLIPSE) && // if valid non elipse
             !(isValidPlacement(top_types[top_type], top_shape) && top_types[top_type] == ELLIPSE && prev_block_height > y_dim/20)); // if valid elipse with heigh >= 1/20th
    
    int lip = rand()%2;
    if (lip && top_type != 1){
        current_x_dim += pyramid_step_height;
        current_z_dim += pyramid_step_height;
    }
    
    transform_group top;
    if (top_type == 0){ //BLOCK
        top = CreateBlock(top_height, randomMaterial(), top_type);
    }
    else if (top_type == 1){ //ELLIPSE
        top = CreateDome(randomMaterial());
        
    }
    else if (top_type == 2){ //PYRAMID
        int steps = (int)(top_height/pyramid_step_height); //height to steps conversion, # of steps rounded down
        top = CreatePyramid(steps, randomMaterial(), top_type);
    }
    building->addChild(top);
    
    return building;
}