1 Replies - 267 Views - Last Post: 05 April 2013 - 08:28 PM Rate Topic: -----

#1 game06  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 74
  • Joined: 21-March 13

game bug. making less variables

Posted 05 April 2013 - 08:06 PM

i have two classes, enemy class and level class.

in level class i am changing the counter value.

note i set up my if statment so it will only goes in onces and never again. so if u reach lvl 2 than it will go in lvl2 if statment onces reset counter to 10. than wait when player reach lvl 3.

if(...)  //if lvl 1
{
   //change counter = 20
}
if(...) //if lvl 2
{
  //change counter = 10
}
if(...) //if lvl 3
{
   //change counter = 5
}



enemy.class
this method just makes enemy to shoot bullet. and counter is the time between every shoot. so enemy shoot a bullet than wait 20 int. when reach 0 than shoot again.

loop/method
counter--;
	if(counter <= 0 &&!shooting)
	{
		//create bullet object / add in arraylist
			
		shooting = true;
		counter = 20;       //reset
	}
	if(counter != 0)
	{
		shooting= false;
}


the problem is that i am hard coding value of counter=20 in emeny class.but i value of counter change depends on wha level player is on.

i was thinking of making counter1, counter2, counter3, in level class. and in enemy class i can use getter method to get the value and do i test.

the problem with this is i end up making variable for every lvls. is there way so i only use one counter. and dont rewrite code.

Is This A Good Question/Topic? 0
  • +

Replies To: game bug. making less variables

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10465
  • View blog
  • Posts: 38,785
  • Joined: 27-December 08

Re: game bug. making less variables

Posted 05 April 2013 - 08:28 PM

Based on the if statements you have provided, it seems that counter = 20 - ((level - 1) * 5).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1