From: Daniel Karbach Date: Tue, 7 Aug 2012 12:38:38 +0000 (+0200) Subject: moved attack type into its own class X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=4d0a650b178d81387caa36953ed06cc5d6c28213;p=l2e.git moved attack type into its own class --- diff --git a/Debug/src/battle/subdir.mk b/Debug/src/battle/subdir.mk index d967ca2..dd0f37f 100644 --- a/Debug/src/battle/subdir.mk +++ b/Debug/src/battle/subdir.mk @@ -4,6 +4,7 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ +../src/battle/AttackChoice.cpp \ ../src/battle/AttackTypeMenu.cpp \ ../src/battle/BattleState.cpp \ ../src/battle/Hero.cpp \ @@ -13,6 +14,7 @@ CPP_SRCS += \ ../src/battle/PartyLayout.cpp OBJS += \ +./src/battle/AttackChoice.o \ ./src/battle/AttackTypeMenu.o \ ./src/battle/BattleState.o \ ./src/battle/Hero.o \ @@ -22,6 +24,7 @@ OBJS += \ ./src/battle/PartyLayout.o CPP_DEPS += \ +./src/battle/AttackChoice.d \ ./src/battle/AttackTypeMenu.d \ ./src/battle/BattleState.d \ ./src/battle/Hero.d \ diff --git a/Release/src/battle/subdir.mk b/Release/src/battle/subdir.mk index 2ae5c59..4ab8784 100644 --- a/Release/src/battle/subdir.mk +++ b/Release/src/battle/subdir.mk @@ -4,6 +4,7 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ +../src/battle/AttackChoice.cpp \ ../src/battle/AttackTypeMenu.cpp \ ../src/battle/BattleState.cpp \ ../src/battle/Hero.cpp \ @@ -13,6 +14,7 @@ CPP_SRCS += \ ../src/battle/PartyLayout.cpp OBJS += \ +./src/battle/AttackChoice.o \ ./src/battle/AttackTypeMenu.o \ ./src/battle/BattleState.o \ ./src/battle/Hero.o \ @@ -22,6 +24,7 @@ OBJS += \ ./src/battle/PartyLayout.o CPP_DEPS += \ +./src/battle/AttackChoice.d \ ./src/battle/AttackTypeMenu.d \ ./src/battle/BattleState.d \ ./src/battle/Hero.d \ diff --git a/src/battle/AttackChoice.cpp b/src/battle/AttackChoice.cpp new file mode 100644 index 0000000..c966b53 --- /dev/null +++ b/src/battle/AttackChoice.cpp @@ -0,0 +1,12 @@ +/* + * AttackChoice.cpp + * + * Created on: Aug 7, 2012 + * Author: holy + */ + +#include "AttackChoice.h" + +namespace battle { + +} diff --git a/src/battle/AttackChoice.h b/src/battle/AttackChoice.h new file mode 100644 index 0000000..b11a81d --- /dev/null +++ b/src/battle/AttackChoice.h @@ -0,0 +1,40 @@ +/* + * AttackChoice.h + * + * Created on: Aug 7, 2012 + * Author: holy + */ + +#ifndef BATTLE_ATTACKCHOICE_H_ +#define BATTLE_ATTACKCHOICE_H_ + +namespace battle { + +class AttackChoice { + +public: + enum Type { + SWORD, + MAGIC, + DEFEND, + IKARI, + ITEM, + UNDECIDED + }; + +public: + AttackChoice() : type(UNDECIDED) { } + ~AttackChoice() { } + +public: + Type GetType() const { return type; } + void SetType(Type t) { type = t; } + +private: + Type type; + +}; + +} + +#endif /* BATTLE_ATTACKCHOICE_H_ */ diff --git a/src/battle/AttackTypeMenu.cpp b/src/battle/AttackTypeMenu.cpp index bee794f..2ec7a1f 100644 --- a/src/battle/AttackTypeMenu.cpp +++ b/src/battle/AttackTypeMenu.cpp @@ -23,11 +23,11 @@ void AttackTypeMenu::Render(SDL_Surface *screen, const geometry::Point &pos Vector ikariOffset(IconWidth(), 2 * IconHeight()); Vector itemOffset(0, IconHeight()); - icons->Draw(screen, position + swordOffset, SWORD, (selected == SWORD) ? 1 : 0); - icons->Draw(screen, position + magicOffset, MAGIC, (selected == MAGIC) ? 1 : 0); - icons->Draw(screen, position + defendOffset, DEFEND, (selected == DEFEND) ? 1 : 0); - icons->Draw(screen, position + ikariOffset, IKARI, (selected == IKARI) ? 1 : 0); - icons->Draw(screen, position + itemOffset, ITEM, (selected == ITEM) ? 1 : 0); + icons->Draw(screen, position + swordOffset, AttackChoice::SWORD, (selected == AttackChoice::SWORD) ? 1 : 0); + icons->Draw(screen, position + magicOffset, AttackChoice::MAGIC, (selected == AttackChoice::MAGIC) ? 1 : 0); + icons->Draw(screen, position + defendOffset, AttackChoice::DEFEND, (selected == AttackChoice::DEFEND) ? 1 : 0); + icons->Draw(screen, position + ikariOffset, AttackChoice::IKARI, (selected == AttackChoice::IKARI) ? 1 : 0); + icons->Draw(screen, position + itemOffset, AttackChoice::ITEM, (selected == AttackChoice::ITEM) ? 1 : 0); } } diff --git a/src/battle/AttackTypeMenu.h b/src/battle/AttackTypeMenu.h index 26a9dd9..4b38dd3 100644 --- a/src/battle/AttackTypeMenu.h +++ b/src/battle/AttackTypeMenu.h @@ -8,6 +8,7 @@ #ifndef BATTLE_ATTACKTYPEMENU_H_ #define BATTLE_ATTACKTYPEMENU_H_ +#include "AttackChoice.h" #include "../geometry/Point.h" #include "../graphics/Sprite.h" @@ -17,22 +18,13 @@ namespace battle { class AttackTypeMenu { -public: - enum Icon { - SWORD, - MAGIC, - DEFEND, - IKARI, - ITEM - }; - public: explicit AttackTypeMenu(const graphics::Sprite *icons) - : icons(icons), selected(SWORD) { } + : icons(icons), selected(AttackChoice::SWORD) { } public: - void Select(Icon i) { selected = i; } - Icon Selected() const { return selected; } + void Select(AttackChoice::Type t) { selected = t; } + AttackChoice::Type Selected() const { return selected; } void Render(SDL_Surface *screen, const geometry::Point &position); int Width() const { return 3 * IconWidth(); } @@ -42,7 +34,7 @@ public: private: const graphics::Sprite *icons; - Icon selected; + AttackChoice::Type selected; }; diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index a3c0879..73f3fbc 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -38,8 +38,7 @@ public: , heroesLayout(&heroesLayout) , attackTypeMenu(attackIcons) , moveMenu(moveIcons) - , moveChoice(-1) - , activeHero(0) { } + , activeHero(-1) { } public: void AddMonster(const Monster &); @@ -59,6 +58,9 @@ public: AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; } MoveMenu &GetMoveMenu() { return moveMenu; } + bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); } + void NextHero() { ++activeHero; } + public: geometry::Vector CalculateScreenOffset(SDL_Surface *screen) const { return geometry::Vector( @@ -85,7 +87,6 @@ private: std::vector monsters; std::vector heroes; std::vector heroTags; - int moveChoice; int activeHero; }; diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp index 1d76b6c..c054813 100644 --- a/src/battle/states/SelectAttackType.cpp +++ b/src/battle/states/SelectAttackType.cpp @@ -7,10 +7,13 @@ #include "SelectAttackType.h" +#include "../AttackChoice.h" #include "../BattleState.h" #include "../../app/Input.h" #include "../../geometry/operators.h" +#include + using app::Input; using geometry::Point; using geometry::Vector; @@ -33,34 +36,36 @@ void SelectAttackType::Resize(int width, int height) { void SelectAttackType::HandleInput(const Input &input) { if (input.IsDown(Input::PAD_UP)) { - battle->GetAttackTypeMenu().Select(AttackTypeMenu::MAGIC); + battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC); } else if (input.IsDown(Input::PAD_RIGHT)) { - battle->GetAttackTypeMenu().Select(AttackTypeMenu::DEFEND); + battle->GetAttackTypeMenu().Select(AttackChoice::DEFEND); } else if (input.IsDown(Input::PAD_DOWN)) { - battle->GetAttackTypeMenu().Select(AttackTypeMenu::IKARI); + battle->GetAttackTypeMenu().Select(AttackChoice::IKARI); } else if (input.IsDown(Input::PAD_LEFT)) { - battle->GetAttackTypeMenu().Select(AttackTypeMenu::ITEM); + battle->GetAttackTypeMenu().Select(AttackChoice::ITEM); } else { - battle->GetAttackTypeMenu().Select(AttackTypeMenu::SWORD); + battle->GetAttackTypeMenu().Select(AttackChoice::SWORD); } if (input.JustPressed(Input::ACTION_A)) { switch (battle->GetAttackTypeMenu().Selected()) { - case AttackTypeMenu::SWORD: + case AttackChoice::SWORD: // TODO: switch to next character break; - case AttackTypeMenu::MAGIC: + case AttackChoice::MAGIC: // TODO: switch to spell select break; - case AttackTypeMenu::DEFEND: + case AttackChoice::DEFEND: // TODO: switch to next character break; - case AttackTypeMenu::IKARI: + case AttackChoice::IKARI: // TODO: switch to ikari attack select break; - case AttackTypeMenu::ITEM: + case AttackChoice::ITEM: // TODO: switch to item select break; + default: + throw std::logic_error("selected invalid attack type"); } } } diff --git a/src/battle/states/SelectMoveAction.cpp b/src/battle/states/SelectMoveAction.cpp index 4a19d48..54f0f29 100644 --- a/src/battle/states/SelectMoveAction.cpp +++ b/src/battle/states/SelectMoveAction.cpp @@ -47,6 +47,7 @@ void SelectMoveAction::HandleInput(const app::Input &input) { switch (battle->GetMoveMenu().Selected()) { case MoveMenu::ATTACK: ctrl->ChangeState(new SelectAttackType(battle)); + battle->NextHero(); break; case MoveMenu::CHANGE: // TODO: switch to change state