Results 1 to 2 of 2
  1. #1
    54byler is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Exclamation Lopping the game for two wins is the winner

    So far i have it so it will display who wins the game and the score of the game sucha s tie, win etc. I need this program to repeat until the user recieves two wins. Then i need it to displsay "You have won the game!"
    here is what i have

    import javax.swing.JOptionPane;

    public class Game{
    public static void main (String[] args){
    int computer = 0,
    user = 0,
    tie = 0,
    ComputerInput;


    //Generate random
    ComputerInput = (int)(Math.random() * 3);

    //User Input
    String intUserInput = JOptionPane.showInputDialog(null, "Enter 1 for rock, 2 for paper, 3 for scissors");
    int UserInput = Integer.parseInt(intUserInput);
    //User input invaild
    while (UserInput < 1 || UserInput > 3){
    intUserInput = JOptionPane.showInputDialog("Invalid entry! Enter a 1, 2 , or 3: " );
    UserInput = Integer.parseInt(intUserInput);
    }

    //Decide who wins and display message
    if (ComputerInput == 0 && UserInput == 1){
    JOptionPane.showMessageDialog(null, "You picked rock." + "\nThe computer picked rock." + "\nYou tied!" );
    tie++;
    }

    else if (ComputerInput == 1 && UserInput == 2){
    JOptionPane.showMessageDialog(null, "You picked paper." + "\nThe computer paper." + "\nYou tied!");
    tie++;
    }

    else if (ComputerInput == 2 && UserInput == 3){
    JOptionPane.showMessageDialog(null, "You picked scissors." + "\nThe computer picked scissors."
    + "\nYou tied!"); tie++;
    }
    else if (ComputerInput == 0 && UserInput == 2){
    JOptionPane.showMessageDialog(null, "You picked paper." + "\nThe computer rock."
    + "\nYou win!"); user++;
    }
    else if (ComputerInput == 0 && UserInput == 3){
    JOptionPane.showMessageDialog(null, "You picked scissors." + "\nThe computer picked rock."
    + "\nYou lose!"); computer++;
    }
    else if (ComputerInput == 1 && UserInput == 1 ){
    JOptionPane.showMessageDialog(null, "You picked rock." +
    "\nThe computer picked paper." + "\nYou lose!"); computer++;
    }
    else if (ComputerInput == 1 && UserInput == 3){
    JOptionPane.showMessageDialog(null, "You picked scissors." +
    "\nThe computer paper." + "\nYou win!"); user++;
    }
    else if (ComputerInput == 2 && UserInput == 1){
    JOptionPane.showMessageDialog(null, "You picked rock." +
    "\nThe computer scissors." + "\nYou win!"); user++;
    }
    else if (ComputerInput == 2 && UserInput == 2 ){
    JOptionPane.showMessageDialog(null, "You picked paper." +
    "\nThe computer scissors." + "\nYou lose!"); computer++;
    }
    //Score of games
    String output = "Scores: " + "\nTies= "+ tie + "\nYour Wins= " + user + "\nYour Losses= " + computer;
    JOptionPane.showMessageDialog(null, output);


    }
    }

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Something like?
    Java Code:
    while (wins<2) {
        // play game
    }
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  2. Game 21
    By aRTx in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2009, 12:33 AM
  3. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 06:00 AM
  4. Tic Tac Game
    By loggen in forum New To Java
    Replies: 1
    Last Post: 12-12-2008, 07:36 AM
  5. game
    By amith in forum AWT / Swing
    Replies: 0
    Last Post: 05-19-2008, 05:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •