mercredi 22 avril 2015

Random number keeps giving the number 1 (java)

Since I added the while loop to my little rock,paper and scissors game it keeps giving me the number 1.

package steenpapierschaar1;

import java.util.Scanner;

/**
 *
 * @author T
 */
public class SteenPapierSchaar1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        int rock = 1 ;   // waarde van Rock
        int paper = 2;  // waarde van paper
        int scissor = 3;// waarde van scissor
        int AI = 1 + (int) (Math.random() *3);// maakt int AI een random getal nog niet af moet een range in komen
        Scanner KeyBoard = new Scanner (System.in);// naam scanner input
        boolean playing = true;
        String answer, answer2 = null;


        while(playing = true){
            System.out.println("choose 1 for rock, 2 for paper and 3 for scissor"); // string met keuze voor User
            int UserChoice = KeyBoard.nextInt();// waarde van UserChoice

            if (AI == 1 && UserChoice == 2 || AI == 2 && UserChoice == 3 || AI == 3 && UserChoice == 1) { // als de speler elke keer 1x hoger heeft wint hij de ronde
                System.out.println("You WIN");// outprint met dat je gewonnen hebt en wat de computer doet
                if (AI == 1)
                    System.out.println("The Computer did rock");
                if (AI == 2)
                    System.out.println("The Computer did paper");
                if (AI == 3)
                    System.out.println("The Computer did scissors");


            }

            else if (AI == 1 && UserChoice == 1 || AI == 2 && UserChoice == 2 || AI == 3 && UserChoice == 3) {
                System.out.println("Draw");
                if (AI == 1)
                    System.out.println("The Computer did rock");
                if (AI == 2)
                    System.out.println("The Computer did paper");
                if (AI == 3)
                    System.out.println("The Computer did scissors");
            }

            else if (AI == 1 && UserChoice == 3 || AI == 2 && UserChoice == 1 || AI == 3 && UserChoice == 2){
                System.out.println("You Lose");
                if (AI == 1)
                    System.out.println("The Computer did rock");
                if (AI == 2)
                    System.out.println("The Computer did paper");
                if (AI == 3)
                    System.out.println("The Computer did scissors");
            }              

        }        
    }
}




Aucun commentaire:

Enregistrer un commentaire