-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.java
More file actions
120 lines (116 loc) · 1.83 KB
/
Entity.java
File metadata and controls
120 lines (116 loc) · 1.83 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
package work;
public class Entity {
private int x;
private int y;
private int hunger;
private int age;
private int speed;
private boolean fertile;
//Original Constructors
public Entity(int x, int y){
this.x=x;
this.y=y;
fertile=false;
hunger=0;
}
//Accessors
public int getX(){
return x;
}
public int getY(){
return y;
}
public int getHunger(){
return hunger;
}
public int getAge(){
return age;
}
public boolean getFertile(){
return fertile;
}
//Mutators
public void setX(int x){
if(checkLeft()&&checkRight()){
this.x=x;
}
//else error1();
}
public void setY(int y){
if(checkDown()&&checkUp()){
this.y=y;
}
//else error2();
}
public void setSpeed(int x){
if(speed>=0&&speed<=2){
speed=x;
}
else {
speed = 0;
error3();
}
}
public void setHunger(int x){
if(x>=0&&x<=50){
hunger=x;
}
else{
hunger=0;
error4();
}
}
public void setAge(int x){
if(x>=0&&x<=10000){
age=x;
}
else{
age=0;
error5();
}
}
public void setFertile(boolean a){
fertile = a;
}
//Assorted
public boolean checkLeft(){
if(x>=10){
return true;
}
return false;
}
public boolean checkRight(){
if(x<=780){
return true;
}
return false;
}
public boolean checkUp(){
if(y>=10){
return true;
}
return false;
}
public boolean checkDown(){
if(y<=580){
return true;
}
return false;
}
//error messages, Identify the error for me
public void error1(){
System.out.println("Error 1");
}
public void error2(){
System.out.println("Error 2");
}
public void error3(){
System.out.println("Error 3");
}
public void error4(){
System.out.println("Error 4");
}
public void error5(){
System.out.println("Error 5");
}
}