Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Gioco.java **/
- public class Gioco {
- /**
- * @Author: Sukhdev Mohan & Andrea Bonatti
- * @version: 0.2
- */
- public static void Benvenuto(){
- System.out.println("************************* T A M A G O T C H I ************************************");
- System.out.println("Benevenuto in Tamagotchi, ti verrà assegnato un mostricciattolo di nome Tamagotchi.");
- System.out.println("Se vuoi puoi cambiargli nome, giocare con lui, accarezzarlo e dargli da mangiare.");
- System.out.println("Divertiti :D");
- System.out.println("**********************************************************************************");
- }
- public static void main(String[] args) {
- Benvenuto();
- Tamagotchi tamagotchi;
- tamagotchi = new Tamagotchi();
- Supervisore controllore;
- controllore = new Supervisore();
- controllore.daiNome(tamagotchi);
- controllore.stampaStato(tamagotchi.carezze, tamagotchi.biscotti, tamagotchi.nome);
- controllore.opzioni(tamagotchi);
- }
- }
- /** Tamagotchi.java **/
- public class Tamagotchi {
- public double carezze = 50;
- public double biscotti = 30;
- public String nome = "Tamagotchi";
- public void creaTamag(int _biscotti, int _carezze, String _nome){
- carezze = _carezze;
- biscotti = _biscotti;
- nome = _nome;
- }
- public void daiCarezza(double num){
- this.carezze += num;
- this.biscotti -= num/2;
- }
- public void daiBiscotti(){
- double num = this.biscotti * 0.1;
- this.biscotti += num;
- this.carezze -= num/4;
- }
- }
- /** Supervisore.java **/
- import java.util.*;
- public class Supervisore {
- public void stampaStato(double ncar, double nbis, String tnome){
- System.out.printf("Nome : %s\nSazio: %3.2f\nAffetto: %3.2f\n", tnome, nbis, ncar);
- if(ncar < 30 || ncar >90 || nbis < 30 || nbis > 90){
- System.out.println(tnome + " è infelice...");
- }
- }
- public void daiNome(Tamagotchi mostro){
- System.out.println("Inserire il nuovo nome:> ");
- Scanner lettore = new Scanner(System.in);
- String nnome = lettore.nextLine();
- mostro.nome = nnome;
- }
- public void opzioni(Tamagotchi mostro){
- int i = 0;
- double m = 0;
- while(i != 3){
- System.out.print("Opzioni:\nPremere\n 1 per dargli da mangiare;\n 2 per accarezzarlo;\n 3 per uscire;");
- Scanner lettore = new Scanner(System.in);
- int valore = lettore.nextInt();
- switch (valore){
- case 1 :
- mostro.daiBiscotti();
- this.stampaStato(mostro.carezze, mostro.biscotti, mostro.nome);
- break;
- case 2 :
- m = this.aCaso();
- mostro.daiCarezza(m);
- this.stampaStato(mostro.carezze, mostro.biscotti, mostro.nome);
- break;
- case 3 :
- i = 3;
- System.out.println("!!!G A M E - O V E R!!!");
- this.stampaStato(mostro.carezze, mostro.biscotti, mostro.nome);
- break;
- }
- if (mostro.carezze <= 0 || mostro.biscotti <= 0 || mostro.biscotti >= 100){
- System.out.println(mostro.nome+ " è Morto...");
- System.out.println("!!!G A M E - O V E R!!!");
- i = 3;
- }
- }
- }
- public double aCaso(){
- Random rand = new Random();
- double num = rand.nextInt(20) +1;
- return num;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment