Beispiel #1
0
void Enemy1::findDestination()
{
	if (prevTargetLocation != currentGoal || path.empty())
		path = (std::async(&Enemy1::getPath, this)).get();

	if (!path.empty()){
		destX = path.back().X + squareSize() / 2;
		destY = path.back().Y - squareSize() / 2 - mHigth + mHigth / 5;
		path.pop_back();
	}
}
bool DoubleDiagonalShoot::hasNext(int squareNumberWidth, int squareNumberHeight, int shipSize)
{
    switch (shipSize)
    {
    case 4:
        if(shootedSquares4->contains(makeId(squareNumberWidth, squareNumberHeight)))
            return true;
        break;
    case 3:
        if (shootedSquares3->contains(makeId(squareNumberWidth, squareNumberHeight)))
            return true;
        break;
    case 2:
        if(shootedSquares2->contains(makeId(squareNumberWidth, squareNumberHeight)))
            return true;
        break;
    }
    int size = squareSize(squareNumberWidth, squareNumberHeight, shipSize);
    int x = squareNumberWidth * shipSize;
    int y = squareNumberHeight * shipSize;
    for (int i = 0; i < size/2; i++)
    {
        id = y * 10 + x;
        if (enemyField->attackable(id))
            return false;
        x++;
        y++;
    }

    x = squareNumberWidth * shipSize;
    y = squareNumberHeight * shipSize;
    if (size < 3)
    {
        if (size != 1)
        {
            x++;
            y++;
        }
        id = y * 10 + x;
        if (enemyField->attackable(id))
            return false;

    }
    else
    {
        x = squareNumberWidth * shipSize + size - 1;
        y = squareNumberHeight * shipSize + size - 2;
        id = y * 10 + x;
        if (enemyField->attackable(id))
            return false;
        x--;
        y++;
        id = y * 10 + x;
        if (enemyField->attackable(id))
            return false;
    }
    int sqr = makeId(squareNumberWidth, squareNumberHeight);
    return true;

}
Beispiel #3
0
void
Game::start() {
    sf::Vector2f squareSize( 100.f, 100.f );

    Egn::Sprite::Ptr playerSprite = spriteFactory_
        ->makeRectSprite( "player_sprite", squareSize, sf::Color::Green );
    this->player_ = new Player( playerSprite, squareSize );
    this->player_->setPosition( sf::Vector2f( 100, 0 ) );
    engine_.registerEntity( this->player_ );

    Egn::Sprite::Ptr boxSprite = spriteFactory_
        ->makeRectSprite( "box_sprite", squareSize, sf::Color::Red );
    Egn::Entity * box = new Egn::Entity( boxSprite, squareSize );
    box->setPosition( sf::Vector2f( 500, 0 ) );
    box->setCanMove( true );
    engine_.registerEntity( box );

    entityFactory_->makeWorld();

    debugText_ = spriteFactory_->makeText( "Debug", 16 );
    Egn::Sprite::Ptr textSprite = spriteFactory_->makeSprite( "debug",
            std::dynamic_pointer_cast< sf::Drawable >( debugText_ ) );

    Egn::Entity * text = new Egn::Entity( textSprite );
    engine_.registerEntity( text );

    engine_.loop();
}
int DoubleDiagonalShoot::nextCell(int squareNumberWidth, int squareNumberHeight, int shipSize)
{
    int size = squareSize(squareNumberWidth, squareNumberHeight, shipSize);
    int x = squareNumberWidth * shipSize;
    int y = squareNumberHeight * shipSize;
    for (int i = 0; i < size/2; i++)
    {
        id = y * 10 + x;
        if (enemyField->attackable(id))
            return id;
        x++;
        y++;
    }
    x = squareNumberWidth * shipSize;
    y = squareNumberHeight * shipSize;
    if (size < 3)
    {
        if (size > 1)
        {
            x++;
            y++;
        }
        id = y * 10 + x;
        if (enemyField->attackable(id))
            return id;

    }
    else
    {
        x = squareNumberWidth * shipSize + size - 1;
        y = squareNumberHeight * shipSize + size - 2;
        id = y * 10 + x;
        if (enemyField->attackable(id))
            return id;
        x--;
        y++;
        id = y * 10 + x;
        if (enemyField->attackable(id))
            return id;
    }
    int sqr = makeId(squareNumberWidth, squareNumberHeight);
    switch (shipSize)
    {
    case 4:
        shootedSquares4->append(makeId(squareNumberWidth, squareNumberHeight));
        break;
    case 3:
        shootedSquares3->append(makeId(squareNumberWidth, squareNumberHeight));
        break;
    case 2:
        shootedSquares2->append(makeId(squareNumberWidth, squareNumberHeight));
        break;
    }
    return true;

}
bool DiagonalShoot::hasNext(int squareNumberWidth, int squareNumberHeight, int shipSize)
{
    int id = makeId(squareNumberWidth, squareNumberHeight);
    switch (shipSize)
    {
    case 4:
        if(shootedSquares4->contains(makeId(squareNumberWidth, squareNumberHeight)))
            return true;
        break;
    case 3:
        if (shootedSquares3->contains(makeId(squareNumberWidth, squareNumberHeight)))
            return true;
        break;
    case 2:
        if(shootedSquares2->contains(makeId(squareNumberWidth, squareNumberHeight)))
            return true;
        break;
    }
    int x = squareNumberWidth * shipSize;
    int y = squareNumberHeight * shipSize;
    int squaresize = squareSize(squareNumberWidth, squareNumberWidth, shipSize);
    for(int i = 0; i < squaresize; i++)
    {
        id = y * 10 + x;
        //cout << id;
        if (enemyField->attackable(id))
            return false;
        x++;
        y++;

    }
    switch (shipSize)
    {
    case 4:
        shootedSquares4->append(makeId(squareNumberWidth, squareNumberHeight));
        break;
    case 3:
        shootedSquares3->append(makeId(squareNumberWidth, squareNumberHeight));
        break;
    case 2:
        shootedSquares2->append(makeId(squareNumberWidth, squareNumberHeight));
        break;
    }
    return true;

}
int DoubleDiagonalShoot::twoSquare(int squareNumberWidth, int squareNumberHeight)
{
    int shipSize = 2;
    int x = squareNumberWidth * shipSize;
    int y = squareNumberHeight * shipSize;
    int squaresize = squareSize(squareNumberWidth, squareNumberWidth, shipSize);
    for(int i = 0; i < squaresize; i++)
    {
        id = y * 10 + x;
        //cout << id;
        if (enemyField->attackable(id))
            return id;
        x++;
        y++;

    }
}
int DiagonalShoot::nextCell(int squareNumberWidth, int squareNumberHeight, int shipSize)
{
    int x = squareNumberWidth * shipSize;
    int y = squareNumberHeight * shipSize;
    int d = -1;
    int squaresize = squareSize(squareNumberWidth, squareNumberWidth, shipSize);
    y += squaresize - 1;
    x += squaresize - 1;

    for(int i = 0; i < squaresize; i++)
    {
        id = y * 10 + x;
        //cout << id;
        if (enemyField->attackable(id))
            return id;
        x +=d;
        y +=d;

    }

}
bool DoubleDiagonalShoot::twoSquareShooted(int squareNumberWidth, int squareNumberHeight)
{
    int shipSize = 2;
    int id = makeId(squareNumberWidth, squareNumberHeight);
    if (shootedSquares2->contains(id))
    {
        return true;
    }
    int x = squareNumberWidth * shipSize;
    int y = squareNumberHeight * shipSize;
    int squaresize = squareSize(squareNumberWidth, squareNumberWidth, shipSize);
    for(int i = 0; i < squaresize; i++)
    {
        id = y * 10 + x;
        //cout << id;
        if (enemyField->attackable(id))
            return false;
        x++;
        y++;

    }
    shootedSquares2->append(makeId(squareNumberWidth, squareNumberHeight));
    return true;
}