Inventory.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. public class Inventory {
  2. private Item[] items;
  3. public Inventory(Item[] items) {
  4. super();
  5. this.items = items;
  6. }
  7. public void updateQuality() {
  8. for (int i = 0; i < items.length; i++) {
  9. if (items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  10. continue;
  11. }
  12. if (items[i].getName().equals("Aged Brie")) {
  13. updateAgedBrie(i);
  14. }else if(items[i].getName().equals("Conjured Item")){
  15. updateConjuredItem(i);
  16. } else{
  17. updateRegularItem(i);
  18. }
  19. if(items[i].getQuality() < 80){
  20. items[i].setSellIn(items[i].getSellIn() -1);
  21. }
  22. }
  23. }
  24. public void updateAgedBrie(int i){
  25. if(items[i].getSellIn() > 0 && items[i].getQuality() <= 49){
  26. items[i].setQuality(items[i].getQuality() + 1);
  27. } else if(items[i].getSellIn() < 0 && items[i].getQuality() <= 48){
  28. items[i].setQuality(items[i].getQuality() + 2);
  29. }
  30. }
  31. public void updateRegularItem(int i){
  32. if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
  33. items[i].setQuality(items[i].getQuality() - 1);
  34. } else if(items[i].getSellIn() < 0 && items[i].getQuality() > 1){
  35. items[i].setQuality(items[i].getQuality() - 2);
  36. }
  37. }
  38. public void updateConjuredItem(int i){
  39. if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
  40. items[i].setQuality(items[i].getQuality() - 2);
  41. } else if(items[i].getSellIn() < 0 && items[i].getQuality() > 1){
  42. items[i].setQuality(items[i].getQuality() - 4);
  43. }
  44. }
  45. }