Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Player {
  3. Location loc;
  4. private String name;
  5. private int HP;
  6. private int AP;
  7. private int DP;
  8. private Inventory inventory;
  9.  
  10. public Player(Location l, String name, int HP, int AP, int DP, Inventory inventory) {
  11. loc=l;
  12. this.name=name;
  13. this.HP=HP;
  14. this.AP=AP;
  15. this.DP=DP;
  16. this.inventory=inventory;
  17. }
  18.  
  19. public void movePlayer(int rowShift, int colShift) {
  20. loc.setRow(loc.getRow()+rowShift);
  21. loc.setCol(loc.getCol()+colShift);
  22. }
  23.  
  24. public void promptMove(Map m){
  25. Scanner scan=new Scanner (System.in);
  26. System.out.println("Please Move");
  27. String move=scan.next();
  28. if (move.equalsIgnoreCase("d")){
  29. if(m.validMove(loc,0,1)){
  30. movePlayer(0,1);
  31. m.inputPlayerLoc(getLoc());
  32. }
  33. else{
  34. System.out.println("Please enter a valid move");
  35. }
  36.  
  37. }
  38. else if (move.equalsIgnoreCase("a")){
  39. if(m.validMove(loc,0,-1)){
  40. movePlayer(0,-1);
  41. m.inputPlayerLoc(getLoc());
  42. }
  43. else{
  44. System.out.println("Please enter a valid move");
  45. }
  46.  
  47. }
  48. else if (move.equalsIgnoreCase("w")){
  49. if(m.validMove(loc,-1,0)){
  50. movePlayer(-1,0);
  51. m.inputPlayerLoc(getLoc());
  52. }
  53. else{
  54. System.out.println("Please enter a valid move");
  55. }
  56.  
  57. }
  58. else if (move.equalsIgnoreCase("s")){
  59. if(m.validMove(loc,1,0)){
  60. movePlayer(1,0);
  61. m.inputPlayerLoc(getLoc());
  62. }
  63. else{
  64. System.out.println("Please enter a valid move");
  65. }
  66.  
  67.  
  68. }
  69. else{
  70. System.out.println("That is an invalid move");
  71.  
  72. }
  73. m.printMap();
  74.  
  75.  
  76. }
  77.  
  78. public Location getLoc() {
  79. return loc;
  80. }
  81.  
  82. public void setLoc(Location loc) {
  83. this.loc = loc;
  84. }
  85. public String getName(){
  86. return name;
  87. }
  88. public void setName(String name){
  89. this.name=name;
  90. }
  91. public int getHP(){
  92. return HP;
  93. }
  94. public void setHP(int HP){
  95. this.HP=HP;
  96. }
  97. public int getAP(){
  98. return AP;
  99. }
  100. public void setAP(int AP){
  101. this.AP=AP;
  102. }
  103. public int getDP(){
  104. return DP;
  105. }
  106. public void setDP(int DP){
  107. this.DP=DP;
  108. }
  109. public Inventory getInventory(){
  110. return inventory;
  111. }
  112. public void setInventory(Inventory inventory){
  113. this.inventory=inventory;
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement