- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
177 lines (147 loc) · 4.25 KB
/
Copy pathMain.java
File metadata and controls
177 lines (147 loc) · 4.25 KB
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
importjava.util.ArrayList;
importjava.util.Scanner;
importjavax.print.attribute.SetOfIntegerSyntax;
importjdk.jfr.SettingDescriptor;
publicclassMain {
publicstaticvoidmain(String[] args) {
KnoxagotchiStalepet = newKnoxagotchi(1.0f,1.0f,1,"Blountasaurus"); // Should be... Knoxagotchi
Knoxagotchipet = newkishan(2, 1.0f, 1.0f, 1, "KishanSpecies");
ArrayList<Action> actions = newArrayList<Action>();
actions.add(newEat());
actions.add(newExercise());
actions.add(newlevelUp());
// Your own action!
Stringinput;
Scannerscan = newScanner(System.in);
System.out.println("#############################");
System.out.println("Welcome to Knoxagotchi. Your pet is a " + pet.species + ".");
do {
// Print options.
System.out.println("\nEnter one of the following commands:\n");
for(Actionaction : actions) {
System.out.println(action.getCommand() + " --- " + action.getMenuMessage());
}
System.out.println("QUIT --- Quit the game.\n");
// Perform specified action.
input = scan.next().toUpperCase().trim();
booleandidAction = false;
for(Actionaction : actions) {
if(input.equals(action.getCommand())) {
System.out.println(action.doAction(pet));
didAction = true;
break;
}
}
if(didAction == false && !input.equals("QUIT")) {
System.out.println("Invalid action. Try again.");
}
} while(!input.equals("QUIT"));
scan.close();
}
}
classKnoxagotchi {
protectedfloathappiness;
protectedfloathunger;
protectedintlevel;
protectedStringspecies;
Knoxagotchi(floathappiness, floathunger, intlevel, Stringspecies) {
this.happiness = happiness;
this.hunger = hunger;
this.level = level;
this.species = species;
}
intgetLevel(){
returnlevel;
}
floatgetHunger() {
returnhunger;
}
floatgetHappiness() {
returnhappiness;
}
StringgetSpecies() {
returnspecies;
}
voidsetLevel(intset){
this.level = set;
}
voidsetHunger(floatset) {
this.hunger = set;
}
voidsetHappiness(floatset) {
this.happiness = set;
}
voidsetSpecies(Stringset) {
this.species = set;
}
}
classkishanextendsKnoxagotchi {
publickishan (intvalue, floathappiness, floathunger, intlevel, Stringspecies) {
super (happiness * value, hunger * value, level * value, species);
}
}
abstractclassAction {
publicabstractStringgetCommand();
publicabstractStringgetMenuMessage();
publicabstractStringdoAction(Knoxagotchipet);
}
classEatextendsAction {
@Override
publicStringgetCommand() {
return"EAT";
}
@Override
publicStringgetMenuMessage() {
return"Feed your pet.";
}
@Override
publicStringdoAction(Knoxagotchipet) {
pet.setHunger(pet.getHunger() - 0.25f);
if(pet.getHunger() < 0.5) {
pet.setHappiness(pet.getHappiness() + 0.25f);
return"Your pet is satisfied!";
}
pet.setHappiness(pet.getHappiness() - 0.25f);
return"You pet is still hungry!";
}
}
classExerciseextendsAction {
@Override
publicStringgetCommand() {
return"EXERCISE";
}
@Override
publicStringgetMenuMessage() {
return"Exercise with your pet.";
}
@Override
publicStringdoAction(Knoxagotchipet) {
pet.setHunger(pet.getHunger() + 0.25f);
if(pet.getHunger() < 0.5) {
pet.setHappiness(pet.getHappiness() + 0.1f);
return"Your pet had a good workout!";
}
pet.setHappiness(pet.getHappiness() - 0.25f);
return"You pet is exhausted and hungry!";
}
}
classlevelUpextendsAction {
@Override
publicStringgetCommand() {
return"LEVEL_UP";
}
@Override
publicStringgetMenuMessage(){
return"Level Up Your Pet";
}
@Override
publicStringdoAction(Knoxagotchipet) {
if(pet.getHappiness() > .5) {
pet.setLevel(pet.getLevel() + 1);
return"You leveled Up!";
}
else {
return"Your pet is not happy enough!";
}
}
}