@@ -6,21 +6,21 @@ using namespace AttackAndDefend;
66CastleObject::CastleObject ()
77 : StaticObject()
88 , maxHealth_(0 .f)
9- , armor_(0 .f)
109 , maxArmor_(0 .f)
1110{
12- InitLabel_ ();
11+ InitLabels_ ();
1312 SetHealth (maxHealth_);
13+ SetArmor (0 .f );
1414}
1515
1616CastleObject::CastleObject (float maxHealth, std::string const & fileName)
1717 : StaticObject(MARGIN_SIZE, GROUND_HEIGHT, fileName)
1818 , maxHealth_(maxHealth)
19- , armor_(0 .f)
2019 , maxArmor_(2 .f * maxHealth)
2120{
22- InitLabel_ ();
21+ InitLabels_ ();
2322 SetHealth (maxHealth_);
23+ SetArmor (0 .f );
2424}
2525
2626void CastleObject::Update (Game* const scene)
@@ -47,59 +47,77 @@ void CastleObject::SetHealth(float health)
4747 health_ = health;
4848 char buf[10 ];
4949 _itoa_s (int (health_), buf, 10 );
50- label_ ->setString (buf);
50+ healthLabel_ ->setString (buf);
5151}
5252
5353void CastleObject::SetArmor (float armor)
5454{
5555 armor_ = armor;
56+ char buf[10 ];
57+ _itoa_s (int (armor_), buf, 10 );
58+ armorLabel_->setString (buf);
5659}
5760
58- float CastleObject::GetHealth ()
61+ float CastleObject::GetHealth () const
5962{
6063 return health_;
6164}
6265
63- float CastleObject::GetMaxHealth ()
66+ float CastleObject::GetMaxHealth () const
6467{
6568 return maxHealth_;
6669}
6770
68- float CastleObject::GetArmor ()
71+ float CastleObject::GetArmor () const
6972{
7073 return armor_;
7174}
7275
73- float CastleObject::GetMaxArmor ()
76+ float CastleObject::GetMaxArmor () const
7477{
7578 return maxArmor_;
7679}
7780
78- cocos2d::CCLabelTTF * AttackAndDefend::CastleObject::GetLabel ()
81+ cocos2d::CCLabelTTF * AttackAndDefend::CastleObject::GetHealthLabel () const
82+ {
83+ return healthLabel_;
84+ }
85+
86+ cocos2d::CCLabelTTF * AttackAndDefend::CastleObject::GetArmorLabel () const
87+ {
88+ return armorLabel_;
89+ }
90+
91+ size_t AttackAndDefend::CastleObject::GetCost () const
7992{
80- return label_ ;
93+ return 0 ;
8194}
8295
8396void AttackAndDefend::CastleObject::onPositionUpdate_ ()
8497{
8598 GameObject::onPositionUpdate_ ();
86- UpdateLabelPosition ();
99+ UpdateLabelsPosition ();
87100}
88101
89- void AttackAndDefend::CastleObject::InitLabel_ ()
102+ void AttackAndDefend::CastleObject::InitLabels_ ()
90103{
91- label_ = cocos2d::CCLabelTTF::create (" " , " Helvetica" , 30 , cocos2d::Size (GetW (), 60 ));
92- UpdateLabelPosition ();
104+ healthLabel_ = cocos2d::CCLabelTTF::create (" " , " Helvetica" , 30 , cocos2d::Size (GetW (), 30 ));
105+ armorLabel_ = cocos2d::CCLabelTTF::create (" " , " Helvetica" , 30 , cocos2d::Size (GetW (), 30 ));
106+ UpdateLabelsPosition ();
93107}
94108
95- void AttackAndDefend::CastleObject::UpdateLabelPosition ()
109+ void AttackAndDefend::CastleObject::UpdateLabelsPosition ()
96110{
97111 if (isRightAlignment_) {
98- label_->setPosition (frameWidth_ - MARGIN_SIZE, GROUND_HEIGHT + GetH () + MARGIN_SIZE);
99- label_->setAnchorPoint (cocos2d::Vec2 (1 , 0 ));
112+ healthLabel_->setPosition (frameWidth_ - MARGIN_SIZE, GROUND_HEIGHT + GetH () + MARGIN_SIZE);
113+ healthLabel_->setAnchorPoint (cocos2d::Vec2 (1 , 0 ));
114+ armorLabel_->setPosition (frameWidth_ - MARGIN_SIZE, GROUND_HEIGHT + GetH () + MARGIN_SIZE + 40 );
115+ armorLabel_->setAnchorPoint (cocos2d::Vec2 (1 , 0 ));
100116 }
101117 else {
102- label_->setPosition (MARGIN_SIZE, GROUND_HEIGHT + GetH () + MARGIN_SIZE);
103- label_->setAnchorPoint (cocos2d::Vec2 (0 , 0 ));
118+ healthLabel_->setPosition (MARGIN_SIZE, GROUND_HEIGHT + GetH () + MARGIN_SIZE);
119+ healthLabel_->setAnchorPoint (cocos2d::Vec2 (0 , 0 ));
120+ armorLabel_->setPosition (MARGIN_SIZE, GROUND_HEIGHT + GetH () + MARGIN_SIZE + 40 );
121+ armorLabel_->setAnchorPoint (cocos2d::Vec2 (0 , 0 ));
104122 }
105123}
0 commit comments