-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cat.java
87 lines (84 loc) · 2.48 KB
/
Cat.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
public class Cat {
protected int Xcor;
protected int Ycor;
public Cat(int x, int y){
Xcor = x;
Ycor = y;
}
public Cat moveURight() {
//System.out.println("OG:"+Xcor+","+Ycor);
Cat c = new Cat(Xcor += 1, Ycor +=2);
if(isInBounds(c)) {
//System.out.println("Cat new:" + c.Xcor+"," + c.Ycor);
return c;
}
return null;
}
public Cat moveDRight() {
//System.out.println("OG2:"+Xcor+","+Ycor);
Cat c = new Cat(Xcor+= 1, Ycor-= 2);
if(isInBounds(c)) {
//System.out.println("Cat new:" + c.Xcor+"," + c.Ycor);
return c;
}
return null;
}
public Cat moveULeft() {
//System.out.println("OG:"+Xcor+","+Ycor);
Cat c = new Cat(Xcor-= 1, Ycor+=2);
if(isInBounds(c)) {
//System.out.println("Cat new1:" + c.Xcor+"," + c.Ycor);
return c;
}
return null;
}
public Cat moveDLeft() {
//System.out.println("OG:"+Xcor+","+Ycor);
Cat c = new Cat(Xcor-= 1, Ycor-= 2);
if(isInBounds(c)) {
//System.out.println("Cat new1:" + c.Xcor+"," + c.Ycor);
return c;
}
return null;
}
public Cat moveLDown() {
//System.out.println("OG:"+Xcor+","+Ycor);
Cat c = new Cat(Xcor-= 2, Ycor-= 1);
if(isInBounds(c)) {
//System.out.println("Cat new:" + c.Xcor+"," + c.Ycor);
return c;
}
return null;
}
public Cat moveRDown() {
//System.out.println("OG:"+Xcor+","+Ycor);
Cat c = new Cat(Xcor+= 2, Ycor-= 1);
if(isInBounds(c)) {
//System.out.println("Cat new:" + c.Xcor+"," + c.Ycor);
return c;
}
return null;
}
public Cat moveLUp() {
//System.out.println("OG:"+Xcor+","+Ycor);
Cat c = new Cat(Xcor-= 2, Ycor+= 1);
if(isInBounds(c)) {
//System.out.println("Cat new:" + c.Xcor+"," + c.Ycor);
return c;
}
return null;
}
public Cat moveRUp() {
//System.out.println("OG:"+Xcor+","+Ycor);
Cat c = new Cat(Xcor+= 2, Ycor+= 1);
if(isInBounds(c)) {
// System.out.println("Cat new:" + c.Xcor+"," + c.Ycor);
return c;
}
return null;
}
public boolean isInBounds(Cat c){
if(0 <= c.Xcor && c.Xcor < 12 && 0 <= c.Ycor && c.Ycor < 12) return true;
return false;
}
}