-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Character class as a superclass of Player and Merchant holding
their shared methods and member variables.
- Loading branch information
Showing
3 changed files
with
72 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package model; | ||
|
||
public class Character { | ||
private int _x, _y; | ||
protected Item[] _inventory; | ||
protected String _name; | ||
|
||
|
||
/** | ||
* Searches through the player's inventory for the item corresponding to the specified item name | ||
* | ||
* @param itemName string containing the name of the item | ||
* @return the item matching the specified item name | ||
*/ | ||
public Item getItem(String itemName) | ||
{ | ||
for(int i = 0; i < _inventory.length; i++) | ||
{ | ||
if(_inventory[i].getItemName().equals(itemName)) | ||
return _inventory[i]; | ||
} | ||
|
||
System.out.println("No such item exists"); // item was not found by searching the inventory | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the merchant's item inventory | ||
* @return item inventory array | ||
*/ | ||
public Item[] getInventory() | ||
{ | ||
return _inventory; | ||
} | ||
|
||
/** | ||
* Returns a string containing the name of the merchant | ||
* | ||
* @return merchant name string | ||
*/ | ||
public String getName() | ||
{ | ||
return _name; | ||
} | ||
|
||
public int getX() { | ||
return _x; | ||
} | ||
|
||
public void setX(int x) { | ||
_x = x; | ||
} | ||
|
||
public int getY() { | ||
return _y; | ||
} | ||
|
||
public void setY(int y) { | ||
_y = y; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters