-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.java
More file actions
63 lines (50 loc) · 1.81 KB
/
Copy pathPlayer.java
File metadata and controls
63 lines (50 loc) · 1.81 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
public class Player extends Monster{
public static final char PLAYERICON='@';
public Player() {
name = null;
enemyMonsters=null;
setIcon(PLAYERICON);
}
public Player(String name) {
this.name = name;
enemyMonsters=null;
setIcon(PLAYERICON);
}
public String getInfoScreen() { //basic info screen. (HP, etc.)
String info="";
if(name!=null)
info+="Name: " + name+"\n";
if(currentHp()>0)
info+="Hitpoints: "+showHitPoints()+"\n"+"\n";
return info;
}
//move functions either override monster moves or work the same way but are called by keyboard input
public void endPlayerTurn(){
Monster[] otherMonsters=currentLevel.levelMonsters;
for(int i=0;i<otherMonsters.length;i++){
if(otherMonsters[i]!=null
&&otherMonsters[i]!=this){ //!= might not be a sophisticated enough operator here
otherMonsters[i].turn();
}
}
RogueLikeGui.mapDisplayArea.setText(RogueLikeGui.d.getMap()); //should put this stuff in its own function somewhere
RogueLikeGui.actionDisplayArea.setText(RogueLikeGui.currentMessage);
RogueLikeGui.infoDisplayArea.setText(RogueLikeGui.player1.getInfoScreen());
}
public void moveTo(int xPos, int yPos){
//TODO: need error handling to prevent moving onto solid objects, or out of the room.
if(currentLevel.containsTile(xPos, yPos)){
if(currentLevel.isPassable(xPos,yPos)){ //idea: some of the code in this if statement might belong better inside of the "setposition" method
currentTile.clear();
setPosition(xPos, yPos);
currentTile.monster=this;
if(currentTile.containsItems())
pickUpAllTileItems();
return;
}
else if(currentLevel.getTile(xPos, yPos).monster!=null)
attack(currentLevel.getTile(xPos, yPos).monster);
}
}
//public void die() TODO: override monster death with correct player death actions
}