I created an abstract class called Player and also created the player subclasses.
Now I need to create a menu for the user to choose which character he will use in the battle, but I can not create a new variable within if
or change a variable already declared on the outside.
Jogador Player2;
if (menu==1){Player2 = Ryu;}
else if (menu==2){Player2 = Blanka;}
else if (menu==3){Player2 = Zangief;}
else if (menu==4){Player2 = ChunLi;}
else if (menu==5){Player2 = Ken;}
In the above situation when trying to use the Player2 variable, Eclipse says that the variable has not yet been initialized.
if (menu==1){Jogador Player2 = new Ryu();}
else if (menu==2){Jogador Player2 = new Blanka();}
else if (menu==3){Jogador Player2 = new Zangief();}
else if (menu==4){Jogador Player2 = new ChunLi();}
else if (menu==5){Jogador Player2 = new Ken();}
In the above situation, it does not work for obvious reasons, as it will be terminated once the if is finished.
So, someone with a little more knowledge than me, can you explain a solution so that I can select one of the characters?