3 * @brief
\83Q
\81[
\83\80\83G
\83\93\83W
\83\93\82Ì
\8eÀ
\91\95
12 #include "GameEngine.h"
14 #include "HaveGameTime.h"
16 #include "GameCampaign.h"
17 #include "GameLogger.h"
21 GameEngine::GameEngine()
23 gameWorld = new GameWorld();
24 gameSurface = new GameSurfaceSDL(gameWorld);
25 gameLogger = new GameLogger();
27 gameSurface->SetField(gameWorld->GetField(0));
28 gameSurface->SetSideStatusCreature(gameWorld->GetCreature(0));
29 this->gameLogger->PutLog("GameEngine
\8aJ
\8en");
30 Direction::Initialize();
33 PLAY_EXIT_CODE GameEngine::PlayLoop(void)
35 GAME_COMMAND commandID;
36 PLAY_EXIT_CODE code = PLAY_EXIT_NONE;
38 gameSurface->Redraw(gameWorld->GetPlayerCreature());
40 while(code == PLAY_EXIT_NONE)
42 this->gameSurface->UpdateTimeStatus(this->gameWorld->GetGameTime());
43 //actionIt = this->toNextProcess();
44 commandID = gameSurface->GetCommand(gameWorld->GetPlayerCreature());
45 code = DoGameCommand(commandID);
46 ProcessDeadCreatures();
47 if(!gameWorld->GetPlayerCreature()->second->IsAlive())
49 code = PLAY_EXIT_DEAD;
50 gameSurface->SystemMessage("
\82 \82È
\82½
\82Í
\8e\80\82É
\82Ü
\82µ
\82½
\81B");
54 return PLAY_EXIT_QUIT;
57 PLAY_EXIT_CODE GameEngine::DoGameCommand(GAME_COMMAND command)
59 CREATURE_IT playerIt = gameWorld->GetPlayerCreature();
63 case GAME_COMMAND_VIEW_PLAYER_STATUS:
64 gameSurface->ViewCreatureStatus(gameWorld->GetPlayerCreature()->second.get());
66 case GAME_COMMAND_REDRAW:
67 gameSurface->Redraw(playerIt);
69 case GAME_COMMAND_DEBUG_XML_SAVE:
71 gameSurface->SystemMessage("XML
\82É
\95Û
\91¶
\82µ
\82Ü
\82µ
\82½
\81B");
73 case GAME_COMMAND_DEBUG_XML_LOAD:
74 gameSurface->Redraw(playerIt);
76 gameSurface->SystemMessage("XML
\82©
\82ç
\8cÄ
\82Ñ
\8fo
\82µ
\82Ü
\82µ
\82½
\81B");
78 case GAME_COMMAND_EXIT:
79 return PLAY_EXIT_QUIT;
81 case GAME_COMMAND_NORTH:
82 this->WalkCreature(playerIt, DIRECTION_NORTH);
84 case GAME_COMMAND_NORTH_EAST:
85 this->WalkCreature(playerIt, DIRECTION_NORTH_EAST);
87 case GAME_COMMAND_EAST:
88 this->WalkCreature(playerIt, DIRECTION_EAST);
90 case GAME_COMMAND_SOUTH_EAST:
91 this->WalkCreature(playerIt, DIRECTION_SOUTH_EAST);
93 case GAME_COMMAND_SOUTH:
94 this->WalkCreature(playerIt, DIRECTION_SOUTH);
96 case GAME_COMMAND_SOUTH_WEST:
97 this->WalkCreature(playerIt, DIRECTION_SOUTH_WEST);
99 case GAME_COMMAND_WEST:
100 this->WalkCreature(playerIt, DIRECTION_WEST);
102 case GAME_COMMAND_NORTH_WEST:
103 this->WalkCreature(playerIt, DIRECTION_NORTH_WEST);
106 return PLAY_EXIT_NONE;
109 bool GameEngine::WalkCreature(CREATURE_IT creatureIt, DIRECTION direction)
111 return this->WalkCreature(creatureIt->second.get(), direction);
114 bool GameEngine::WalkCreature(Creature *creaturePtr, DIRECTION direction)
116 Coordinates nextPoint = creaturePtr->GetPosition() + Direction::DirectionVector[direction];
117 Floor *floorPtr = gameWorld->GetFloorFromPosition(creaturePtr->GetFieldID(), &nextPoint);
120 //! @note
\88Ú
\93®
\90æ
\82É
\95Ê
\82Ì
\83N
\83\8a\81[
\83`
\83\83\81[
\82ª
\91¶
\8dÝ
\82·
\82é
\82È
\82ç
\82Î
\94\92\95º
\8f\88\97\9d\82É
\88Ú
\8ds
\82µ
\82Ä FALSE
121 targetPtr = gameWorld->GetCreatureFromPosition(creaturePtr->GetFieldID(), &nextPoint);
124 this->gameLogger->CreaturesCombated(creaturePtr->GetName(), targetPtr->GetName());
125 return this->CombatCreatures(creaturePtr, targetPtr);
128 if(!creaturePtr->CanEnterPosition(floorPtr))
130 this->gameSurface->GameMessage("
\8ds
\82
\8eè
\82ð
\91j
\82Ü
\82ê
\82Ä
\82¢
\82é
\81B");
134 creaturePtr->Walk(this->gameLogger, direction);
135 this->gameSurface->FocusField(creaturePtr->GetPosition());
136 creaturePtr->UpdateFieldLore(gameWorld->GetField(creaturePtr->GetFieldID()));
137 this->gameSurface->GameMessage("");
141 bool GameEngine::CombatCreatures(Creature *attackerPtr, Creature *targetPtr)
143 attackerPtr->Melee(targetPtr);
144 this->gameSurface->UpdateSideCreatureStatus(gameWorld->GetPlayerCreature()->second.get());
148 int GameEngine::ProcessDeadCreatures()
151 CREATURE_IT creatureIt, creatureItCurrent;
152 CREATURE_LIST *creatureList = gameWorld->GetCreatureList();
154 creatureIt = creatureList->begin();
156 while(creatureIt != creatureList->end())
158 creatureItCurrent = creatureIt;
160 if(!creatureItCurrent->second->IsAlive())
162 //!< @note
\83v
\83\8c\83C
\83\84\81[
\82Ì
\8e\80\96S
\82È
\82ç
\82Î
\95Ê
\93r
\8f\88\97\9d\82·
\82é
\82Ì
\82Å
\83X
\83L
\83b
\83v
\81A
\82³
\82à
\82È
\82
\82Î
\83N
\83\8a\81[
\83`
\83\83\81[
\82Ì
\8fÁ
\96Å
\81B
163 if(gameWorld->GetPlayerCreature() != creatureItCurrent)
165 gameSurface->GameMessage(creatureItCurrent->second->GetName() + "
\82Í
\8e\80\82ñ
\82¾
\81B");
166 creatureList->erase(creatureItCurrent);
175 ACTION_IT GameEngine::toNextProcess(void)
177 return this->gameWorld->GetActionList()->begin()++;