Browse Source

Split choose_level() in two functions

choose_level() had two purposes: allow the user to choose the level and
setup thoings for the match. I split it in two functions, one for each
purpose, with the first one (choose_level) returning the chosen level
anc the second one (setup_level) taking it as an argument.
Matteo Zeccoli Marazzini 4 years ago
parent
commit
607f7eb2ad
3 changed files with 14 additions and 6 deletions
  1. 5 2
      functions.cpp
  2. 3 1
      functions.hpp
  3. 6 3
      invaders.cpp

+ 5 - 2
functions.cpp

@@ -222,7 +222,7 @@ void print_info(){
 }
 
 
-void choose_level(double& shootr, int& refresh_t, boss& boss1, int& level, int& enemy_num, int* commands)
+int choose_level(int* commands)
 {
 	std::string phrase;
 	phrase=choose_phrase();
@@ -283,8 +283,11 @@ void choose_level(double& shootr, int& refresh_t, boss& boss1, int& level, int&
 	}while(!(input=='1' || input=='2' || input=='3' || input=='4'));
 	
 	create_folder(0);
-	level = input - '0';
+	return input - '0';
+}
 
+void setup_level(int level, double& shootr, int& refresh_t, boss& boss1, int& enemy_num, int* commands)
+{
 	switch(level)        //setting game parameters
 	{
 		case 1:

+ 3 - 1
functions.hpp

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

+ 6 - 3
invaders.cpp

@@ -97,7 +97,8 @@ int main(int argc,char** argv)
 	
 	WALLS_NUM=2;
 	
-	choose_level(shootrate, refresh_time, boss1, level, ENEMY_NUM, commands);     	// set game parameters and boss
+	level = choose_level(commands);     	// get desired level
+	setup_level(level, shootrate, refresh_time, boss1, ENEMY_NUM, commands);     	// set game parameters and boss
 	load_enemies(enemies,ENEMY_NUM);
 	player1.set_commands(commands);
 	erase();
@@ -261,7 +262,8 @@ int main(int argc,char** argv)
 				score=0;
 				erase();
 				refresh();
-				choose_level(shootrate, refresh_time, boss1, level, ENEMY_NUM, commands);     	// set game parameters and boss
+				level = choose_level(commands);     	// get desired level
+				setup_level(level, shootrate, refresh_time, boss1, ENEMY_NUM, commands);     	// set game parameters and boss
 				load_enemies(enemies,ENEMY_NUM);
 				reset(player1, enemies, boss1, bullets, bombs, walls, powerups,rockets, level,chflag); // reset box, player, enemy and deletes all bullets and bombs
 				erase();
@@ -292,7 +294,8 @@ int main(int argc,char** argv)
 				score=0;
 				erase();
 				refresh();
-				choose_level(shootrate, refresh_time, boss1, level, ENEMY_NUM, commands);     	// set game parameters and boss
+				level = choose_level(commands);     	// get desired level
+				setup_level(level, shootrate, refresh_time, boss1, ENEMY_NUM, commands);     	// set game parameters and boss
 				load_enemies(enemies,ENEMY_NUM);
 				reset(player1, enemies, boss1, bullets, bombs, walls, powerups,rockets,level,chflag);       // reset box, player, enemy and delete all bullets and bombs
 				erase();