Browse Source

Make ENEMY_NUM a proper global variable

Since ENEMY_NUM is a global variable, I decleared it as extern in
definitions.hpp, and defined it in invaders.cpp.
I also removed made choose_level() a void function, since it is not
useful to return a global variable (which can be accessed directly by the
caller).
Matteo Zeccoli Marazzini 4 years ago
parent
commit
5673e18f32
4 changed files with 10 additions and 11 deletions
  1. 1 1
      definitions.hpp
  2. 5 8
      functions.cpp
  3. 1 1
      functions.hpp
  4. 3 1
      invaders.cpp

+ 1 - 1
definitions.hpp

@@ -79,7 +79,7 @@
 #define backcyan "\033[46m"
 #define backgreen "\033[1;42m" 
 
-static int ENEMY_NUM=1;
+extern int ENEMY_NUM;
 static int WALLS_NUM;
 
 extern std::mutex m_player;

+ 5 - 8
functions.cpp

@@ -222,7 +222,7 @@ void print_info(){
 }
 
 
-int choose_level(double& shootr, int& refresh_t, boss& boss1, char& level,int* commands)	//returns ENEMY_NUM
+void choose_level(double& shootr, int& refresh_t, boss& boss1, char& level,int* commands)
 {
 	std::string phrase;
 	phrase=choose_phrase();
@@ -297,7 +297,7 @@ int choose_level(double& shootr, int& refresh_t, boss& boss1, char& level,int* c
 			bossname=bossname+RECORD_DIR+BOSS_FILE1+".dat";
 			boss1.loadpicture(bossname.c_str());
 			ENEMY_NUM=30;
-			return ENEMY_NUM;
+			break;
 		}
 		case 2:
 		{
@@ -309,7 +309,7 @@ int choose_level(double& shootr, int& refresh_t, boss& boss1, char& level,int* c
 			bossname=bossname+RECORD_DIR+BOSS_FILE2+".dat";
 			boss1.loadpicture(bossname.c_str());
 			ENEMY_NUM=40;
-			return ENEMY_NUM;
+			break;
 		}
 		case 3:
 		{
@@ -321,7 +321,7 @@ int choose_level(double& shootr, int& refresh_t, boss& boss1, char& level,int* c
 			bossname=bossname+RECORD_DIR+BOSS_FILE3+".dat";
 			boss1.loadpicture(bossname.c_str());
 			ENEMY_NUM=45;
-			return ENEMY_NUM;
+			break;
 		}
 		case 4:
 		{
@@ -333,12 +333,9 @@ int choose_level(double& shootr, int& refresh_t, boss& boss1, char& level,int* c
 			bossname=bossname+RECORD_DIR+BOSS_FILE4+".dat";
 			boss1.loadpicture(bossname.c_str());
 			ENEMY_NUM=50;
-			return ENEMY_NUM;
+			break;
 		}
 	}
-
-	return 0;
-	
 }
 
 void change_commands(int* commands){

+ 1 - 1
functions.hpp

@@ -49,7 +49,7 @@ void print_info();
 
 void print_scores();
 
-int choose_level(double& shootr, int& refresh_t, boss &boss1, char& level,int* commands);
+void choose_level(double& shootr, int& refresh_t, boss &boss1, char& level,int* commands);
 
 void change_commands(int* commands);
 

+ 3 - 1
invaders.cpp

@@ -11,6 +11,8 @@ using std::cout;
 using std::endl; 
 using std::min;
 
+int ENEMY_NUM=1;
+
 int main(int argc,char** argv)
 {
 	if(argc>1){
@@ -95,7 +97,7 @@ int main(int argc,char** argv)
 	
 	WALLS_NUM=2;
 	
-	ENEMY_NUM=choose_level(shootrate, refresh_time, boss1, level, commands);     	//choose difficulty level and set game parameters and boss
+	choose_level(shootrate, refresh_time, boss1, level, commands);     	//choose difficulty level and set game parameters and boss
 	player1.set_commands(commands);
 	erase();