some small fixes
This commit is contained in:
parent
3d9c50bf6e
commit
99f08864f0
14
config.yml
14
config.yml
@ -5,21 +5,21 @@ players:
|
|||||||
speed: 1
|
speed: 1
|
||||||
user1:
|
user1:
|
||||||
color: red
|
color: red
|
||||||
keys:
|
|
||||||
left: 4
|
|
||||||
right: 6
|
|
||||||
shoot: 5
|
|
||||||
user2:
|
|
||||||
color: blue
|
|
||||||
keys:
|
keys:
|
||||||
left: q
|
left: q
|
||||||
right: d
|
right: d
|
||||||
shoot: s
|
shoot: s
|
||||||
|
user2:
|
||||||
|
color: blue
|
||||||
|
keys:
|
||||||
|
left: 4
|
||||||
|
right: 6
|
||||||
|
shoot: 5
|
||||||
|
|
||||||
|
|
||||||
# Enemies config
|
# Enemies config
|
||||||
invaders:
|
invaders:
|
||||||
size: 4
|
size: 15
|
||||||
speed: 2
|
speed: 2
|
||||||
distance: 10 # distance in pixels between invaders
|
distance: 10 # distance in pixels between invaders
|
||||||
|
|
||||||
|
6
headers/errors.h
Normal file
6
headers/errors.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef SPACE_ERRORS_H
|
||||||
|
#define SPACE_ERRORS_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -6,10 +6,9 @@ public:
|
|||||||
ConfigData collectedData;
|
ConfigData collectedData;
|
||||||
void parseFile(const string& fname);
|
void parseFile(const string& fname);
|
||||||
void readConfig();
|
void readConfig();
|
||||||
|
void dumpInternalValues();
|
||||||
private:
|
private:
|
||||||
map<string, string> internalValues;
|
map<string, string> internalValues;
|
||||||
|
|
||||||
string& getString(const configKey& key);
|
string& getString(const configKey& key);
|
||||||
char getChar(const configKey& key);
|
char getChar(const configKey& key);
|
||||||
int getInt(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){
|
void trimSpaces(string& str){
|
||||||
str.erase(0, str.find_first_not_of(' '));
|
str.erase(0, str.find_first_not_of(' '));
|
||||||
}
|
}
|
||||||
@ -36,7 +41,6 @@ void ConfigBuilder::parseFile(const string& fname) {
|
|||||||
unsigned currentIndent = 0;
|
unsigned currentIndent = 0;
|
||||||
while (line[currentIndent] == ' ')++currentIndent;
|
while (line[currentIndent] == ' ')++currentIndent;
|
||||||
|
|
||||||
|
|
||||||
match = line.find(':');
|
match = line.find(':');
|
||||||
if (match == string::npos)throw runtime_error("Invalid line : " + line);
|
if (match == string::npos)throw runtime_error("Invalid line : " + line);
|
||||||
string key = line.substr(0, match);
|
string key = line.substr(0, match);
|
||||||
@ -150,8 +154,13 @@ bool Game::reloadConfig() {
|
|||||||
builder.readConfig();
|
builder.readConfig();
|
||||||
}catch(runtime_error& e){
|
}catch(runtime_error& e){
|
||||||
if(parsed)cerr << "An error occured while reading the configuration :" << endl;
|
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;
|
cerr << e.what() << endl;
|
||||||
|
if(parsed){
|
||||||
|
cerr << "Parsed keys :" << endl;
|
||||||
|
builder.dumpInternalValues();
|
||||||
|
}
|
||||||
|
cerr << "(The old configuration was kept in memory)" << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
confData = builder.collectedData;
|
confData = builder.collectedData;
|
||||||
|
@ -40,7 +40,12 @@ PlayMode Game::initialMenuHandler(){
|
|||||||
case 0:{
|
case 0:{
|
||||||
return PlayMode::SINGLE;
|
return PlayMode::SINGLE;
|
||||||
}
|
}
|
||||||
// potential options...
|
case 1:{
|
||||||
|
return PlayMode::TWO_LOCAL;
|
||||||
|
}
|
||||||
|
case 2:{
|
||||||
|
return PlayMode::TWO_TCPIP;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return PlayMode::EXIT;
|
return PlayMode::EXIT;
|
||||||
}
|
}
|
||||||
@ -64,7 +69,7 @@ bool Game::invadersTouchPlayer(){
|
|||||||
/**
|
/**
|
||||||
* Plays the game, and returns once the game is finished
|
* 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
|
WinValue Game::playGame(){ // returns when game is finished
|
||||||
// INIT
|
// INIT
|
||||||
|
@ -42,7 +42,7 @@ bool Game::manageInvaders(){
|
|||||||
if(end + confData.invadersSpeed < pm.getScreenWidth()){
|
if(end + confData.invadersSpeed < pm.getScreenWidth()){
|
||||||
basePos.setX(basePos.getX() + confData.invadersSpeed);
|
basePos.setX(basePos.getX() + confData.invadersSpeed);
|
||||||
}else{
|
}else{
|
||||||
basePos.setY(basePos.getY() + confData.invadersSize);
|
basePos.setY(basePos.getY() + confData.invadersSize + confData.invadersDistance);
|
||||||
direction = !direction;
|
direction = !direction;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ bool Game::manageInvaders(){
|
|||||||
if(basePos.getX() >= confData.invadersSpeed){
|
if(basePos.getX() >= confData.invadersSpeed){
|
||||||
basePos.setX(basePos.getX() - confData.invadersSpeed);
|
basePos.setX(basePos.getX() - confData.invadersSpeed);
|
||||||
}else{
|
}else{
|
||||||
basePos.setY(basePos.getY() + confData.invadersSize);
|
basePos.setY(basePos.getY() + confData.invadersSize + confData.invadersDistance);
|
||||||
direction = !direction;
|
direction = !direction;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ void PixelManager::dessinerSprite(const nsGraphics::Vec2D& baseVector, const std
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned PixelManager::showInitialMenu(){
|
unsigned PixelManager::showInitialMenu(){
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned PixelManager::showDeathMenu() {
|
unsigned PixelManager::showDeathMenu() {
|
||||||
|
Loading…
Reference in New Issue
Block a user