some small fixes

This commit is contained in:
Thomas R 2021-12-31 18:55:02 +01:00
parent 3d9c50bf6e
commit 99f08864f0
No known key found for this signature in database
GPG Key ID: E538821A6CDFDAD7
6 changed files with 36 additions and 16 deletions

View File

@ -5,21 +5,21 @@ players:
speed: 1
user1:
color: red
keys:
left: 4
right: 6
shoot: 5
user2:
color: blue
keys:
left: q
right: d
shoot: s
user2:
color: blue
keys:
left: 4
right: 6
shoot: 5
# Enemies config
invaders:
size: 4
size: 15
speed: 2
distance: 10 # distance in pixels between invaders

6
headers/errors.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef SPACE_ERRORS_H
#define SPACE_ERRORS_H
#endif

View File

@ -6,10 +6,9 @@ public:
ConfigData collectedData;
void parseFile(const string& fname);
void readConfig();
void dumpInternalValues();
private:
map<string, string> internalValues;
string& getString(const configKey& key);
char getChar(const configKey& key);
int getInt(const configKey& key);
@ -17,6 +16,12 @@ private:
};
void ConfigBuilder::dumpInternalValues(){
for(const auto& ite : internalValues){
cerr << ite.first << " -> " << ite.second << endl;
}
}
void trimSpaces(string& str){
str.erase(0, str.find_first_not_of(' '));
}
@ -36,7 +41,6 @@ void ConfigBuilder::parseFile(const string& fname) {
unsigned currentIndent = 0;
while (line[currentIndent] == ' ')++currentIndent;
match = line.find(':');
if (match == string::npos)throw runtime_error("Invalid line : " + line);
string key = line.substr(0, match);
@ -150,8 +154,13 @@ bool Game::reloadConfig() {
builder.readConfig();
}catch(runtime_error& e){
if(parsed)cerr << "An error occured while reading the configuration :" << endl;
else cerr << "An error occured while parsind the configuration :" << endl;
else cerr << "An error occured while parsing the configuration :" << endl;
cerr << e.what() << endl;
if(parsed){
cerr << "Parsed keys :" << endl;
builder.dumpInternalValues();
}
cerr << "(The old configuration was kept in memory)" << endl;
return false;
}
confData = builder.collectedData;

View File

@ -40,7 +40,12 @@ PlayMode Game::initialMenuHandler(){
case 0:{
return PlayMode::SINGLE;
}
// potential options...
case 1:{
return PlayMode::TWO_LOCAL;
}
case 2:{
return PlayMode::TWO_TCPIP;
}
}
return PlayMode::EXIT;
}
@ -64,7 +69,7 @@ bool Game::invadersTouchPlayer(){
/**
* Plays the game, and returns once the game is finished
*
* @return WinValue::PLAYERS if the players won, WinValue::INVADERS is the invaders won, WinValue::NOBODY else (also in case of error)
* @return @WinValue::PLAYERS if the players won, @WinValue::INVADERS is the invaders won, WinValue::NOBODY else (also in case of error)
*/
WinValue Game::playGame(){ // returns when game is finished
// INIT

View File

@ -42,7 +42,7 @@ bool Game::manageInvaders(){
if(end + confData.invadersSpeed < pm.getScreenWidth()){
basePos.setX(basePos.getX() + confData.invadersSpeed);
}else{
basePos.setY(basePos.getY() + confData.invadersSize);
basePos.setY(basePos.getY() + confData.invadersSize + confData.invadersDistance);
direction = !direction;
return true;
}
@ -50,7 +50,7 @@ bool Game::manageInvaders(){
if(basePos.getX() >= confData.invadersSpeed){
basePos.setX(basePos.getX() - confData.invadersSpeed);
}else{
basePos.setY(basePos.getY() + confData.invadersSize);
basePos.setY(basePos.getY() + confData.invadersSize + confData.invadersDistance);
direction = !direction;
return true;
}

View File

@ -51,7 +51,7 @@ void PixelManager::dessinerSprite(const nsGraphics::Vec2D& baseVector, const std
}
unsigned PixelManager::showInitialMenu(){
return 0;
return 1;
}
unsigned PixelManager::showDeathMenu() {