Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. import java.util.Date;
  4.  
  5. public class GiocoDeiDadi {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. String nome;
  10. Date date = new Date();
  11. Random rand = new Random(date.getTime());
  12. Scanner scan = new Scanner(System.in);
  13. int x = (int)(rand.nextDouble() * 6) + 1, numeroDadi = 5, somma1 = 0, somma2 = 0, lancio1 = (int)(rand.nextDouble() * 6) + 1, lancio2 = (int)(rand.nextDouble() * 6) + 1;
  14.  
  15. System.out.print("Inserisci il nome del Giocatore: ");
  16. nome = scan.next();
  17. System.out.println("Ok " + nome + " iniziamo a giocare!");
  18.  
  19. System.out.println(nome + " lanci per primo il dado, chi fa il risultato più basso inizia a giocare. Risultato: " + lancio1 + "!");
  20. System.out.println("Lancio per secondo il dado, chi fa il risultato più basso inizia a giocare. Risultato: " + lancio2 + "!");
  21.  
  22. while (lancio1 == lancio2) {
  23. System.out.println("Stesso risultato, riprova il lancio.");
  24. lancio1 = (int)(rand.nextDouble() * 6) + 1;
  25. System.out.println(nome + " il risultato del secondo lancio è " + lancio1);
  26. }
  27.  
  28. if (lancio1 < lancio2) {
  29. System.out.println("Inzia a giocare " + nome);
  30.  
  31. while (numeroDadi != 0) {
  32. x = (int)(rand.nextDouble() * 6) + 1;
  33. if (x == 2 || x == 5) {
  34. numeroDadi--;
  35. } else {
  36. somma1 = somma1 + x;
  37. }
  38. }
  39. System.out.println(nome + " hai totalizzato: " + somma1);
  40.  
  41. numeroDadi = 5;
  42. while (numeroDadi != 0) {
  43. x = (int)(rand.nextDouble() * 6) + 1;
  44. if (x == 2 || x == 5) {
  45. numeroDadi--;
  46. } else {
  47. somma2 = somma2 + x;
  48. }
  49. }
  50. System.out.println("Ho totalizzato: " + somma2);
  51.  
  52. } else {
  53. System.out.println("Inzio a giocare io");
  54.  
  55. while (numeroDadi != 0) {
  56. x = (int)(rand.nextDouble() * 6) + 1;
  57. if (x == 2 || x == 5) {
  58. numeroDadi--;
  59. } else {
  60. somma2 = somma2 + x;
  61. }
  62. }
  63. System.out.println("Ho totalizzato: " + somma2);
  64.  
  65. numeroDadi = 5;
  66. while (numeroDadi != 0) {
  67. x = (int)(rand.nextDouble() * 6) + 1;
  68. if (x == 2 || x == 5) {
  69. numeroDadi--;
  70. } else {
  71. somma1 = somma1 + x;
  72. }
  73. }
  74. System.out.println(nome + " hai totalizzato: " + somma1);
  75. }
  76.  
  77. if (somma1 > somma2) {
  78. System.out.println("Il vincitore è " + nome + " con " + somma1 + "! Mentre io ho totalizzato " + somma2 + "!");
  79. } else if (somma1 == somma2){
  80. System.out.println("Pareggio!");
  81. } else {
  82. System.out.println("Il vincitore sono io con " + somma2 + "! Mentre " + nome + " hai totalizzato " + somma1 + "!");
  83. }
  84. scan.close();
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement