Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.39 KB | None | 0 0
  1. package fr.liwlufe.sgp;
  2.  
  3. import fr.liwlufe.shortcuts.Clavier;
  4. import fr.liwlufe.shortcuts.Ecran;
  5.  
  6. public class Mastermind {
  7.  
  8.     private static int chances = 10;
  9.     private static final char RED = 'R',
  10.                               BLUE = 'B',
  11.                               YELLOW = 'J',
  12.                               GREEN = 'V',
  13.                               ORANGE = 'O',
  14.                               GREY = 'G',
  15.                               INDIGO = 'I',
  16.                               FUCHSIA = 'F',
  17.                               BLANK = ' ';
  18.  
  19.     private static final String FIRST_SHOT = "Veuillez saisir la première lettre de la combinaison",
  20.                                 SECOND_SHOT = "Veuillez saisir la seconde lettre de la combinaison",
  21.                                 THIRD_SHOT = "Veuillez saisir la troisième lettre de la combinaison",
  22.                                 FOURTH_SHOT = "Veuillez saisir la quatrième lettre de la combinaison";
  23.    
  24.     private static class Combination {
  25.  
  26.         char first, second, third, fourth;
  27.  
  28.     }
  29.  
  30.     public static class Shot {
  31.        
  32.         char first, second, third, fourth;
  33.        
  34.     }
  35.    
  36.     public static void main(String[] args) {
  37.  
  38.         Combination c = createCombination();
  39.         Ecran.afficherln("[" + c.first + c.second + c.third + c.fourth + "]");
  40.         Shot s = createShot();
  41.  
  42.     }
  43.  
  44.     private static Combination random(Combination c, int counter) {
  45.  
  46.         char color;
  47.         int randomNumber = randomNumber(8);
  48.  
  49.         switch(randomNumber) {
  50.  
  51.         case 0:
  52.             color = RED;
  53.             break;
  54.         case 1:
  55.             color = BLUE;
  56.             break;
  57.         case 2:
  58.             color = YELLOW;
  59.             break;
  60.         case 3:
  61.             color = GREEN;
  62.             break;
  63.         case 4:
  64.             color = ORANGE;
  65.             break;
  66.         case 5:
  67.             color = GREY;
  68.             break;
  69.         case 6:
  70.             color = INDIGO;
  71.             break;
  72.         case 7:
  73.             color = FUCHSIA;
  74.             break;
  75.         default:
  76.             color = BLANK;
  77.             break;
  78.  
  79.         }
  80.  
  81.        
  82.         switch(counter) {
  83.        
  84.         case 1:
  85.             c.first = color;
  86.         case 2:
  87.             c.second = color;
  88.         case 3:
  89.             c.third = color;
  90.         case 4:
  91.             c.fourth = color;
  92.        
  93.         }
  94.         return c;
  95.  
  96.     }
  97.  
  98.     private static int randomNumber(int max) {
  99.  
  100.         return (int) (Math.random()*max);
  101.  
  102.     }
  103.  
  104.     private static Combination createCombination() {
  105.        
  106.         Combination c = new Combination();
  107.  
  108.         do {
  109.             for(int i = 1; i <= 4; ++i) {
  110.                 c = random(c, i);  
  111.             }
  112.         } while (c.first == c.second || c.first == c.third || c.first == c.fourth || c.second == c.third || c.second == c.fourth || c.third == c.fourth);
  113.  
  114.         return c;
  115.        
  116.     }
  117.    
  118.     private static Shot createShot() {
  119.        
  120.         Shot s = new Shot();
  121.        
  122.         char first = ' ', second = ' ', third = ' ', fourth = ' ';
  123.        
  124.         do {
  125.             Ecran.afficherln(FIRST_SHOT);
  126.             first = Clavier.saisirChar();
  127.         } while (first != RED && first != BLUE && first != YELLOW && first != GREEN && first != ORANGE && first != GREY && first != INDIGO && first != FUCHSIA);
  128.  
  129.         do {
  130.             Ecran.afficherln(SECOND_SHOT);
  131.             second = Clavier.saisirChar();
  132.         } while (second != RED && second != BLUE && second != YELLOW && second != GREEN && second != ORANGE && second != GREY && second != INDIGO && second != FUCHSIA);
  133.  
  134.         do {
  135.             Ecran.afficherln(THIRD_SHOT);
  136.             third = Clavier.saisirChar();
  137.         } while (third != RED && third != BLUE && third != YELLOW && third != GREEN && third != ORANGE && third != GREY && third != INDIGO && third != FUCHSIA);
  138.  
  139.         do {
  140.             Ecran.afficherln(FOURTH_SHOT);
  141.             fourth = Clavier.saisirChar();
  142.         } while (fourth != RED && fourth != BLUE && fourth != YELLOW && fourth != GREEN && fourth != ORANGE && fourth != GREY && fourth != INDIGO && fourth != FUCHSIA);
  143.  
  144.         s.first = first;
  145.         s.second = second;
  146.         s.third = third;
  147.         s.fourth = fourth;
  148.        
  149.         return s;
  150.        
  151.     }
  152.  
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement