-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecall.java
More file actions
31 lines (25 loc) · 1.08 KB
/
Recall.java
File metadata and controls
31 lines (25 loc) · 1.08 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
import java.util.ArrayList;
import java.util.DuplicateFormatFlagsException;
public class Recall {
private int actingHeroIndex;
private ArrayList<Heros> heroList;
private Map map;
public Recall(int actingHeroIndex, ArrayList<Heros> heroList, Map map){
this.actingHeroIndex = actingHeroIndex;
this.map = map;
this.heroList = heroList;
}
public void back() throws OccupiedLocationException {
Heros actingHero = heroList.get(actingHeroIndex);
int[] oldLocation = new int[2];
oldLocation[0] = actingHero.getHeroCol();
oldLocation[1] = actingHero.getHeroRow();
int[] newLocation = actingHero.getHomeLocation();
if (map.getStatus()[newLocation[0]][newLocation[1]].isHeroOccupied()){
throw new OccupiedLocationException("Home is occupied by other heroes!");
}
map.HeroMove(actingHeroIndex, heroList, actingHero.getHomeLocation(), oldLocation);
heroList.get(actingHeroIndex).setHeroCol(newLocation[0]);
heroList.get(actingHeroIndex).setHeroRow(newLocation[1]);
}
}