Skip to content

Commit

Permalink
Implement hero as a card
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Shih committed Nov 23, 2016
1 parent cc2e88f commit 32f39ad
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dev/include/EntitiesManager/EntitiesManager-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ template <typename T>
CardRef EntitiesManager::PushBack(State::State & state, T&& card)
{
CardRef ref = CardRef(cards_.PushBack(std::forward<T>(card)));
this->GetMinionManipulator(ref).GetZoneChanger().Add(state);
this->GetGeneralManipulator(ref).GetZoneChanger().Add(state);
return ref;
}
2 changes: 2 additions & 0 deletions dev/include/Entity/Card.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace Entity
int GetCost() const { return data_.enchanted_states.cost; }
void SetCost(int new_cost) { data_.enchanted_states.cost = new_cost; }

int GetHP() const { return data_.enchanted_states.max_hp - data_.damaged; }

MutableEnchantmentAuxDataGetter GetMutableEnchantmentAuxDataGetter()
{
return MutableEnchantmentAuxDataGetter(data_);
Expand Down
1 change: 1 addition & 0 deletions dev/include/Entity/CardType.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Entity
{
enum CardType
{
kCardTypeHero,
kCardTypeMinion,
kCardTypeSpell,
kCardTypeWeapon,
Expand Down
6 changes: 4 additions & 2 deletions dev/include/FlowControl/Helpers/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ namespace FlowControl
public:
static Result CheckWinLoss(State::State & state)
{
bool first_died = state.players.Get(State::kPlayerFirst).state_.GetHP() < 0;
bool second_died = state.players.Get(State::kPlayerSecond).state_.GetHP() < 0;
const Entity::Card & first_hero = state.mgr.Get(state.players.Get(State::kPlayerFirst).hero_ref_);
bool first_died = first_hero.GetHP() < 0;
const Entity::Card & second_hero = state.mgr.Get(state.players.Get(State::kPlayerSecond).hero_ref_);
bool second_died = second_hero.GetHP() < 0;

if (first_died) {
if (second_died) return kResultDraw;
Expand Down
4 changes: 4 additions & 0 deletions dev/include/Manipulators/Helpers/ZoneChanger.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ namespace Manipulators
{
switch (card_.GetCardType())
{
case Entity::kCardTypeHero:
return ZoneChangerWithUnknownZone<Entity::kCardTypeHero>(mgr_, card_ref_, card_).ChangeTo<ChangeToZone>(state, player_identifier, pos);
case Entity::kCardTypeMinion:
return ZoneChangerWithUnknownZone<Entity::kCardTypeMinion>(mgr_, card_ref_, card_).ChangeTo<ChangeToZone>(state, player_identifier, pos);
case Entity::kCardTypeHeroPower:
Expand All @@ -197,6 +199,8 @@ namespace Manipulators
{
switch (card_.GetCardType())
{
case Entity::kCardTypeHero:
return ZoneChangerWithUnknownZone<Entity::kCardTypeHero>(mgr_, card_ref_, card_).Add(state);
case Entity::kCardTypeMinion:
return ZoneChangerWithUnknownZone<Entity::kCardTypeMinion>(mgr_, card_ref_, card_).Add(state);
case Entity::kCardTypeHeroPower:
Expand Down
5 changes: 2 additions & 3 deletions dev/include/State/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "State/Secrets.h"
#include "State/Weapon.h"
#include "State/PlayerResource.h"
#include "State/PlayerState.h"

namespace State
{
Expand All @@ -16,6 +15,8 @@ namespace State
public:
Player() : fatigue_damage_(0) {}

CardRef hero_ref_;

Deck deck_;
Hand hand_;
Minions minions_;
Expand All @@ -24,8 +25,6 @@ namespace State
Graveyard graveyard_;

PlayerResource resource_;
PlayerState state_;

int fatigue_damage_;
};
}
24 changes: 0 additions & 24 deletions dev/include/State/PlayerState.h

This file was deleted.

4 changes: 4 additions & 0 deletions dev/include/StaticEventManager/Events/AddToZone.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ namespace StaticEventManager

switch (TargetCardType)
{
case Entity::kCardTypeHero:
if (player.hero_ref_.IsValid()) throw std::exception("hero should be removed first");
player.hero_ref_ = card_ref;
return;
case Entity::kCardTypeMinion:
return player.minions_.GetLocationManipulator().Insert(state.mgr, card_ref);
case Entity::kCardTypeWeapon:
Expand Down

0 comments on commit 32f39ad

Please sign in to comment.