001 002/** 003 * Décrivez votre classe ItemList ici. 004 * 005 * @author Alban FERRACANI 006 * @version 04/2021 007 */ 008 009import java.util.HashMap; 010import java.util.Set; 011 012public class ItemList 013{ 014 private HashMap<String, Item> aInventory; 015 016 /** 017 * Constructeur 018 */ 019 public ItemList() 020 { 021 this.aInventory = new HashMap<>(); 022 } 023 024 /** 025 * Retourne la liste des items disponibles dans chaque pièce avec retour à la ligne. 026 */ 027 public String getItemString(){ 028 String vItemDescription = "Items disponibles :\n"; 029 String vItemDescription1 = " "; 030 Set<String> vKeys = this.aInventory.keySet(); 031 for(String vI : vKeys) 032 { 033 Item vItemA = this.aInventory.get(vI); 034 vItemDescription1 += " " + vItemA.getDescription() + "\n" + " "; 035 036 } 037 038 if (vItemDescription1 == " ") vItemDescription = "Aucun item disponible dans cette pièce."; 039 else vItemDescription += vItemDescription1; 040 041 return vItemDescription; 042 } //getItemString() 043 044 /** 045 * Retourne les items pris par le joueur. 046 */ 047 public String getItemStringInventaire(){ 048 String vItemDescriptionA = " "; 049 String vItemDescriptionIntro = "Vous avez pris les items : \n "; 050 String vItemDescriptionFinal = ""; 051 Set<String> vKeys = this.aInventory.keySet(); 052 053 for(String vI : vKeys) 054 { 055 Item vItemA = this.aInventory.get(vI); 056 vItemDescriptionA += " " +vItemA.getDescription() + "\n" + " "; 057 058 } 059 060 if (vItemDescriptionA == " ") vItemDescriptionFinal = "Vous n'avez pris aucun item avec vous."; 061 else vItemDescriptionFinal += vItemDescriptionIntro + vItemDescriptionA; 062 063 return vItemDescriptionFinal; 064 } //getItemStringInventaire() 065 066 /** 067 * putItem 068 */ 069 public void putItem(final String pStringItem, final Item pItem) 070 { 071 this.aInventory.put(pStringItem, pItem); 072 } //putItem() 073 074 /** 075 * removeItem 076 */ 077 public void removeItem(final String pStringItem) 078 { 079 this.aInventory.remove(pStringItem); 080 } //removeItem() 081 082 /** 083 * getCurrentItem 084 */ 085 public Item getCurrentItem(final String pItem) 086 { 087 return this.aInventory.get(pItem); 088 } //getCurrentItem() 089 090 /** 091 * Equivalent à getItemString() mais retourne les items les uns après les autres sans retour à la ligne. 092 * Sert dans le test pour voir si le joueur a gagné ou non. 093 */ 094 public String getItemStringWin(){ 095 String vItemDescription = ""; 096 097 Set<String> vKeys = this.aInventory.keySet(); 098 for(String vI : vKeys) 099 { 100 Item vItemA = this.aInventory.get(vI); 101 vItemDescription += vItemA.getDescription(); 102 } 103 104 // if (vItemDescription1 == null) vItemDescription = null; 105 // else vItemDescription += vItemDescription1; 106 107 return vItemDescription; 108 } //getItemStringWin() 109}