当前位置: 首页>>代码示例>>C++>>正文


C++ Castle类代码示例

本文整理汇总了C++中Castle的典型用法代码示例。如果您正苦于以下问题:C++ Castle类的具体用法?C++ Castle怎么用?C++ Castle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Castle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ApplyPlayWithStartingHero

void Kingdom::ApplyPlayWithStartingHero(void)
{
    if(isPlay() && castles.size())
    {
	// get first castle
	Castle* first = castles.GetFirstCastle();
	if(NULL == first) first = castles.front();

	// check manual set hero (castle position + point(0, 1))?
	const Point & cp = (first)->GetCenter();
	Heroes* hero = world.GetTiles(cp.x, cp.y + 1).GetHeroes();

    	// and move manual set hero to castle
	if(hero && hero->GetColor() == GetColor())
	{
		bool patrol = hero->Modes(Heroes::PATROL);
    		hero->SetFreeman(0);
    		hero->Recruit(*first);

		if(patrol)
		{
		    hero->SetModes(Heroes::PATROL);
		    hero->SetCenterPatrol(cp);
		}
	}
	else
	if(Settings::Get().GameStartWithHeroes())
	{
    	    Heroes* hero = world.GetFreemanHeroes(first->GetRace());
	    if(hero && AllowRecruitHero(false, 0)) hero->Recruit(*first);
	}
    }
}
开发者ID:infsega,项目名称:fheroes2-playbook,代码行数:33,代码来源:kingdom.cpp

示例2: CastleRedrawBuilding

void CastleRedrawBuilding(const Castle & castle, const Point & dst_pt, u32 build, u32 frame, int alpha)
{
    const Rect max = CastleGetMaxArea(castle, dst_pt);

    // correct build
    switch(build)
    {
	case DWELLING_MONSTER2:
	case DWELLING_MONSTER3:
	case DWELLING_MONSTER4:
	case DWELLING_MONSTER5:
	case DWELLING_MONSTER6: build = castle.GetActualDwelling(build); break;

	default: break;
    }

    const int icn = Castle::GetICNBuilding(build, castle.GetRace());
    u32 index = 0;

    // correct index (mage guild)
    switch(build)
    {
        case BUILD_MAGEGUILD1: index = 0; break;
        case BUILD_MAGEGUILD2: index = Race::NECR == castle.GetRace() ? 6 : 1; break;
        case BUILD_MAGEGUILD3: index = Race::NECR == castle.GetRace() ? 12 : 2; break;
        case BUILD_MAGEGUILD4: index = Race::NECR == castle.GetRace() ? 18 : 3; break;
        case BUILD_MAGEGUILD5: index = Race::NECR == castle.GetRace() ? 24 : 4; break;
        default: break;
    }

    if(icn != ICN::UNKNOWN)
    {
	// simple first sprite
	Sprite sprite1 = AGG::GetICN(icn, index);

	if(alpha)
	{
	    sprite1.SetSurface(sprite1.GetSurface());
	    sprite1.SetAlphaMod(alpha);
	    sprite1.Blit(dst_pt.x + sprite1.x(), dst_pt.y + sprite1.y());
	}
	else
	    CastleDialog::RedrawBuildingSpriteToArea(sprite1, dst_pt.x + sprite1.x(), dst_pt.y + sprite1.y(), max);

	// second anime sprite
	if(const u32 index2 = ICN::AnimationFrame(icn, index, frame))
	{
	    Sprite sprite2 = AGG::GetICN(icn, index2);

	    if(alpha)
	    {
		sprite2.SetSurface(sprite2.GetSurface());
		sprite2.SetAlphaMod(alpha);
		sprite2.Blit(dst_pt.x + sprite2.x(), dst_pt.y + sprite2.y());
	    }
	    else
	        CastleDialog::RedrawBuildingSpriteToArea(sprite2, dst_pt.x + sprite2.x(), dst_pt.y + sprite2.y(), max);
	}
    }
}
开发者ID:gerstrong,项目名称:fheroes2plus,代码行数:60,代码来源:castle_building.cpp

示例3: Unit

Battle::Tower::Tower(const Castle & castle, int twr) : Unit(Troop(Monster::ARCHER, 0), -1, false),
    type(twr), color(castle.GetColor()), bonus(0), valid(true)
{
    count += castle.CountBuildings();
    count += castle.GetLevelMageGuild() - 1;

    if(count > 20) count = 20;
    if(TWR_CENTER != type) count /= 2;
    if(count == 0) count = 1;
    bonus = castle.GetLevelMageGuild();

    SetModes(CAP_TOWER);
}
开发者ID:mastermind-,项目名称:free-heroes,代码行数:13,代码来源:battle_tower.cpp

示例4: arena

Battle2::Tower::Tower(const Castle & castle, u8 twr, Arena & a) : Army::Troop(Monster::ARCHER), arena(a), type(twr), valid(true)
{
    count += castle.CountBuildings();
    count += castle.GetLevelMageGuild() - 1;

    if(count > 20) count = 20;
    if(TWR_CENTER != type) count /= 2;
    if(count == 0) count = 1;

    BattleInit();
    Stats* b = GetBattleStats();
    b->SetModes(CAP_TOWER);
}
开发者ID:blchinezu,项目名称:EZX-Projects,代码行数:13,代码来源:battle_tower.cpp

示例5: ReceiveMessage

void GameApp::ReceiveMessage(Message* message)
{
	if (message->GetMessageName() == "MouseDown")
    {
    	Castle* castle = (Castle*)Actor::GetNamed("Castle");
    	TypedMessage<Vec2i> *m = (TypedMessage<Vec2i>*)message;
        Vec2i screenCoordinates = m->GetValue();
        Vector2 click = MathUtil::ScreenToWorld(screenCoordinates);
        if(tower != 3){
	        ActorSet background = theTagList.GetObjectsTagged("grass");
			ActorSet::iterator it = background.begin();
	        while(it != background.end()){
	        	Vector2 position = (*it)->GetPosition();
	        	Vector2 size = (*it)->GetSize();
	        	if ((click.X < position.X + size.X/2.0) && (click.X > position.X - size.X/2.0) && (click.Y < position.Y + size.Y/2.0) && (click.Y > position.Y - size.Y/2.0)){
	        		if(!(castle->buy_tower(tower))) return;
	        		if(tower == 1){
	        			StandartTower* new_tower = (StandartTower*)Actor::Create("standart_tower");
	        			new_tower->SetPosition(click);
	        			theWorld.Add(new_tower, 2);
	        		}
	        		if(tower == 2){
	        			MagicTower* new_tower = (MagicTower*)Actor::Create("magic_tower");
	        			new_tower->SetPosition(click);
	        			theWorld.Add(new_tower, 2);
	        		}
	        		break;
	        	}
	        	it++;
	        }
	    }
	    else{
	    	ActorSet background = theTagList.GetObjectsTagged("road");
			ActorSet::iterator it = background.begin();
	        while(it != background.end()){
	        	Vector2 position = (*it)->GetPosition();
	        	Vector2 size = (*it)->GetSize();
	        	if ((click.X < position.X + size.X/2.0) && (click.X > position.X - size.X/2.0) && (click.Y < position.Y + size.Y/2.0) && (click.Y > position.Y - size.Y/2.0)){
	        		if(!(castle->buy_tower(tower))) return;
	        		Trap* new_trap = (Trap*)Actor::Create("trap");
	        		new_trap->SetPosition(click);
	        		theWorld.Add(new_trap, 1);
	        		break;
	        	}
	        	it++;
	        }
	    }
        theSwitchboard.UnsubscribeFrom(this, "MouseDown");
    }
}
开发者ID:,项目名称:,代码行数:50,代码来源:

示例6: Init

    void Init(Castle* ptr)
    {
	castle = ptr;

	Clear();

	armyBarGuard = new ArmyBar(& castle->GetArmy(), true, false);
	armyBarGuard->SetBackground(41, 41, 0x3C);
	armyBarGuard->SetColRows(5, 1);
	armyBarGuard->SetHSpace(-1);

	CastleHeroes heroes = world.GetHeroes(*castle);

        if(heroes.Guest())
	{
	    armyBarGuest = new ArmyBar(& heroes.Guest()->GetArmy(), true, false);
	    armyBarGuest->SetBackground(41, 41, 0x3C);
	    armyBarGuest->SetColRows(5, 1);
	    armyBarGuest->SetHSpace(-1);
	}

	dwellingsBar = new DwellingsBar(*castle, 39, 52, 0x3C);
	dwellingsBar->SetColRows(6, 1);
	dwellingsBar->SetHSpace(2);
    }
开发者ID:mastermind-,项目名称:free-heroes,代码行数:25,代码来源:kingdom_overview.cpp

示例7: CastleRemove

void AI::CastleRemove(const Castle & castle)
{
    AIKingdom & ai = AIKingdoms::Get(castle.GetColor());

    if(ai.capital == &castle)
    {
        ai.capital->ResetModes(Castle::CAPITAL);
        ai.capital = NULL;
    }
}
开发者ID:mastermind-,项目名称:free-heroes,代码行数:10,代码来源:ai_simple.cpp

示例8: CastleRedrawTownName

void CastleRedrawTownName(const Castle & castle, const Point & dst)
{
    const Sprite & ramka = AGG::GetICN(ICN::TOWNNAME, 0);
    Point dst_pt(dst.x + 320 - ramka.w() / 2, dst.y + 248);
    ramka.Blit(dst_pt);

    Text text(castle.GetName(), Font::SMALL);
    dst_pt.x = dst.x + 320 - text.w() / 2;
    dst_pt.y = dst.y + 248;
    text.Blit(dst_pt);
}
开发者ID:gerstrong,项目名称:fheroes2plus,代码行数:11,代码来源:castle_building.cpp

示例9: HowManyRecruitMonster

u16 HowManyRecruitMonster(const Castle & castle, u32 dw, const Funds & add, Funds & res)
{
    const Monster ms(castle.GetRace(), castle.GetActualDwelling(dw));
    const Kingdom & kingdom = world.GetKingdom(castle.GetColor());

    if(! castle.GetArmy().CanJoinTroop(ms)) return 0;
                                                                                                                         
    u16 count = castle.GetDwellingLivedCount(dw);
    payment_t payment;

    while(count)
    {
        payment = ms.GetCost() * count;
        res = payment;
        payment += add;
        if(kingdom.AllowPayment(payment)) break;
        --count;
    }

    return count;
}
开发者ID:asimonov-im,项目名称:fheroes2,代码行数:21,代码来源:castle_well.cpp

示例10: Tower

std::string Battle::Tower::GetInfo(const Castle & cstl)
{
    const char* tmpl = _("The %{name} fires with the strength of %{count} Archers");
    const char* addn = _("each with a +%{attack} bonus to their attack skill.");

    std::vector<int> towers;
    std::string msg;

    if(cstl.isBuild(BUILD_CASTLE))
    {
	towers.push_back(TWR_CENTER);

	if(cstl.isBuild(BUILD_LEFTTURRET)) towers.push_back(TWR_LEFT);
	if(cstl.isBuild(BUILD_RIGHTTURRET)) towers.push_back(TWR_RIGHT);

	for(std::vector<int>::const_iterator
	    it = towers.begin(); it != towers.end(); ++it)
	{
    	    Tower twr = Tower(cstl, *it);

    	    msg.append(tmpl);
    	    StringReplace(msg, "%{name}", twr.GetName());
    	    StringReplace(msg, "%{count}", twr.GetCount());

	    if(twr.GetBonus())
	    {
		msg.append(", ");
		msg.append(addn);
    		StringReplace(msg, "%{attack}", twr.GetBonus());
	    }
	    else
		msg.append(".");

	    if((it + 1) != towers.end())
    		msg.append("\n \n");
	}
    }

    return msg;
}
开发者ID:mastermind-,项目名称:free-heroes,代码行数:40,代码来源:battle_tower.cpp

示例11: switch

RowSpells::RowSpells(const Point & pos, const Castle & castle, u8 lvl)
{
    const MageGuild & guild = castle.GetMageGuild();
    bool hide = castle.GetLevelMageGuild() < lvl;
    const Sprite & roll_show = AGG::GetICN(ICN::TOWNWIND, 0);
    const Sprite & roll_hide = AGG::GetICN(ICN::TOWNWIND, 1);
    const Sprite & roll = (hide ? roll_hide : roll_show);

    u8 count = 0;

    switch(lvl)
    {
	case 1:
	case 2: count = 3; break;
	case 3:
	case 4: count = 2; break;
	case 5: count = 1; break;
	default: break;
    }

    for(u8 ii = 0; ii < count; ++ii)
	coords.push_back(Rect(pos.x + coords.size() * (Settings::Get().QVGA() ? 72 : 110) - roll.w() / 2, pos.y, roll.w(), roll.h()));

    if(castle.HaveLibraryCapability())
    {
	if(! hide && castle.isLibraryBuild())
	    coords.push_back(Rect(pos.x + coords.size() * (Settings::Get().QVGA() ? 72 : 110) - roll_show.w() / 2, pos.y, roll_show.w(), roll_show.h()));
	else
	    coords.push_back(Rect(pos.x + coords.size() * (Settings::Get().QVGA() ? 72 : 110) - roll_hide.w() / 2, pos.y, roll_hide.w(), roll_hide.h()));
    }

    spells.reserve(6);
    spells = guild.GetSpells(castle.GetLevelMageGuild(), castle.isLibraryBuild(), lvl);
    spells.resize(coords.size(), Spell::NONE);
}
开发者ID:asimonov-im,项目名称:fheroes2,代码行数:35,代码来源:castle_mageguild.cpp

示例12: CastlePackOrdersBuildings

CastleDialog::CacheBuildings::CacheBuildings(const Castle & castle, const Point & top)
{
    std::vector<building_t> ordersBuildings;

    ordersBuildings.reserve(25);

    CastlePackOrdersBuildings(castle, ordersBuildings);

    for(std::vector<building_t>::const_iterator
        it = ordersBuildings.begin(); it != ordersBuildings.end(); ++it)
    {
        push_back(builds_t(*it, CastleGetCoordBuilding(castle.GetRace(), *it, top)));
    }
}
开发者ID:gerstrong,项目名称:fheroes2plus,代码行数:14,代码来源:castle_building.cpp

示例13: load_prefs

GameApp::GameApp()
{	
	load_prefs();
	theSound.SetSoundCallback(this, &GameManager::SoundEnded);
	screen = new AppScreen();
	sample = theSound.LoadSample("Resources/Sounds/click.ogg", false /*no stream*/);
	theWorld.NameLayer("background", 0);
	theWorld.NameLayer("objects", 1);
	theWorld.NameLayer("units", 2);
	theWorld.LoadLevel("level");
	BoundingBox bounds(Vector2(-20, -20), Vector2(20, 20));
	theSpatialGraph.CreateGraph(0.6f, bounds);
	Castle* castle = (Castle*)Actor::GetNamed("Castle");
	castle_health = new TextActor("Console", "Castle health: " + IntToString(castle->getHealth()), TXT_Center);
	castle_health->SetPosition(Vector2(-4.5f, 4.5f));
	theWorld.Add(castle_health);
	castle_cash = new TextActor("Console", "Castle cash: " + IntToString(castle->getCash()), TXT_Center);
	castle_cash->SetPosition(Vector2(-4.5f, 3.5f));
	theWorld.Add(castle_cash);
	std::thread interval(&GameApp::timer, this);
	interval.detach();
	_button = theUI.AddButton("Change tactics", Vec2i(90, 700), ButtonPress, true);
}
开发者ID:,项目名称:,代码行数:23,代码来源:

示例14: CastleRedrawBuildingExtended

void CastleRedrawBuildingExtended(const Castle & castle, const Point & dst_pt, u32 build, u32 frame)
{
    const Rect max = CastleGetMaxArea(castle, dst_pt);
    int icn = Castle::GetICNBuilding(build, castle.GetRace());

    // shipyard
    if(BUILD_SHIPYARD == build)
    {
	// boat
	if(castle.PresentBoat())
	{
	    const int icn2 = castle.GetICNBoat(castle.GetRace());

    	    const Sprite & sprite40 = AGG::GetICN(icn2, 0);
	    CastleDialog::RedrawBuildingSpriteToArea(sprite40, dst_pt.x + sprite40.x(), dst_pt.y + sprite40.y(), max);

    	    if(const u32 index2 = ICN::AnimationFrame(icn2, 0, frame))
	    {
		const Sprite & sprite41 = AGG::GetICN(icn2, index2);
		CastleDialog::RedrawBuildingSpriteToArea(sprite41, dst_pt.x + sprite41.x(), dst_pt.y + sprite41.y(), max);
	    }
	}
	else
	{
    	    if(const u32 index2 = ICN::AnimationFrame(icn, 0, frame))
	    {
		const Sprite & sprite3 = AGG::GetICN(icn, index2);
		CastleDialog::RedrawBuildingSpriteToArea(sprite3, dst_pt.x + sprite3.x(), dst_pt.y + sprite3.y(), max);
	    }
	}
    }
    else
    // sorc and anime wel2 or statue
    if(Race::SORC == castle.GetRace() && BUILD_WEL2 == build)
    {
	const int icn2 = castle.isBuild(BUILD_STATUE) ? ICN::TWNSEXT1 : icn;

    	const Sprite & sprite20 = AGG::GetICN(icn2, 0);
	CastleDialog::RedrawBuildingSpriteToArea(sprite20, dst_pt.x + sprite20.x(), dst_pt.y + sprite20.y(), max);

    	if(const u32 index2 = ICN::AnimationFrame(icn2, 0, frame))
	{
	    const Sprite & sprite21 = AGG::GetICN(icn2, index2);
	    CastleDialog::RedrawBuildingSpriteToArea(sprite21, dst_pt.x + sprite21.x(), dst_pt.y + sprite21.y(), max);
	}
    }
}
开发者ID:gerstrong,项目名称:fheroes2plus,代码行数:47,代码来源:castle_building.cpp

示例15: CastleGetMaxArea

Rect CastleGetMaxArea(const Castle & castle, const Point & top)
{
    Rect res(top, 0, 0);
    Sprite townbkg;

    switch(castle.GetRace())
    {
	case Race::KNGT: townbkg = AGG::GetICN(ICN::TOWNBKG0, 0); break;
	case Race::BARB: townbkg = AGG::GetICN(ICN::TOWNBKG1, 0); break;
	case Race::SORC: townbkg = AGG::GetICN(ICN::TOWNBKG2, 0); break;
	case Race::WRLK: townbkg = AGG::GetICN(ICN::TOWNBKG3, 0); break;
	case Race::WZRD: townbkg = AGG::GetICN(ICN::TOWNBKG4, 0); break;
	case Race::NECR: townbkg = AGG::GetICN(ICN::TOWNBKG5, 0); break;
	default: break;
    }

    if(townbkg.isValid())
    {
	res.w = townbkg.w();
	res.h = townbkg.h();
    }

    return res;
}
开发者ID:gerstrong,项目名称:fheroes2plus,代码行数:24,代码来源:castle_building.cpp


注:本文中的Castle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。