2017-05-15 2 views
1
public static int wildPokemon(int opponentstats[] , int rattataStats[] , int geodudeStats[] , int pidgeyStats[]) 
{ 
rattataStats = new int[]{27,42,35}; 
geodudeStats = new int[]{35,45,80}; 
pidgeyStats = new int[]{39,33,33}; 

System.out.println("."); 
Pause(1000); 
System.out.println("."); 
Pause(1000); 
System.out.println("."); 
Pause(1000); 

Random wildPokemon = new Random(); 
int opponent = (wildPokemon.nextInt(3)); 
while(true) 
{ 
if(opponent == 0) 
{ 
System.out.println("You have come across a wild Rattata!!!"); 
rattataStats[0] = opponentstats[0]; 
rattataStats[1] = opponentstats[1]; 
rattataStats[2] = opponentstats[2]; 
return opponentstats; 

} 
else if(opponent == 1) 
{ 
    System.out.println("You have come across a wild Geodude!!!"); 
geodudeStats[0] = opponentstats[0]; 
geodudeStats[1] = opponentstats[1]; 
geodudeStats[2] = opponentstats[2]; 
return opponentstats; 

} 
else if(opponent ==-2) 
{ 
    System.out.println("You have come across a wild Pidgey!!!"); 
pidgeyStats[0] = opponentstats[0]; 
pidgeyStats[1] = opponentstats[1]; 
pidgeyStats[2] = opponentstats[2]; 
return opponentstats; 
} 
} 
} 

Ich bin so verloren und frustriert. Warum kann ich keine gegnerischen Stats und deren Werte zurückgeben? Danke für die Hilfe.Pokemon Spiel. Problem beim Zurückgeben eines Arrays JAVA

+0

Ich bin froh, dass wir das schnell lösen konnten :-) – GhostCat

Antwort

1

Die Methode wird deklariert, um int zurückzugeben.

Die Variable, die Sie zurückgeben möchten, ist vom Typ int [].

Entweder ändern Sie den Rückgabetyp in das Array von int, oder geben Sie stattdessen einen einzelnen int-Wert (kein Array!) Zurück.

+0

Vielen Dank für die unkomplizierte Antwort !! Sehr informativ und leicht zu verstehen! – lol

Verwandte Themen