Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Java games....


ghost's Avatar
0 0

I got bored and programmed a simple Rock, Paper scissors game, just wondering if someone can help me add something that shows how many games you have played and how many times you have won and lost and such….here is the code…. import java.util.; import javax.swing.; public class RPS1 { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Let's play a game of R0ck, P4p3r, Scizz0rz", "Game", JOptionPane.INFORMATION_MESSAGE);

  /*Pick your choice of R P S*/
  int choice;
  int compchoice;
  String comment;
  Random generator = new Random();
  /*infanite loop*/
  
  while(true) 
  {
  
  choice = Integer.parseInt(JOptionPane.showInputDialog("Choose Rock(0) Paper(1) or Scissors(2)" )); /*i put a space between the "and the ) b/c it made this....") */
  
  /*Random Generator*/
  
  compchoice=generator.nextInt()%3;
  comment="";
  
  /* If user picks Rock*/
   switch (choice)
  {
     case (0):
     if(compchoice==0)
        comment+="Its a draw!";
     if(compchoice==1)
        comment+="You lose!";
     if(compchoice==2)
        comment+="You Win!";
     break; 
       
     
     /* If user picks Paper*/
     case 1:
     if(compchoice==0)
        comment+="You Lose!";
     if(compchoice==1)
        comment+="Its a draw!";
     if(compchoice==2)
        comment+="You Win!";
     break;
     
     /*If user picks Scissors*/
     case 2:
     if(compchoice==0)
        comment+="You Lose!";
     if(compchoice==1)
        comment+="You Win!";
     if(compchoice==2)
        comment+="Its a draw!" ;
     break;        
     
     /*If user picks an illegal number*/
     default:
        comment+="Pick the right number n00b cake!";
     break;  
        
                 
   }
   
   /* Shows comment after number is inputed*/
   JOptionPane.showMessageDialog(null,  comment, "Game", JOptionPane.INFORMATION_MESSAGE);
  } 

} }