Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/03/2008, 19:21
nerublanco
 
Fecha de Ingreso: marzo-2008
Mensajes: 13
Antigüedad: 16 años, 2 meses
Puntos: 0
Ayuda una variable

Hola,

estoy haciendo un programa de piedra, papel, tijera. El programa corre bien, pero necesito utilizar numeros en vez de string para la entrada de datos del jugador. Probablemente hay algo que no se como hacer, por fsvor me ayudan.

gracias


Código:
/*  calling libraries*/

     import javax.swing.JOptionPane;
     import java.util.Random;

/*  Declaring the class */

     public class RockPaperScissors1

     {

/*  Defining The method */

     public static void main(String[ ] args)
     {

/*  Declaring variables*/

        double selection;
        double R = 1;
        double P = 2;
        double S = 3;
        Random pc = new Random();
        int pcint = pc.nextInt(3)+1;

/*  Aqui necesito la opcion de que la entrada sea a traves de numeros y no string */

        selection = JOptionPane.showMessageDialog(null, "Welcome to the Rock, 
        Paper, Scissors"
        + "\nEnter 1 for ROCK" + "\nEnter 2 for PAPER" + "\nEnter 3 for SCISSORS");

/*  Comparing the two inputs and getting a result */

        if(selection == pcint)
          JOptionPane.showMessageDialog(null, " It's a Tie! ");      

       if(selection == 1 && pcint == 2)
         JOptionPane.showMessageDialog(null, " PC wins! ");      
  
       if(selection == 2 && pcint ==1)
         JOptionPane.showMessageDialog(null, " You Win! ");      

       if(selection == 1 && pcint == 3)
         JOptionPane.showMessageDialog(null, " PC Wins! ");      

       if(selection == 3 && pcint == 1)
         JOptionPane.showMessageDialog(null, " You Win! ");      

       if(selection == 2 && pcint == 3)
         JOptionPane.showMessageDialog(null, " PC Wins! ");      

       if(selection == 3 && pcint == 2)
         JOptionPane.showMessageDialog(null, " You Win! ");      

/* Program finishes here */

       System.exit(0);   
        
       }
}