mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-02 18:21:12 +00:00
@@ -130,7 +130,10 @@ namespace BBM {
|
||||
std::ofstream playerFile(player);
|
||||
std::ofstream bonusFile(bonus);
|
||||
auto &ret = scene->view<TagComponent<Timer>, TimerComponent>();
|
||||
_block << "timer: " << ret.front().get<TimerComponent>().ringIn.count();
|
||||
if (ret.size())
|
||||
_block << "timer: " << ret.front().get<TimerComponent>().ringIn.count();
|
||||
else
|
||||
_block << "timer: " << std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::minutes(3)).count();
|
||||
|
||||
_player << "players:";
|
||||
_bonus << "bonuses:";
|
||||
@@ -240,16 +243,16 @@ namespace BBM {
|
||||
MapGenerator::MapBlock map;
|
||||
int size = -1;
|
||||
|
||||
if (!Utils::tryParseInteger(node.getProperty("width"), size)) {
|
||||
if (!Utils::tryParse(node.getProperty("width"), size)) {
|
||||
throw ParserError("width property must be an int");
|
||||
}
|
||||
Runner::mapWidth = size;
|
||||
if (!Utils::tryParseInteger(node.getProperty("height"), size)) {
|
||||
if (!Utils::tryParse(node.getProperty("height"), size)) {
|
||||
throw ParserError("width property must be an int");
|
||||
}
|
||||
Runner::mapHeight = size;
|
||||
long timer = 0;
|
||||
if (!Utils::tryParseLong(node.getProperty("timer"), timer)) {
|
||||
std::chrono::nanoseconds::rep timer = 0;
|
||||
if (!Utils::tryParse(node.getProperty("timer"), timer)) {
|
||||
throw ParserError("timer property must be a long");
|
||||
}
|
||||
Runner::timerDelay = std::chrono::nanoseconds(timer);
|
||||
@@ -310,7 +313,7 @@ namespace BBM {
|
||||
auto pos = Utils::splitStr(subStr, ',');
|
||||
if (pos.size() != 3)
|
||||
throw (ParserError("Error parsing position."));
|
||||
if (!Utils::tryParseFloat(pos[0], x) || !Utils::tryParseFloat(pos[1], y) || !Utils::tryParseFloat(pos[2], z))
|
||||
if (!Utils::tryParse(pos[0], x) || !Utils::tryParse(pos[1], y) || !Utils::tryParse(pos[2], z))
|
||||
throw (ParserError("Error parsing position."));
|
||||
} catch (const std::out_of_range &err) {
|
||||
throw (ParserError("Error parsing position."));
|
||||
@@ -324,7 +327,7 @@ namespace BBM {
|
||||
|
||||
if (str.find('-') != std::string::npos)
|
||||
throw (ParserError("Couldn't parse max bomb."));
|
||||
if (!Utils::tryParseInteger(str, maxBomb))
|
||||
if (!Utils::tryParse(str, maxBomb))
|
||||
throw (ParserError("Couldn't parse max bomb."));
|
||||
return (maxBomb);
|
||||
}
|
||||
@@ -335,7 +338,7 @@ namespace BBM {
|
||||
|
||||
if (line.find('-') != std::string::npos)
|
||||
throw (ParserError("Couldn't parse explosion radius."));
|
||||
if (!Utils::tryParseInteger(line, explosionRadius))
|
||||
if (!Utils::tryParse(line, explosionRadius))
|
||||
throw (ParserError("Couldn't parse explosion radius."));
|
||||
return (explosionRadius);
|
||||
}
|
||||
@@ -346,7 +349,7 @@ namespace BBM {
|
||||
|
||||
if (line.find('-') != std::string::npos)
|
||||
throw (ParserError("Couldn't parse speed."));
|
||||
if (!Utils::tryParseFloat(line, speed))
|
||||
if (!Utils::tryParse(line, speed))
|
||||
throw (ParserError("Couldn't parse speed."));
|
||||
return (speed);
|
||||
}
|
||||
@@ -356,7 +359,7 @@ namespace BBM {
|
||||
if (blockType.find('-') != std::string::npos)
|
||||
throw (ParserError("Couldn't parse block type."));
|
||||
int block = 0;
|
||||
if (!Utils::tryParseInteger(blockType, block))
|
||||
if (!Utils::tryParse(blockType, block))
|
||||
throw (ParserError("Couldn't parse block type."));
|
||||
return (static_cast<MapGenerator::BlockType>(block));
|
||||
}
|
||||
@@ -366,7 +369,7 @@ namespace BBM {
|
||||
if (bonusType.find('-') != std::string::npos)
|
||||
throw (ParserError("Couldn't parse bonus type."));
|
||||
int bonus = 0;
|
||||
if (!Utils::tryParseInteger(bonusType, bonus))
|
||||
if (!Utils::tryParse(bonusType, bonus))
|
||||
throw (ParserError("Couldn't parse bonus type."));
|
||||
return (static_cast<Bonus::BonusType>(bonus));
|
||||
}
|
||||
|
||||
@@ -60,22 +60,6 @@ namespace BBM
|
||||
return static_cast<int>(numberOfMatches);
|
||||
}
|
||||
|
||||
bool Utils::tryParseInteger(const std::string &s, int &i)
|
||||
{
|
||||
std::istringstream iss(s);
|
||||
|
||||
iss >> std::noskipws >> i;
|
||||
return iss.eof() && !iss.fail();
|
||||
}
|
||||
|
||||
bool Utils::tryParseFloat(const std::string &s, float &f)
|
||||
{
|
||||
std::istringstream iss(s);
|
||||
|
||||
iss >> std::noskipws >> f;
|
||||
return iss.eof() && !iss.fail();
|
||||
}
|
||||
|
||||
std::vector<std::string> Utils::splitStr(const std::string &str, char delim)
|
||||
{
|
||||
std::vector<std::string> strings;
|
||||
@@ -90,13 +74,4 @@ namespace BBM
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
bool Utils::tryParseLong(const std::string &s, long &l)
|
||||
{
|
||||
std::istringstream iss(s);
|
||||
|
||||
iss >> std::noskipws >> l;
|
||||
return iss.eof() && !iss.fail();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,13 +30,14 @@ namespace BBM
|
||||
static int findFrequency(const std::string &s, const std::string &pattern);
|
||||
|
||||
//! @brief return true if parsing has been successful result ill be in i
|
||||
static bool tryParseInteger(const std::string &s, int &i);
|
||||
template<typename T>
|
||||
static bool tryParse(const std::string &s, T &f)
|
||||
{
|
||||
std::istringstream iss(s);
|
||||
|
||||
//! @brief return true if parsing has been successful result ill be in f
|
||||
static bool tryParseFloat(const std::string &s, float &f);
|
||||
|
||||
//! @brief return true if parsing has been successful result ill be in l
|
||||
static bool tryParseLong(const std::string &s, long &l);
|
||||
iss >> std::noskipws >> f;
|
||||
return iss.eof() && !iss.fail();
|
||||
}
|
||||
|
||||
//! @brief split a string with a delim char
|
||||
static std::vector<std::string> splitStr(const std::string &str, char delim);
|
||||
|
||||
Reference in New Issue
Block a user