Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.liwlufe.sgp;
- import fr.liwlufe.shortcuts.Clavier;
- import fr.liwlufe.shortcuts.Ecran;
- public class Mastermind {
- private static int chances = 10;
- private static final char RED = 'R',
- BLUE = 'B',
- YELLOW = 'J',
- GREEN = 'V',
- ORANGE = 'O',
- GREY = 'G',
- INDIGO = 'I',
- FUCHSIA = 'F',
- BLANK = ' ';
- private static final String FIRST_SHOT = "Veuillez saisir la première lettre de la combinaison",
- SECOND_SHOT = "Veuillez saisir la seconde lettre de la combinaison",
- THIRD_SHOT = "Veuillez saisir la troisième lettre de la combinaison",
- FOURTH_SHOT = "Veuillez saisir la quatrième lettre de la combinaison";
- private static class Combination {
- char first, second, third, fourth;
- }
- public static class Shot {
- char first, second, third, fourth;
- }
- public static void main(String[] args) {
- Combination c = createCombination();
- Ecran.afficherln("[" + c.first + c.second + c.third + c.fourth + "]");
- Shot s = createShot();
- }
- private static Combination random(Combination c, int counter) {
- char color;
- int randomNumber = randomNumber(8);
- switch(randomNumber) {
- case 0:
- color = RED;
- break;
- case 1:
- color = BLUE;
- break;
- case 2:
- color = YELLOW;
- break;
- case 3:
- color = GREEN;
- break;
- case 4:
- color = ORANGE;
- break;
- case 5:
- color = GREY;
- break;
- case 6:
- color = INDIGO;
- break;
- case 7:
- color = FUCHSIA;
- break;
- default:
- color = BLANK;
- break;
- }
- switch(counter) {
- case 1:
- c.first = color;
- case 2:
- c.second = color;
- case 3:
- c.third = color;
- case 4:
- c.fourth = color;
- }
- return c;
- }
- private static int randomNumber(int max) {
- return (int) (Math.random()*max);
- }
- private static Combination createCombination() {
- Combination c = new Combination();
- do {
- for(int i = 1; i <= 4; ++i) {
- c = random(c, i);
- }
- } 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);
- return c;
- }
- private static Shot createShot() {
- Shot s = new Shot();
- char first = ' ', second = ' ', third = ' ', fourth = ' ';
- do {
- Ecran.afficherln(FIRST_SHOT);
- first = Clavier.saisirChar();
- } while (first != RED && first != BLUE && first != YELLOW && first != GREEN && first != ORANGE && first != GREY && first != INDIGO && first != FUCHSIA);
- do {
- Ecran.afficherln(SECOND_SHOT);
- second = Clavier.saisirChar();
- } while (second != RED && second != BLUE && second != YELLOW && second != GREEN && second != ORANGE && second != GREY && second != INDIGO && second != FUCHSIA);
- do {
- Ecran.afficherln(THIRD_SHOT);
- third = Clavier.saisirChar();
- } while (third != RED && third != BLUE && third != YELLOW && third != GREEN && third != ORANGE && third != GREY && third != INDIGO && third != FUCHSIA);
- do {
- Ecran.afficherln(FOURTH_SHOT);
- fourth = Clavier.saisirChar();
- } while (fourth != RED && fourth != BLUE && fourth != YELLOW && fourth != GREEN && fourth != ORANGE && fourth != GREY && fourth != INDIGO && fourth != FUCHSIA);
- s.first = first;
- s.second = second;
- s.third = third;
- s.fourth = fourth;
- return s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement