Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. /*
  2. *date:le 14/11/2019
  3. *author: Bouquet Antoine
  4. */
  5.  
  6. import iut.algo.*;
  7. import java.util.*;
  8.  
  9. public class Streams
  10. {
  11.  
  12. /*-----------------*/
  13. /* Constantes */
  14. /*-----------------*/
  15.  
  16. static final int TAILLE_PIOCHE = 40;
  17. static final int TAILLE_GRILLE = 20;
  18. static int[] pioche;
  19. static int[] grille;
  20. static boolean expert = false;
  21. static boolean debug = false;
  22. 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};
  23. 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};
  24.  
  25. public static void main(String[] args)
  26. {
  27. System.out.println("---------------------------------------------------\n");
  28.  
  29. /*-----------------*/
  30. /* Variables */
  31. /*-----------------*/
  32.  
  33. int tour = 1;
  34. int action = 0;
  35. int jeton = 0;
  36. char mode = 'O';
  37.  
  38. int cpt;
  39.  
  40. pioche = new int [TAILLE_PIOCHE];
  41. grille = new int [TAILLE_GRILLE];
  42.  
  43. /* Initialisation de la pioche */
  44. cpt = 1;
  45. while (cpt < TAILLE_PIOCHE)
  46. {
  47. if (cpt <= 30)
  48. {
  49. pioche[cpt-1] = cpt;
  50. }
  51. else
  52. {
  53. pioche[cpt-1] = cpt-20;
  54. }
  55.  
  56. cpt++;
  57. }
  58. pioche[TAILLE_PIOCHE-1] = 31; // Joker = 31
  59. /* Fin de l'initialisation de la pioche */
  60.  
  61. /* On demande à l'utilisateur la difficulté */
  62. System.out.print("Difficulté (N (normal) ou E (expert)): ");
  63. mode = Clavier.lire_char();
  64. while (mode != 'N' && mode != 'E') {
  65. System.out.print("Difficulté (N (normal) ou E (expert): ");
  66. mode = Clavier.lire_char();
  67. }
  68. if(mode == 'E') { expert = true; }
  69. /* Fin de la demande à l'utilisateur */
  70.  
  71. /* L'utilisateur remplit la grille */
  72. while(tour < 21 && !debug) {
  73. System.out.println("Tour actuel: " + tour + "/20.");
  74.  
  75. // On pioche un jeton
  76. jeton = piocher();
  77.  
  78. if(jeton == 31) {
  79. System.out.println("Jeton pioché: JOKER");
  80. }
  81. else
  82. {
  83. System.out.println("Jeton pioché: " + jeton);
  84. }
  85.  
  86. System.out.println("Grille actuelle: | " + afficherGrille());
  87. System.out.println("Ou souhaitez-vous placer ce jeton ?");
  88. action = Clavier.lire_int();
  89.  
  90. while(action < 1 || action > 20 || grille[action-1] != 0)
  91. {
  92. System.out.println("Ou souhaitez-vous placer ce jeton ?");
  93. action = Clavier.lire_int();
  94. }
  95.  
  96. grille[action-1] = jeton;
  97. System.out.println("\n");
  98.  
  99. tour++;
  100. }
  101.  
  102.  
  103. if(debug) {
  104. for(int i=0;i<TAILLE_GRILLE;i++) {
  105. grille[i] = piocher();
  106. }
  107. }
  108.  
  109. System.out.println(afficherGrille());
  110. /* L'utilisateur a finit de remplir la grille */
  111.  
  112. /* On calcul le score */
  113. System.out.println("Score: " + calculerScore());
  114. System.out.println("\n---------------------------------------------------");
  115. }
  116.  
  117. public static String afficherGrille () // Cette fonction retourne une chaine de caractère correspondante à la grille du joueur.
  118. {
  119. String chaine = "";
  120. for (int i=0 ; i<TAILLE_GRILLE ; i++ )
  121. {
  122. if( grille[i] == 31 )
  123. {
  124. chaine += "JOKER | ";
  125. }
  126. else
  127. {
  128. if(grille[i] == 0) {
  129. chaine += "("+Integer.toString(i+1)+") | ";
  130. } else {
  131. chaine += grille[i]+" | ";
  132. }
  133. }
  134.  
  135. }
  136.  
  137. return chaine;
  138. }
  139.  
  140. public static int piocher() // Cette fonction retourne un jeton de la pioche, et le supprime de la pioche.
  141. {
  142. Random ran = new Random();
  143.  
  144. int randomInt = 0;
  145. int nbPioche = 0;
  146. randomInt = ran.nextInt(40);
  147.  
  148. while (pioche[randomInt] == 0)
  149. {
  150. randomInt = ran.nextInt(40);
  151. }
  152. nbPioche = pioche[randomInt];
  153. pioche[randomInt] = 0;
  154.  
  155. return nbPioche;
  156. }
  157.  
  158. public static int calculerScore()
  159. {
  160. // grille = variable principale
  161. int score = 0;
  162. int previousNumber = 32;
  163. int cpt = 0;
  164. int length = 0;
  165.  
  166. while (cpt < TAILLE_GRILLE)
  167. {
  168. if(grille[cpt] >= previousNumber || grille[cpt] == 31) { // 31 joker
  169. length++;
  170. } else {
  171. if(expert) {
  172. score += calculExpert[length+1];
  173. } else {
  174. score += calculNormal[length+1];
  175. }
  176. length = 0;
  177. }
  178.  
  179. previousNumber = grille[cpt];
  180. cpt++;
  181. }
  182. score += calculNormal[length+1];
  183.  
  184. return score;
  185. }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement