-
Notifications
You must be signed in to change notification settings - Fork 449
/
Copy pathVirtualPet.java
180 lines (148 loc) · 5.41 KB
/
VirtualPet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
Text based Tamagotchi
By Emmanuel Adefuye 20/03/2019
*/
import java.util.Scanner;
public class VirtualPet
{
//Declare class petAttributes
//name, age, cleanliness, happiness, hunger, petRunAway boolean
//createPet method
//set the attribute variables
//interaction method
//while petRunAway is false
//increase Age
//player interaction
//feed, pet, play
//display status (current cleanliness, happiness, hunger)
//if cleanliness, happiness, hunger is less than a TBD value
//petRunAway is true
// if age is less than a TBD value, display corresponding petRunAway message
//prompt user to start over
//else petRunAway is false
//loop and increase age by 1
//Print how old the pet is and feeling
public static void main(String[] args)
{
VirtualPet tamagotchi = new VirtualPet();
tamagotchi.createPet();
}//end main
private String name;
private int age;
private int cleanliness;
private int happiness;
private int hunger;
private String hungerString;
private String cleanString;
private String happyString;
private boolean petRunAway;
public void createPet()
{
System.out.print("\nGive your pet a name: ");
Scanner petName = new Scanner(System.in);
name = petName.next();
age = 0;
cleanliness = 2;
happiness =1;
hunger = 0;
hungerString="";
cleanString="";
happyString="";
petRunAway = false;
interaction();
}
public void interaction()//this is where the actual game starts (interaction with the pet)
{
while(petRunAway == false)
{
Scanner input = new Scanner(System.in);
age += 1;
System.out.println(name+" is "+age+" days old!\n(1) Feed\n(2) Clean\n(3) Play");
System.out.println("\nSelect an action:" );
int interact = input.nextInt();
if(interact == 1)
{
happiness+=1;
if(happiness >=1 && happiness<=2){happyString = "Happy";}
if(happiness ==3){happyString = "Very Happy";}
if(happiness >=4){happyString = "Super-Mega-Ultra Happy";}
else if(happiness <0){happyString = "Sad";}
hunger-=1;
if(hunger >=1 && hunger <=2){hungerString = "Hungry";}
if(hunger ==3){hungerString = "Starving";}
if(hunger >=4){hungerString = "Borderline Dead (Calling PETA)";}
else if(hunger <=0){hungerString = "Full";}
cleanliness-=1;
if(cleanliness ==1){cleanString = "Messy";}
if(cleanliness == 0){cleanString = "Dirty";}
if(cleanliness < 0){cleanString = "Disgusting!";}
else if(cleanliness >=2){cleanString = "Clean";}
System.out.println("\n-------"+name+"'s Current Status-------"+"\n"+name+" gets dirtier!");
}
if(interact == 2)
{
happiness-=1;
if(happiness >=1 && happiness<=2){happyString = "Happy";}
if(happiness ==3){happyString = "Very Happy";}
if(happiness >=4){happyString = "Super-Mega-Ultra Happy";}
else if(happiness <=0){happyString = "Sad";}
hunger+=1;
if(hunger >=1 && hunger <=2){hungerString = "Hungry";}
if(hunger ==3){hungerString = "Starving";}
if(hunger >=4){hungerString = "Borderline Dead (Calling PETA)";}
else if(hunger <=0){hungerString = "Full";}
cleanliness+=1;
if(cleanliness ==1){cleanString = "Messy";}
if(cleanliness == 0){cleanString = "Dirty";}
if(cleanliness < 0){cleanString = "Disgusting!";}
else if(cleanliness >=2){cleanString = "Clean";}
System.out.println("\n-------"+name+"'s Current Status-------"+"\n"+name+" gets unhappy!");
}
if(interact == 3)
{
happiness+=1;
if(happiness >=1 && happiness<=2){happyString = "Happy";}
if(happiness ==3){happyString = "Very Happy";}
if(happiness >=4){happyString = "Super-Mega-Ultra Happy";}
else if(happiness <0){happyString = "Sad";}
hunger+=1;
if(hunger >=1 && hunger <=2){hungerString = "Hungry";}
if(hunger ==3){hungerString = "Starving";}
if(hunger >=4){hungerString = "Borderline Dead (Calling PETA)";}
else if(hunger <=0){hungerString = "Full";}
cleanliness-=1;
if(cleanliness ==1){cleanString = "Messy";}
if(cleanliness == 0){cleanString = "Dirty";}
if(cleanliness < 0){cleanString = "Disgusting!";}
else if(cleanliness >=2){cleanString = "Clean";}
System.out.println("\n-------"+name+"'s Current Status-------"+"\n"+name+" gets hungrier!");
}
System.out.println("Hunger Level: "+hungerString+"\nCleanliness: "+cleanString+"\nHappiness: "+happyString);
System.out.println("\n------------------------------------------------"+"\n");
if(age%2 == 0){hunger = hunger*2; cleanliness = cleanliness/2; happiness = happiness/2;}
if(hunger >=5 || happiness <= -1 || cleanliness <0)
{
petRunAway = true;
}
}//end while loop
if(petRunAway == true)
{
if(age >= 3 && age < 5){System.out.println("You only took care of "+name+" for "+age+" days, there's room for improvement.");}
if(age >= 5 && age < 10){System.out.println("Good job, you took care of "+name+" for "+age+" days!");}
if(age >= 10 && age < 20){System.out.println("Wow, you took care of "+name+" for "+age+" days, you're a great pet owner!");}
if(age <3){System.out.println(name+" ran away...you didn't care for it well enough");}
tryAgain();
}
}//end interaction
public void tryAgain()
{
System.out.println("Would you like to try again with another pet?\nY or N");
Scanner tryAgain = new Scanner(System.in);
String answer = tryAgain.next();
if(answer.matches("y|Y"))
{
createPet();
}
else{System.exit(0);}
}
}//end class