-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCell.java
More file actions
77 lines (71 loc) · 2.11 KB
/
Cell.java
File metadata and controls
77 lines (71 loc) · 2.11 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
/**
* Representation of the objects within the game
* @author Jeremy Okeyo
*/
public class Cell {
private int X;
private int Y;
private char direction; //Used to determine the orientation of the snake. u/d/l/r is up/down/left/right
/*
* Constuctor for food cell
*/
public Cell() {
X = 0;
Y = 0;
direction = 'n';
}
/*
* Constuctor for snake cell
* @param X Prosition of snake in Y axis
@param Y Position of snake in X axis
@param direction current direction of cell
*/
public Cell(int X, int Y, char direction) {
this.X = game.outOfBounds(X);
this.Y = game.outOfBounds(Y);
this.direction = direction;
}
public char getDir() {
return direction;
}
public int getX(){
return X;
}
public int getY(){
return Y;
}
public void setDir(char direction) {
this.direction = direction;
}
public void setLoc(int X, int Y){
this.Y = Y;
this.X = X;
}
/**
* Moves cell depending on the direction of the cell
* @param dir current direction
* @return new position depending on the direction
*/
public void move(char dir) {
if (dir == 'l')
X -= 1;
else if (dir == 'r')
X += 1;
else if (dir == 'u')
Y -= 1;
else if (dir == 'd')
Y += 1;
}
/**
* Checks whether two cells overlap
* @param cell another cell
* @ return true, if they overlap, false if they don't
*/
//@Override
public boolean equals(Cell cell) {
if (X == cell.getX() && Y == cell.getY())
return true;
else
return false;
}
}