maha_kaal

Tamagotchi 0.2

Apr 17th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.08 KB | None | 0 0
  1. /** Gioco.java **/
  2. public class Gioco {
  3.  
  4.     /**
  5.      * @Author: Sukhdev Mohan & Andrea Bonatti
  6.      * @version: 0.2
  7.      */
  8.    
  9.     public static void Benvenuto(){
  10.         System.out.println("************************* T A M A G O T C H I ************************************");
  11.         System.out.println("Benevenuto in Tamagotchi, ti verrà assegnato un mostricciattolo di nome Tamagotchi.");
  12.         System.out.println("Se vuoi puoi cambiargli nome, giocare con lui, accarezzarlo e dargli da mangiare.");
  13.         System.out.println("Divertiti :D");
  14.         System.out.println("**********************************************************************************");
  15.     }
  16.    
  17.     public static void main(String[] args) {
  18.         Benvenuto();
  19.         Tamagotchi tamagotchi;
  20.         tamagotchi = new Tamagotchi();
  21.         Supervisore controllore;
  22.         controllore = new Supervisore();
  23.         controllore.daiNome(tamagotchi);
  24.         controllore.stampaStato(tamagotchi.carezze, tamagotchi.biscotti, tamagotchi.nome);
  25.         controllore.opzioni(tamagotchi);
  26.     }
  27.  
  28. }
  29.  
  30. /** Tamagotchi.java **/
  31. public class Tamagotchi {
  32.    
  33.     public double carezze = 50;
  34.     public double biscotti = 30;
  35.     public String nome = "Tamagotchi";
  36.    
  37.     public void creaTamag(int _biscotti, int _carezze, String _nome){
  38.         carezze = _carezze;
  39.         biscotti = _biscotti;
  40.         nome = _nome;
  41.     }
  42.    
  43.     public void daiCarezza(double num){
  44.         this.carezze += num;
  45.         this.biscotti -= num/2;
  46.     }
  47.    
  48.     public void daiBiscotti(){
  49.         double num = this.biscotti * 0.1;
  50.         this.biscotti += num;
  51.         this.carezze -= num/4;
  52.     }
  53. }
  54.  
  55. /** Supervisore.java **/
  56.  
  57.  import java.util.*;
  58.  
  59. public class Supervisore {
  60.     public void stampaStato(double ncar, double nbis, String tnome){
  61.         System.out.printf("Nome : %s\nSazio: %3.2f\nAffetto: %3.2f\n", tnome, nbis, ncar);
  62.         if(ncar < 30 || ncar >90 || nbis < 30 || nbis > 90){
  63.             System.out.println(tnome + " è infelice...");
  64.         }
  65.     }
  66.    
  67.     public void daiNome(Tamagotchi mostro){
  68.         System.out.println("Inserire il nuovo nome:> ");
  69.         Scanner lettore = new Scanner(System.in);
  70.         String nnome = lettore.nextLine();
  71.         mostro.nome = nnome;
  72.     }
  73.    
  74.     public void opzioni(Tamagotchi mostro){
  75.         int i = 0;
  76.         double m = 0;
  77.         while(i != 3){
  78.             System.out.print("Opzioni:\nPremere\n 1 per dargli da mangiare;\n 2 per accarezzarlo;\n 3 per uscire;");
  79.             Scanner lettore = new Scanner(System.in);
  80.             int valore = lettore.nextInt();
  81.             switch (valore){
  82.                 case 1 :
  83.                     mostro.daiBiscotti();
  84.                     this.stampaStato(mostro.carezze, mostro.biscotti, mostro.nome);
  85.                     break;
  86.                 case 2 :
  87.                     m = this.aCaso();
  88.                     mostro.daiCarezza(m);
  89.                     this.stampaStato(mostro.carezze, mostro.biscotti, mostro.nome);
  90.                     break;
  91.                 case 3 :
  92.                     i = 3;
  93.                     System.out.println("!!!G A M E - O V E R!!!");
  94.                     this.stampaStato(mostro.carezze, mostro.biscotti, mostro.nome);
  95.                     break;
  96.             }
  97.             if (mostro.carezze <= 0 || mostro.biscotti <= 0 || mostro.biscotti >= 100){
  98.                 System.out.println(mostro.nome+ " è Morto...");
  99.                 System.out.println("!!!G A M E - O V E R!!!");
  100.                 i = 3;
  101.             }
  102.         }
  103.     }
  104.    
  105.     public double aCaso(){
  106.         Random rand = new Random();
  107.         double num = rand.nextInt(20) +1;
  108.         return num;
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment