Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.63 KB | None | 0 0
  1. package programs;
  2. import java.util.Scanner;
  3. public class TalhasShittyCode {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner input = new Scanner (System.in);
  8.        
  9.         int guess = 10;
  10.         int numGuess = 0;
  11.         int max = 3;
  12.         int min  = 1;
  13.         int peg1 = 0;
  14.         int peg2 = 0;
  15.         int peg3 = 0;
  16.         int correct = 0;
  17.         int randLoop1 = 0;
  18.         int randLoop2 = 0;
  19.         String string1 = "";
  20.         String string2 = "";
  21.         String string3 = "";
  22.         String guess1 = "";
  23.         String guess2 = "";
  24.         String guess3 = "";
  25.        
  26.         do {
  27.            
  28.             do {
  29.                 peg1 = (int)(Math.random()*(max) + min); //peg1 = (int)Math.random()*(max) + min; why does this only print one
  30.                
  31.                 if (peg1 == 1) {
  32.                 string1 = "R";
  33.             }
  34.             else if (peg1 == 2) {
  35.                 string1 = "G";
  36.             }
  37.             else if (peg1 == 3){
  38.                 string1 = "B";
  39.             }
  40.             randLoop1++;
  41.            
  42.             }while (randLoop1 < 1);
  43.            
  44.             randLoop2++;
  45.            
  46.             do {
  47.                 peg2 = (int)(Math.random()*(max) + min);
  48.                
  49.                 if (peg2 == 1) {
  50.                 string2 = "R";
  51.             }
  52.             else if (peg2 == 2) {
  53.                 string2 = "G";
  54.             }
  55.             else if (peg2 == 3){
  56.                 string2 = "B";
  57.             }
  58.             randLoop1++;
  59.            
  60.             }while (randLoop1 < 2);
  61.            
  62.             randLoop2++;
  63.            
  64.             do {
  65.                 peg3 = (int)(Math.random()*(max) + min);
  66.                
  67.                 if (peg3 == 1) {
  68.                 string3 = "R";
  69.             }
  70.             else if (peg3 == 2) {
  71.                 string3 = "G";
  72.             }
  73.             else if (peg3 == 3){
  74.                 string3 = "B";
  75.             }
  76.             randLoop1++;
  77.            
  78.             }while (randLoop1 < 3);
  79.            
  80.             randLoop2++;
  81.            
  82.         }while(randLoop2 <=3);
  83.        
  84.         System.out.println("Welcome to Mastermind! You have ten guesses to guess the hidden combination of coloured pegs.");
  85.         System.out.println("The possible colours are red (R), green (G) and blue (B)");
  86.         System.out.println("Enter in your guess as a capital letters, ie RGB");
  87.         do {
  88.         System.out.println("You have " + guess-- + " guesses left.");
  89.         System.out.println("Enter in your first peg");
  90.         guess1 = input.next();
  91.         System.out.println("Enter in your second peg");
  92.         guess2 = input.next();
  93.         System.out.println("Enter in your third peg");
  94.         guess3 = input.next();
  95.         correct = 0;
  96.         if (guess1.equals(string1)) {
  97.             correct++;
  98.         }
  99.         if (guess2.equals(string2)) {
  100.             correct++;
  101.         }
  102.         if (guess3.equals(string3)) {
  103.             correct++;
  104.         }
  105.         System.out.println("You got " + correct + " pegs correct");
  106.         numGuess++;
  107.         }while((correct != 3) && (numGuess < 10)); 
  108.         if (correct == 3) {
  109.             System.out.println("Congratulations you got them all");
  110.         }
  111.         else{
  112.             System.out.println("You fail.");
  113.             System.out.println("like everything else you have ever done in your life");
  114.             System.out.println("goodbye I dont have time for plebs");
  115.         }
  116.     }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement