implemented add-resource command

This commit is contained in:
devZoGok
2023-09-30 16:27:39 +03:00
parent 92168151ce
commit d62c5105cd
4 changed files with 67 additions and 1 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES})
set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp)
set(UTIL util.cpp binds.h)
set(CONTROLLERS unitFrameController.cpp cameraController.cpp)
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp)
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp)
set(CORE gameManager.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS})
set(PROJECTILES projectile.cpp)
set(FX explosion.cpp)
+44
View File
@@ -0,0 +1,44 @@
#include "addResourceCommand.h"
#include "map.h"
#include "player.h"
namespace battleship{
void AddResourceCommand::validate(){
if(arguments.size() != 3)
return;
playerId = atoi(arguments[0].c_str());
if(playerId != 0 && playerId != 1)
return;
resourceId = atoi(arguments[1].c_str());
if(!(0 <= resourceId && resourceId <= 2))
return;
resourceAmmount = atoi(arguments[2].c_str());
}
void AddResourceCommand::addResource(){
Player *player = Map::getSingleton()->getPlayer(playerId);
switch(resourceId){
case 0:
player->addRefineds(resourceAmmount);
break;
case 1:
player->addWealth(resourceAmmount);
break;
case 2:
player->addResearch(resourceAmmount);
break;
}
}
void AddResourceCommand::execute(){
AbstractCommand::handle();
validate();
addResource();
}
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef ADD_RESOURCE_COMMAND_H
#define ADD_RESOURCE_COMMAND_H
#include "abstractCommand.h"
namespace battleship{
class AddResourceCommand : public AbstractCommand{
public:
AddResourceCommand(std::string argsStr) : AbstractCommand(argsStr){}
void execute();
private:
void validate();
void addResource();
int playerId, resourceId, resourceAmmount;
};
}
#endif
+3
View File
@@ -1,5 +1,6 @@
#include "console.h"
#include "addUnitCommand.h"
#include "addResourceCommand.h"
using namespace std;
@@ -15,5 +16,7 @@ namespace battleship{
if(cmdName == "add-unit")
AddUnitCommand(argsStr).execute();
else if(cmdName == "add-resource")
AddResourceCommand(argsStr).execute();
}
}