I see a lot that we could help you with.
Operaters.
You use :
while(armyAlive & army2Alive)
You could rewrite it as :
while(armyAlive && army2Alive).
Short explanation : if first is false, it won't check statement 2. Your case both operands are always checked.
Long explication here. Long explication here.
Use correct methods
Name may be strange, but what I want to say is, you are in the manager.
You want to do the battle between 2 Army's.
Why not returning the Army what won?
As you logical think about it, the battle just need to happen and you need to know in the guy who has won.
Setting the right things at the right place.
If it was me I would implement the method isAlive
in the Army class like this :
public boolean isAlive () {
return units > 0;
}
public void loseAUnit() {
units--;
}
Then changing the code to :
int playerStartUnits = playerArmy.units, enemyStartUnits = enemyArmy.units;
while(playerArmy.isAlive() && enemyArmy.isAlive()){
if(chance.generate()){
enemyArmy.loseAUnit();
}
else{
playerArmy.loseAUnit();
}
}
Army winner = playerArmy.isAlive()?playerArmy:enemyArmy;
resurrect(playerArmy,playerStartUnits,chance);
resurrect(enemyArmy,playerStartUnits,chance);
return winner;
For the regenerating, @vnp already mentioned how you could do it, just he didn't mentioned that you would have to send the chancegenerator also to the method.
I just find it strange that you only set the player his units back and not the enemy his troops after the resurrection.
What I mean with that is that you resurrect the enemy troops also, but never set them back.
Or you delete the resurrection of enemy troops or you do set them back.
I see a lot that we could help you with.
Operaters.
You use :
while(armyAlive & army2Alive)
You could rewrite it as :
while(armyAlive && army2Alive).
Short explanation : if first is false, it won't check statement 2. Your case both operands are always checked.
Long explication here.
Use correct methods
Name may be strange, but what I want to say is, you are in the manager.
You want to do the battle between 2 Army's.
Why not returning the Army what won?
As you logical think about it, the battle just need to happen and you need to know in the guy who has won.
Setting the right things at the right place.
If it was me I would implement the method isAlive
in the Army class like this :
public boolean isAlive () {
return units > 0;
}
public void loseAUnit() {
units--;
}
Then changing the code to :
int playerStartUnits = playerArmy.units, enemyStartUnits = enemyArmy.units;
while(playerArmy.isAlive() && enemyArmy.isAlive()){
if(chance.generate()){
enemyArmy.loseAUnit();
}
else{
playerArmy.loseAUnit();
}
}
Army winner = playerArmy.isAlive()?playerArmy:enemyArmy;
resurrect(playerArmy,playerStartUnits,chance);
resurrect(enemyArmy,playerStartUnits,chance);
return winner;
For the regenerating, @vnp already mentioned how you could do it, just he didn't mentioned that you would have to send the chancegenerator also to the method.
I just find it strange that you only set the player his units back and not the enemy his troops after the resurrection.
What I mean with that is that you resurrect the enemy troops also, but never set them back.
Or you delete the resurrection of enemy troops or you do set them back.
I see a lot that we could help you with.
Operaters.
You use :
while(armyAlive & army2Alive)
You could rewrite it as :
while(armyAlive && army2Alive).
Short explanation : if first is false, it won't check statement 2. Your case both operands are always checked.
Long explication here.
Use correct methods
Name may be strange, but what I want to say is, you are in the manager.
You want to do the battle between 2 Army's.
Why not returning the Army what won?
As you logical think about it, the battle just need to happen and you need to know in the guy who has won.
Setting the right things at the right place.
If it was me I would implement the method isAlive
in the Army class like this :
public boolean isAlive () {
return units > 0;
}
public void loseAUnit() {
units--;
}
Then changing the code to :
int playerStartUnits = playerArmy.units, enemyStartUnits = enemyArmy.units;
while(playerArmy.isAlive() && enemyArmy.isAlive()){
if(chance.generate()){
enemyArmy.loseAUnit();
}
else{
playerArmy.loseAUnit();
}
}
Army winner = playerArmy.isAlive()?playerArmy:enemyArmy;
resurrect(playerArmy,playerStartUnits,chance);
resurrect(enemyArmy,playerStartUnits,chance);
return winner;
For the regenerating, @vnp already mentioned how you could do it, just he didn't mentioned that you would have to send the chancegenerator also to the method.
I just find it strange that you only set the player his units back and not the enemy his troops after the resurrection.
What I mean with that is that you resurrect the enemy troops also, but never set them back.
Or you delete the resurrection of enemy troops or you do set them back.
- 145.5k
- 22
- 190
- 478
I see a lot whatthat we could help you with.
Operaters.
You use :
while(armyAlive & army2Alive)
You could refactor torewrite it as :
while(armyAlive && army2Alive).
Explication shortShort explanation : if first is faslefalse, heit won't check statement 2. Your case he checks the toboth operands are always checked.
Long explication here.
Use correct methods
Name may be strange, but what I want to say is, you are in the manager.
You want to do the battle between 2 Army's.
Why not returning the Army what won?
As you logical think about it, the battle just need to happen and you need to know in the guiguy who has won.
Setting the right things at the right place.
If it was me I should pywould implement the method isAlive
in th eArmythe Army class like this :
public boolean isAlive () {
return units > 0;
}
public void looseAUnitloseAUnit() {
units--;
}
Then changing the code to :
int playerStartUnits = playerArmy.units, enemyStartUnits = enemyArmy.units;
while(playerArmy.isAlive() && enemyArmy.isAlive()){
if(chance.generate()){
enemyArmy.looseAUnitloseAUnit();
}
else{
playerArmy.looseAUnitloseAUnit();
}
}
Army winner = playerArmy.isAlive()?playerArmy:enemyArmy;
resurrect(playerArmy,playerStartUnits,chance);
resurrect(enemyArmy,playerStartUnits,chance);
return winner;
For the regenerating, @vnp already mentioned how you could do it, just he didn't mentioned that you would have to send the chancegenerator also to the method.
I just find it strange that you only set the player his units back and not the enemy his troops after the ressurectionresurrection.
What I mean with that is that you ressurectresurrect the enemy troops also, but never set them back.
Or you delete the ressurectionresurrection of enemy troops or you do set them back.
I see a lot what we could help you with.
Operaters.
You use :
while(armyAlive & army2Alive)
You could refactor to :
while(armyAlive && army2Alive).
Explication short : if first is fasle, he won't check statement 2. Your case he checks the to.
Long explication here.
Use correct methods
Name may be strange, but what I want to say is, you are in the manager.
You want to do the battle between 2 Army's.
Why not returning the Army what won?
As you logical think about it, the battle just need to happen and you need to know in the gui who has won.
Setting the right things at the right place.
If it was me I should py the method isAlive
in th eArmy class like this :
public boolean isAlive () {
return units > 0;
}
public void looseAUnit() {
units--;
}
Then changing the code to :
int playerStartUnits = playerArmy.units, enemyStartUnits = enemyArmy.units;
while(playerArmy.isAlive() && enemyArmy.isAlive()){
if(chance.generate()){
enemyArmy.looseAUnit();
}
else{
playerArmy.looseAUnit();
}
}
Army winner = playerArmy.isAlive()?playerArmy:enemyArmy;
resurrect(playerArmy,playerStartUnits,chance);
resurrect(enemyArmy,playerStartUnits,chance);
return winner;
For the regenerating, @vnp already mentioned how you could do it, just he didn't mentioned that you would have to send the chancegenerator also to the method.
I just find it strange that you only set the player his units back and not the enemy his troops after the ressurection.
What I mean with that is that you ressurect the enemy troops also, but never set them back.
Or you delete the ressurection of enemy troops or you do set them back.
I see a lot that we could help you with.
Operaters.
You use :
while(armyAlive & army2Alive)
You could rewrite it as :
while(armyAlive && army2Alive).
Short explanation : if first is false, it won't check statement 2. Your case both operands are always checked.
Long explication here.
Use correct methods
Name may be strange, but what I want to say is, you are in the manager.
You want to do the battle between 2 Army's.
Why not returning the Army what won?
As you logical think about it, the battle just need to happen and you need to know in the guy who has won.
Setting the right things at the right place.
If it was me I would implement the method isAlive
in the Army class like this :
public boolean isAlive () {
return units > 0;
}
public void loseAUnit() {
units--;
}
Then changing the code to :
int playerStartUnits = playerArmy.units, enemyStartUnits = enemyArmy.units;
while(playerArmy.isAlive() && enemyArmy.isAlive()){
if(chance.generate()){
enemyArmy.loseAUnit();
}
else{
playerArmy.loseAUnit();
}
}
Army winner = playerArmy.isAlive()?playerArmy:enemyArmy;
resurrect(playerArmy,playerStartUnits,chance);
resurrect(enemyArmy,playerStartUnits,chance);
return winner;
For the regenerating, @vnp already mentioned how you could do it, just he didn't mentioned that you would have to send the chancegenerator also to the method.
I just find it strange that you only set the player his units back and not the enemy his troops after the resurrection.
What I mean with that is that you resurrect the enemy troops also, but never set them back.
Or you delete the resurrection of enemy troops or you do set them back.
I see a lot what we could help you with.
Operaters.
You use :
while(armyAlive & army2Alive)
You could refactor to :
while(armyAlive && army2Alive).
Explication short : if first is fasle, he won't check statement 2. Your case he checks the to.
Long explication here.
Use correct methods
Name may be strange, but what I want to say is, you are in the manager.
You want to do the battle between 2 Army's.
Why not returning the Army what won?
As you logical think about it, the battle just need to happen and you need to know in the gui who has won.
Setting the right things at the right place.
If it was me I should py the method isAlive
in th eArmy class like this :
public boolean isAlive () {
return units > 0;
}
public void looseAUnit() {
units--;
}
Then changing the code to :
int playerStartUnits = playerArmy.units, enemyStartUnits = enemyArmy.units;
while(playerArmy.isAlive() && enemyArmy.isAlive()){
if(chance.generate()){
enemyArmy.looseAUnit();
}
else{
playerArmy.looseAUnit();
}
}
Army winner = playerArmy.isAlive()?playerArmy:enemyArmy;
resurrect(playerArmy,playerStartUnits,chance);
resurrect(enemyArmy,playerStartUnits,chance);
return winner;
For the regenerating, @vnp already mentioned how you could do it, just he didn't mentioned that you would have to send the chancegenerator also to the method.
I just find it strange that you only set the player his units back and not the enemy his troops after the ressurection.
What I mean with that is that you ressurect the enemy troops also, but never set them back.
Or you delete the ressurection of enemy troops or you do set them back.