Browse Source

Make enemy_num a local variable in invader's main

ENEMY_NUM is no longer needed as a global variable. Instead, add a local
variable, enemy_num, in invader's main and pass it as an argument to the
functions that require it. Also remove the variable ENEMY_NUM from
bossrush, where it is not needed.
Matteo Zeccoli Marazzini 3 years ago
parent
commit
e0e2f5326c
3 changed files with 6 additions and 10 deletions
  1. 0 2
      bossrush.cpp
  2. 0 1
      definitions.hpp
  3. 6 7
      invaders.cpp

+ 0 - 2
bossrush.cpp

@@ -31,8 +31,6 @@ using std::endl;
 using std::min;
 using std::max;
 
-int ENEMY_NUM=1;	// This variable isn't used, but we have to define it since it is decleared in definitions.hpp"
-
 int main(int argc,char** argv)
 {
 

+ 0 - 1
definitions.hpp

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

+ 6 - 7
invaders.cpp

@@ -19,8 +19,6 @@ using std::cout;
 using std::endl; 
 using std::min;
 
-int ENEMY_NUM=1;
-
 int main(int argc,char** argv)
 {
 	if(argc>1){
@@ -61,6 +59,7 @@ int main(int argc,char** argv)
 	//PARAMETERS/UTILITIES
 	double shootrate;				  	//probability of an enemy shooting a bomb 
 	double poweruprate;					//probability of a powerup being dropped
+	int enemy_num;						//number of enemies in the current match
 	int command;						//keyboard input
 	int score=0;					   	//score: gain +100 when an enemy is destroyed and +50 when a bomb is destroyed
 	int level=1;						//difficulty level
@@ -107,8 +106,8 @@ int main(int argc,char** argv)
 	WALLS_NUM=2;
 	
 	level = choose_level(commands);     	// get desired level
-	setup_level(level, shootrate, poweruprate, refresh_time, boss1, ENEMY_NUM, commands);     	// set game parameters and boss
-	load_enemies(enemies,ENEMY_NUM);
+	setup_level(level, shootrate, poweruprate, refresh_time, boss1, enemy_num, commands);     	// set game parameters and boss
+	load_enemies(enemies,enemy_num);
 	player1.set_commands(commands);
 	erase();
 	
@@ -192,7 +191,7 @@ int main(int argc,char** argv)
 			{
 				//mvaddch(it->y,it->x,' ');
 				it->next_pos();                                        //evaluate new positions
-				if(it->alive && (double)rand()/RAND_MAX<(shootrate*ENEMY_NUM/n_enemies)){     //try a bomb-dropping
+				if(it->alive && (double)rand()/RAND_MAX<(shootrate*enemy_num/n_enemies)){     //try a bomb-dropping
 						//if(sound) shoot_sound = pthread_create(&thread[1],NULL,penshoot_sound,NULL);
 						it->shoot(bombs);
 				}
@@ -280,8 +279,8 @@ int main(int argc,char** argv)
 					refresh();
 					if(choice=='n')
 						level = choose_level(commands);     	// get desired level
-					setup_level(level, shootrate, poweruprate, refresh_time, boss1, ENEMY_NUM, commands);     	// set game parameters and boss
-					load_enemies(enemies,ENEMY_NUM);
+					setup_level(level, shootrate, poweruprate, 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();
 					refresh();