Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *date:le 14/11/2019
- *author: Bouquet Antoine
- */
- import iut.algo.*;
- import java.util.*;
- public class Streams
- {
- /*-----------------*/
- /* Constantes */
- /*-----------------*/
- static final int TAILLE_PIOCHE = 40;
- static final int TAILLE_GRILLE = 20;
- static int[] pioche;
- static int[] grille;
- static boolean expert = false;
- static boolean debug = false;
- static final int[] calculNormal = {0,0,1,3,5,7,8,11,15,20,25,30,35,40,50,60,70,85,100,150,300};
- static final int[] calculExpert = {0,0,1,3,5,7,3,11,15,20,25,30,20,40,50,60,70,50,100,150,300};
- public static void main(String[] args)
- {
- System.out.println("---------------------------------------------------\n");
- /*-----------------*/
- /* Variables */
- /*-----------------*/
- int tour = 1;
- int action = 0;
- int jeton = 0;
- char mode = 'O';
- int cpt;
- pioche = new int [TAILLE_PIOCHE];
- grille = new int [TAILLE_GRILLE];
- /* Initialisation de la pioche */
- cpt = 1;
- while (cpt < TAILLE_PIOCHE)
- {
- if (cpt <= 30)
- {
- pioche[cpt-1] = cpt;
- }
- else
- {
- pioche[cpt-1] = cpt-20;
- }
- cpt++;
- }
- pioche[TAILLE_PIOCHE-1] = 31; // Joker = 31
- /* Fin de l'initialisation de la pioche */
- /* On demande à l'utilisateur la difficulté */
- System.out.print("Difficulté (N (normal) ou E (expert)): ");
- mode = Clavier.lire_char();
- while (mode != 'N' && mode != 'E') {
- System.out.print("Difficulté (N (normal) ou E (expert): ");
- mode = Clavier.lire_char();
- }
- if(mode == 'E') { expert = true; }
- /* Fin de la demande à l'utilisateur */
- /* L'utilisateur remplit la grille */
- while(tour < 21 && !debug) {
- System.out.println("Tour actuel: " + tour + "/20.");
- // On pioche un jeton
- jeton = piocher();
- if(jeton == 31) {
- System.out.println("Jeton pioché: JOKER");
- }
- else
- {
- System.out.println("Jeton pioché: " + jeton);
- }
- System.out.println("Grille actuelle: | " + afficherGrille());
- System.out.println("Ou souhaitez-vous placer ce jeton ?");
- action = Clavier.lire_int();
- while(action < 1 || action > 20 || grille[action-1] != 0)
- {
- System.out.println("Ou souhaitez-vous placer ce jeton ?");
- action = Clavier.lire_int();
- }
- grille[action-1] = jeton;
- System.out.println("\n");
- tour++;
- }
- if(debug) {
- for(int i=0;i<TAILLE_GRILLE;i++) {
- grille[i] = piocher();
- }
- }
- System.out.println(afficherGrille());
- /* L'utilisateur a finit de remplir la grille */
- /* On calcul le score */
- System.out.println("Score: " + calculerScore());
- System.out.println("\n---------------------------------------------------");
- }
- public static String afficherGrille () // Cette fonction retourne une chaine de caractère correspondante à la grille du joueur.
- {
- String chaine = "";
- for (int i=0 ; i<TAILLE_GRILLE ; i++ )
- {
- if( grille[i] == 31 )
- {
- chaine += "JOKER | ";
- }
- else
- {
- if(grille[i] == 0) {
- chaine += "("+Integer.toString(i+1)+") | ";
- } else {
- chaine += grille[i]+" | ";
- }
- }
- }
- return chaine;
- }
- public static int piocher() // Cette fonction retourne un jeton de la pioche, et le supprime de la pioche.
- {
- Random ran = new Random();
- int randomInt = 0;
- int nbPioche = 0;
- randomInt = ran.nextInt(40);
- while (pioche[randomInt] == 0)
- {
- randomInt = ran.nextInt(40);
- }
- nbPioche = pioche[randomInt];
- pioche[randomInt] = 0;
- return nbPioche;
- }
- public static int calculerScore()
- {
- // grille = variable principale
- int score = 0;
- int previousNumber = 32;
- int cpt = 0;
- int length = 0;
- while (cpt < TAILLE_GRILLE)
- {
- if(grille[cpt] >= previousNumber || grille[cpt] == 31) { // 31 joker
- length++;
- } else {
- if(expert) {
- score += calculExpert[length+1];
- } else {
- score += calculNormal[length+1];
- }
- length = 0;
- }
- previousNumber = grille[cpt];
- cpt++;
- }
- score += calculNormal[length+1];
- return score;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement