001import java.util.HashMap; 002import java.util.Stack; 003import java.util.Set; 004/** 005 * This class is part of the "Pere-noel" application. 006 * "Pere Noel" is a very simple, text based adventure game. 007 * 008 * @author Célia Priol & Benoît Chauveau 009 */ 010public class Player //7.29 011{ 012 private String aName; 013 private Room currentRoom; 014 private Stack<Room> stack; 015 //private HashMap<String,Item>Inventaire; 016 private int aMaxPoids=30 ; 017 //private ItemList ItemList; 018 private ItemList aInventaire; 019 private int aPoidsJoueur; 020 private Room aBeamer; 021 //private int moves = 0; 022 023 /** 024 * constructeur de la classe player 025 */public Player(String pname, Room pCurrentRoom) 026 { 027 this.aName=pname; 028 this.currentRoom = pCurrentRoom; 029 aInventaire = new ItemList(); 030 //stack = new Stack<Room>(); 031 032 } 033 034 /** 035 * Donne le nom du joueur 036 */ 037 public String getName() { 038 return aName; 039 } 040 041 /** 042 / * Accesseur 043 */ 044 public Room getcurrentRoom() 045 { 046 return currentRoom; 047 } 048 049 public int getPlayerPoids() 050 { 051 return aPoidsJoueur; 052 } 053 054 055 /** 056 * Modificateur 057 */ 058 public void setcurrentRoom(Room Room) 059 { 060 currentRoom=Room; 061 } 062 063 public int maxPoids() 064 { 065 return aMaxPoids; 066 } 067 068 /** 069 * Modificateur 070 */ 071 public void setMaxPoids(int pPoids) 072 { 073 aMaxPoids = pPoids; 074 } 075 076 public void addItem(String pName,Item pItem) 077 { 078 aInventaire.addItem(pName,pItem); 079 } 080 081 public String getInventory() 082 { 083 String returnString = "Dans ton inventaire :"; 084 Set<String> keys = aInventaire.getkeySet(); 085 for(String clé : keys) 086 { 087 Item trueItem = aInventaire.getItem(clé); 088 returnString += trueItem.getLongItem1Description(); 089 } 090 091 return returnString + "\n" + "Objet spécial : Il y a le Beamer (téléporteur portatif)." +"\n"; 092 } 093 094 public void removeItem(String pName) 095 { 096 aInventaire.removeItem(pName); 097 } 098 099 public void changeRoom( Room nextRoom) 100 { 101 currentRoom = nextRoom ; 102 103 } 104 105/** 106 * Accesseur 107 */ 108 public Item getItem(String pItem) 109 { 110 return aInventaire.getItem(pItem); 111 } 112// 113// * Returns a string describing the players current location and which 114// * items the player carries. 115// */ 116 public String getLongDescription() { 117 String returnString = currentRoom.getLongDescription(); 118 returnString += "\n" + getInventory(); 119 return returnString; 120 } 121 122 /** 123 * Charger the beamer to the current room 124 */ 125 public void chargeBeamer() { 126 aBeamer = currentRoom; 127 } 128 129 /** 130 * Fires the beamer 131 */ 132 public boolean fireBeamer() { 133 if(aBeamer != null) { 134 changeRoom(aBeamer); 135 return true; 136 } 137 return false; 138 } 139 140} 141