No consigo hacer funcionar el programa, siempre me devuelve lo mismo
"El jugador no ha introducido una opcion valida" y "Ganador PC", cuando es mentira.
El código es el siguiente:
import java.util.*;
public class juegoInfantil
{
public final int Piedra = 0,Papel = 1,Tijeras = 2;
public String eleccionJugador1,eleccionJugador2
; public int ganadorJuego; // 0 si gana Pc 1 si gana jugador 2 empate
public juegoInfantil
(String eleccionJugador1
) {
this.eleccionJugador1 = eleccionJugador1;
this.eleccionJugador1 = this.eleccionJugador1.toUpperCase();
}
public void setEleccionJugador2()
{
int eleccionPc = numeroRandom.nextInt(3);
switch(eleccionPc)
{
case 0: this.eleccionJugador2 = "Piedra";
break;
case 1: this.eleccionJugador2 = "Papel";
break;
case 2: this.eleccionJugador2 = "Tijeras";
break;
}
this.eleccionJugador2 = this.eleccionJugador2.toUpperCase();
System.
out.
println("La eleccion del jugador 2 es: " + this.
eleccionJugador2 + " y la del jugador 1: " + this.
eleccionJugador1); }
public void inicioJuego()
{
if(this.eleccionJugador1 == "PIEDRA")
{
if(this.eleccionJugador2 == "PAPEL") this.ganadorJuego = 0;
else if(this.eleccionJugador2 == "TIJERAS") this.ganadorJuego = 1;
else this.ganadorJuego = 2;
}
else if(this.eleccionJugador1 == "PAPEL")
{
if(this.eleccionJugador2 == "PAPEL") this.ganadorJuego = 2;
else if(this.eleccionJugador2 == "TIJERAS") this.ganadorJuego = 0;
else this.ganadorJuego = 1;
}
else if(this.eleccionJugador1 == "TIJERAS")
{
if(this.eleccionJugador2 == "TIJERAS") this.ganadorJuego = 2;
else if(this.eleccionJugador2 == "PIEDRA") this.ganadorJuego = 0;
else this.ganadorJuego = 1;
}
else if(this.eleccionJugador1 != "TIJERAS" && this.eleccionJugador1 != "PAPEL" && this.eleccionJugador1 != "PIEDRA")
{
System.
out.
print("El jugador no ha introducido una opcion valida"); return;
}
}
{
if(this.ganadorJuego == 0) return "Ganador Pc";
else if(this.ganadorJuego == 1) return "Ganador Jugador";
else if(this.ganadorJuego == 2) return "Empate o Tablas";
return "Error";
}
public static void main
(String args
[]) {
Scanner entradaTeclado
= new Scanner
(System.
in); System.
out.
println("Introduce tu opcion: "); String entradaJugador
= entradaTeclado.
next(); entradaJugador = entradaJugador.toUpperCase();
juegoInfantil piedraPapelTijera = new juegoInfantil(entradaJugador);
piedraPapelTijera.setEleccionJugador2();
piedraPapelTijera.inicioJuego();
System.
out.
printf("%n%s",piedraPapelTijera.
getGanador()); }
}
No sé que pasará pero me trae de cabeza xD