]> git.localhorst.tv Git - l2e.git/commitdiff
moved attack type into its own class
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 7 Aug 2012 12:38:38 +0000 (14:38 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 7 Aug 2012 12:38:38 +0000 (14:38 +0200)
Debug/src/battle/subdir.mk
Release/src/battle/subdir.mk
src/battle/AttackChoice.cpp [new file with mode: 0644]
src/battle/AttackChoice.h [new file with mode: 0644]
src/battle/AttackTypeMenu.cpp
src/battle/AttackTypeMenu.h
src/battle/BattleState.h
src/battle/states/SelectAttackType.cpp
src/battle/states/SelectMoveAction.cpp

index d967ca2be744e327827160cf3326583b94979021..dd0f37f011b6a0673ee15bcc7740b7c2e8b56cfd 100644 (file)
@@ -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 \
index 2ae5c5935d56a92fd8e45714ff4dba24f6d607df..4ab87844e1063dfc62fa3dec9f19ebadac8ac2df 100644 (file)
@@ -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 (file)
index 0000000..c966b53
--- /dev/null
@@ -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 (file)
index 0000000..b11a81d
--- /dev/null
@@ -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_ */
index bee794f453a813e53355816a3c0ffa6d33cd36a0..2ec7a1f129b26bbe25eadf47232d014023fc8cdd 100644 (file)
@@ -23,11 +23,11 @@ void AttackTypeMenu::Render(SDL_Surface *screen, const geometry::Point<int> &pos
        Vector<int> ikariOffset(IconWidth(), 2 * IconHeight());
        Vector<int> 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);
 }
 
 }
index 26a9dd9d07089ea128fe566c884c01fd0d30d045..4b38dd3bd45d2ecf908fb0242df93d94e5a13123 100644 (file)
@@ -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<int> &position);
 
        int Width() const { return 3 * IconWidth(); }
@@ -42,7 +34,7 @@ public:
 
 private:
        const graphics::Sprite *icons;
-       Icon selected;
+       AttackChoice::Type selected;
 
 };
 
index a3c0879cedbbace7352a0ad547a090e9be8e41ae..73f3fbc01813c478870d6cb42ff7988b87872c9b 100644 (file)
@@ -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<int> CalculateScreenOffset(SDL_Surface *screen) const {
                return geometry::Vector<int>(
@@ -85,7 +87,6 @@ private:
        std::vector<Monster> monsters;
        std::vector<Hero> heroes;
        std::vector<HeroTag> heroTags;
-       int moveChoice;
        int activeHero;
 
 };
index 1d76b6c10894b4fa0dc0efa42ddbc4786fde43b2..c0548132b536c115d5cee98265ce4afd43856ace 100644 (file)
@@ -7,10 +7,13 @@
 
 #include "SelectAttackType.h"
 
+#include "../AttackChoice.h"
 #include "../BattleState.h"
 #include "../../app/Input.h"
 #include "../../geometry/operators.h"
 
+#include <stdexcept>
+
 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");
                }
        }
 }
index 4a19d48a00643e74f82b1d97a0616d8d9cc7d638..54f0f297661f2654ef49ffb82ed463b07ec57c98 100644 (file)
@@ -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