-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
177 lines (147 loc) · 4.25 KB
/
Main.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
import java.util.ArrayList;
import java.util.Scanner;
import javax.print.attribute.SetOfIntegerSyntax;
import jdk.jfr.SettingDescriptor;
public class Main {
public static void main(String[] args) {
Knoxagotchi Stalepet = new Knoxagotchi(1.0f,1.0f,1,"Blountasaurus"); // Should be... Knoxagotchi
Knoxagotchi pet = new kishan(2, 1.0f, 1.0f, 1, "KishanSpecies");
ArrayList<Action> actions = new ArrayList<Action>();
actions.add(new Eat());
actions.add(new Exercise());
actions.add(new levelUp());
// Your own action!
String input;
Scanner scan = new Scanner(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(Action action : actions) {
System.out.println(action.getCommand() + " --- " + action.getMenuMessage());
}
System.out.println("QUIT --- Quit the game.\n");
// Perform specified action.
input = scan.next().toUpperCase().trim();
boolean didAction = false;
for(Action action : 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();
}
}
class Knoxagotchi {
protected float happiness;
protected float hunger;
protected int level;
protected String species;
Knoxagotchi(float happiness, float hunger, int level, String species) {
this.happiness = happiness;
this.hunger = hunger;
this.level = level;
this.species = species;
}
int getLevel(){
return level;
}
float getHunger() {
return hunger;
}
float getHappiness() {
return happiness;
}
String getSpecies() {
return species;
}
void setLevel(int set){
this.level = set;
}
void setHunger(float set) {
this.hunger = set;
}
void setHappiness(float set) {
this.happiness = set;
}
void setSpecies(String set) {
this.species = set;
}
}
class kishan extends Knoxagotchi {
public kishan (int value, float happiness, float hunger, int level, String species) {
super (happiness * value, hunger * value, level * value, species);
}
}
abstract class Action {
public abstract String getCommand();
public abstract String getMenuMessage();
public abstract String doAction(Knoxagotchi pet);
}
class Eat extends Action {
@Override
public String getCommand() {
return "EAT";
}
@Override
public String getMenuMessage() {
return "Feed your pet.";
}
@Override
public String doAction(Knoxagotchi pet) {
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!";
}
}
class Exercise extends Action {
@Override
public String getCommand() {
return "EXERCISE";
}
@Override
public String getMenuMessage() {
return "Exercise with your pet.";
}
@Override
public String doAction(Knoxagotchi pet) {
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!";
}
}
class levelUp extends Action {
@Override
public String getCommand() {
return "LEVEL_UP";
}
@Override
public String getMenuMessage(){
return "Level Up Your Pet";
}
@Override
public String doAction(Knoxagotchi pet) {
if(pet.getHappiness() > .5) {
pet.setLevel(pet.getLevel() + 1);
return "You leveled Up!";
}
else {
return "Your pet is not happy enough!";
}
}
}