3 * @brief
\83Q
\81[
\83\80\83G
\83\93\83W
\83\93\82Ì
\8eÀ
\91\95
12 #include "GameEngine.h"
17 GameEngine::GameEngine()
19 gameWorld = new GameWorld();
20 gameSurface = new GameSurfaceSDL(gameWorld);
21 gameLogger = new GameLogger();
23 gameSurface->SetField(gameWorld->GetField(0));
24 gameSurface->SetSideStatusCreature(gameWorld->GetCreature(0));
25 this->gameLogger->PutLog("GameEngine
\8aJ
\8en");
26 Direction::Initialize();
29 PLAY_EXIT_CODE GameEngine::PlayLoop(void)
31 GAME_COMMAND commandID;
32 PLAY_EXIT_CODE code = PLAY_EXIT_NONE;
33 gameSurface->Redraw();
35 while(code == PLAY_EXIT_NONE)
37 commandID = gameSurface->GetCommand();
38 code = DoGameCommand(commandID);
41 return PLAY_EXIT_QUIT;
44 PLAY_EXIT_CODE GameEngine::DoGameCommand(GAME_COMMAND command)
46 Creature *playerPtr = gameWorld->GetPlayerCreature();
50 case GAME_COMMAND_VIEW_PLAYER_STATUS:
51 gameSurface->ViewCreatureStatus(gameWorld->GetCreature(0));
53 case GAME_COMMAND_REDRAW:
54 gameSurface->Redraw();
56 case GAME_COMMAND_DEBUG_XML_SAVE:
58 gameSurface->SystemMessage("XML
\82É
\95Û
\91¶
\82µ
\82Ü
\82µ
\82½
\81B");
60 case GAME_COMMAND_DEBUG_XML_LOAD:
61 gameSurface->Redraw();
63 gameSurface->SystemMessage("XML
\82©
\82ç
\8cÄ
\82Ñ
\8fo
\82µ
\82Ü
\82µ
\82½
\81B");
65 case GAME_COMMAND_EXIT:
66 return PLAY_EXIT_QUIT;
68 case GAME_COMMAND_NORTH:
69 this->WalkCreature(playerPtr, DIRECTION_NORTH);
71 case GAME_COMMAND_NORTH_EAST:
72 this->WalkCreature(playerPtr, DIRECTION_NORTH_EAST);
74 case GAME_COMMAND_EAST:
75 this->WalkCreature(playerPtr, DIRECTION_EAST);
77 case GAME_COMMAND_SOUTH_EAST:
78 this->WalkCreature(playerPtr, DIRECTION_SOUTH_EAST);
80 case GAME_COMMAND_SOUTH:
81 this->WalkCreature(playerPtr, DIRECTION_SOUTH);
83 case GAME_COMMAND_SOUTH_WEST:
84 this->WalkCreature(playerPtr, DIRECTION_SOUTH_WEST);
86 case GAME_COMMAND_WEST:
87 this->WalkCreature(playerPtr, DIRECTION_WEST);
89 case GAME_COMMAND_NORTH_WEST:
90 this->WalkCreature(playerPtr, DIRECTION_NORTH_WEST);
93 return PLAY_EXIT_NONE;
96 bool GameEngine::WalkCreature(Creature *creaturePtr, DIRECTION direction)
98 Coordinates nextPoint = creaturePtr->GetPosition() + Direction::DirectionVector[direction];
99 Floor *floor = gameWorld->GetFloorFromPosition(creaturePtr->GetFieldID(), &nextPoint);
102 //! @note
\88Ú
\93®
\90æ
\82É
\95Ê
\82Ì
\83N
\83\8a\81[
\83`
\83\83\81[
\82ª
\91¶
\8dÝ
\82·
\82é
\82È
\82ç
\82Î FALSE
103 targetPtr = gameWorld->GetCreatureFromPosition(creaturePtr->GetFieldID(), &nextPoint);
106 this->gameLogger->CreaturesCombated(creaturePtr->GetName(), targetPtr->GetName());
107 return this->CombatCreatures(creaturePtr, targetPtr);
110 //! @note
\88Ú
\93®
\90æ
\82ª
\95Ç
\92n
\8c`
\82È
\82ç
\82Î FALSE
111 if(!floor || floor->IsWall())
113 this->gameSurface->GameMessage("
\8ds
\82
\8eè
\82ð
\91j
\82Ü
\82ê
\82Ä
\82¢
\82é
\81B");
117 creaturePtr->Walk(this->gameLogger, direction);
118 this->gameSurface->FocusField(creaturePtr->GetPosition());
122 bool GameEngine::CombatCreatures(Creature *attackerPtr, Creature *targetPtr)
124 attackerPtr->CalcHP(-Dice::Cast(1, 6));
125 targetPtr->CalcHP(-Dice::Cast(1, 6));
126 this->gameSurface->UpdateSideCreatureStatus(gameWorld->GetPlayerCreature());