Hallo
Ich bräuchte bei folgender Aufgabe Hilfe. Mein Hauptssachliches Problem besteht in den Methoden. Wie die Werte richtig übergeben werden und wie ich sie richtig zurückgebe. Wäre nett wenn jemand mal über den Code gucken könnte (ja ich weiß das es nicht sehr effizient/professionell geschrieben ist. Ich möchte nur wissen wie ich meine Methode richtig benutze/aufrufe/etc.)
Danke schonmal
Ich bräuchte bei folgender Aufgabe Hilfe. Mein Hauptssachliches Problem besteht in den Methoden. Wie die Werte richtig übergeben werden und wie ich sie richtig zurückgebe. Wäre nett wenn jemand mal über den Code gucken könnte (ja ich weiß das es nicht sehr effizient/professionell geschrieben ist. Ich möchte nur wissen wie ich meine Methode richtig benutze/aufrufe/etc.)
Danke schonmal
Java:
public class RockPaperScissors {
public static void main(String[] args) {
printGreetings();
int i = computerMove(i);
int c = playerMove(c);
boolean b = hasPlayerWon();
boolean b = isDraw();
// printMoves();
// printStatistics();
boolean B = askToPlayAgain();
printGoodbye();
}
public static void printGreetings(){
Out.println("Welcome to rock-paper-scissors!");
}
public static void printGoodbye(){
Out.println("Thank you for playing. Goodbye!");
}
public static int computerMove(int i){
i = (int) (Math.random()*3+1);
return i2;
}
public static int playerMove(int c){
Out.println("Your turn. What do you select? (1) = Rock, (2) = Paper, (3) = Scissor: ");
c = In.readInt();
return c2;
}
public static boolean hasPlayerWon() {
if ( i == 1 || c == 2)
b = true;
if ( i == 2 || c == 3)
b = true;
if ( i == 3 || c == 1)
b = true;
else b = false;
return b;
}
public static boolean isDraw(){
if ( i == 1 || c == 1)
b = true;
if ( i == 2 || c == 2)
b = true;
if ( i == 3 || c == 3)
b = true;
return b;
}
//public static void printMoves(){
// }
// public static void printStatistics(){
// }
public static boolean askToPlayAgain(){
Out.println("Do you want to play again? (1) = Yes, (2) = No: ");
int again = In.readInt();
if (again == 1)
B = true;
return B;
if (again == 2)
B = false;
return B;
}
}