Repository navigation
Expand file tree
/
Copy pathPlayer.java
More file actions
148 lines (128 loc) · 4.5 KB
/
Copy pathPlayer.java
File metadata and controls
148 lines (128 loc) · 4.5 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import java.util.ArrayList;
/**
* Write a description of class Player here.
*
* @author (Mainuddin Monsur Robin)
* @version (1.0)
*/
public class Player
{
// instance variables - replace the example below with your own
private String name;
private int lives;
private int carriedWeight;
private Room currentLocation;
private static final int CarryWeightLimit = 30;
private ArrayList<Item> inventory;
private Room previousLocation;
/**
* Constructor for objects of class Player
*/
public Player(String name)
{
// initialise instance variables
this.carriedWeight = 0;
this.name = name;
this.lives = 3;
this.inventory = new ArrayList<Item>();
this.previousLocation = null;
}
/**
* Method putItem
* gives back an item from player items list to the room's list
* @param item the item to be left
* @return return true if it's left in the room successfully, and false if not, due to the room max limit
*/
public boolean putItem(Item item)
{
//adding the item to the room and checking its condition
if(this.currentLocation.addItem(item))
{
//removing it from the inventory and updating the status values.
this.inventory.remove(item);
return true;
}
return false;
}
/**
* Method takeItem
*-- adds specific item from the room to the player inventory
* @param item the item to be taken
* @return The return value is true if it doesn't exceed the weight limit, and false if it exceeded it
*/
public boolean takeItem(Item item)
{
if(this.carriedWeight <= CarryWeightLimit)
{
//removing the item from the room and checking its condition
if(this.currentLocation.removeItem(item))
{
//adding it to the inventory and updating the status values.
this.inventory.add(item);
return true;
}
}
return false;
}
/**
* Method status
*
* @return The return value is a string includs all the player status
*/
/*
public String status()
{
return "your current Status is the following: -" + "\n" + "number of lives: " + lives + ", health Points: " + healthPoints + ", Attack Points: " + attackPoints +
"\n" + "Defense Points: " + defensePoints;
}
*/
/**
* Method printInventory
* --Will be called by game class
*
* prints the itemslist to the user with its description
*/
public void printInventory()
{
System.out.printf("+---------------------------------------------------------------------------------------------------------------------------+%n");
System.out.printf("| %-10s | %-50s | %-6s | %-13s | %-14s | %-13s |%n", "Name", "Description", "Weight", "Attack Points", "Defense Points", "Health Points");
System.out.printf("+---------------------------------------------------------------------------------------------------------------------------+%n");
for (Item item : inventory)
{
System.out.printf("| %-10s |%n", item.getName());
}
System.out.printf("+---------------------------------------------------------------------------------------------------------------------------+%n");
System.out.printf("| %40s = %d/30 |%n","carriedWeight", carriedWeight);
System.out.printf("+---------------------------------------------------------------------------------------------------------------------------+%n");
}
/*<-----------------variables getters-------------------------------------------------------------->*/
public Room getCurrentLocation()
{
return this.currentLocation;
}
public ArrayList<Item> getInventory()
{
return this.inventory;
}
public int getLives()
{
return this.lives;
}
public Room getPreviousLocation()
{
return this.currentLocation;
}
public String getName()
{
return this.name;
}
/*<-----------------variables setters-------------------------------------------------------------->*/
public void setCurrentLocation(Room room)
{
this.currentLocation = room;
}
public void setPreviousLocation(Room room)
{
this.previousLocation = room;
}
}