John Kim преди 6 години
родител
ревизия
449454721d
променени са 2 файла, в които са добавени 116 реда и са изтрити 11 реда
  1. 112
    7
      Inventory.java
  2. 4
    4
      package.bluej

+ 112
- 7
Inventory.java Целия файл

@@ -1,18 +1,26 @@
1
-
1
+import java.util.ArrayList;
2 2
 public class Inventory {
3
+    
3 4
     private Item[] items;
4
-
5
+    private ArrayList<String> specialItems;
6
+    
5 7
     public Inventory(Item[] items) {
6 8
         super();
7 9
         this.items = items;
10
+        this.specialItems = new ArrayList<String>();
11
+        this.specialItems.add("Aged Brie");
12
+        this.specialItems.add("Backstage passes to a TAFKAL80ETC concert");
13
+        this.specialItems.add("Sulfuras, Hand of Ragnaros");
8 14
     }
9
-
10
-
15
+    /*
11 16
     public void updateQuality() {
12 17
         for (int i = 0; i < items.length; i++) {
18
+            //if item at ith index doesnt equal aged brie AND BACKSTAGE PASS
13 19
             if (!items[i].getName().equals("Aged Brie")
14
-                    && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
20
+            && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
21
+                //left with normal and sulfuras with qual greater than 0
15 22
                 if (items[i].getQuality() > 0) {
23
+                    //not sulfurs minus the qual of each -1 but does it factor in time after sell by?
16 24
                     if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
17 25
                         items[i].setQuality(items[i].getQuality() - 1);
18 26
                     }
@@ -51,7 +59,7 @@ public class Inventory {
51 59
                         }
52 60
                     } else {
53 61
                         items[i].setQuality(items[i].getQuality()
54
-                                - items[i].getQuality());
62
+                            - items[i].getQuality());
55 63
                     }
56 64
                 } else {
57 65
                     if (items[i].getQuality() < 50) {
@@ -60,5 +68,102 @@ public class Inventory {
60 68
                 }
61 69
             }
62 70
         }
63
-}
71
+    }
72
+    */
73
+   
74
+    public void updateQuality() {
75
+        for (int i = 0; i < items.length; i++) {
76
+            //updateSulfurusQuality(i);
77
+            updateNormalItemQuality(i);
78
+            updateNormalItemSellIn(i);
79
+            updateAgedBrieQuality(i);
80
+            updateBackStageQuality(i);
81
+        }
82
+    }
83
+    
84
+    public void updateSellIn(int i) {
85
+        if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
86
+            items[i].setSellIn(items[i].getSellIn() - 1);
87
+        }
88
+    }
89
+    
90
+    public boolean determineSpecialQuality(int i) {
91
+        if (specialItems.contains(items[i].getName())) {
92
+            return true;
93
+        }
94
+        return false;
95
+    }
96
+    
97
+    public boolean pastSellIn(int i) {
98
+        if (items[i].getSellIn() < 0) {
99
+            return true;
100
+        }
101
+        return false;
102
+    }
103
+    
104
+    public void updateAgedBrieQuality(int index) {
105
+        if (items[index].getName().equals("Aged Brie")) {
106
+            if (pastSellIn(index)) {
107
+                changeQuality(index, 2);
108
+            } else {
109
+                changeQuality(index, 1);
110
+            }
111
+            pastMaxQuality(index);
112
+        }
113
+    }
114
+    
115
+    public void updateBackStageQuality(int index) {
116
+        if (items[index].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
117
+            
118
+            if (items[index].getSellIn() > 10) {
119
+                changeQuality(index, 1);
120
+            } else if (items[index].getSellIn() > 5) {
121
+                changeQuality(index, 2);
122
+            } else if (items[index].getSellIn() >= 0) {
123
+                changeQuality(index, 3);
124
+            } else {
125
+                items[index].setQuality(0);
126
+            }
127
+            pastMaxQuality(index);
128
+        }
129
+    }
130
+    
131
+    public void updateSulfurusQuality(int i) {
132
+        if (items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
133
+            //change nothing
134
+        }
135
+    }
136
+    
137
+    public void updateNormalItemSellIn(int index) {
138
+        if (!determineSpecialQuality(index)) {
139
+            updateSellIn(index);
140
+        }
141
+    }
142
+    
143
+    public void updateNormalItemQuality(int index) {
144
+        if (!determineSpecialQuality(index)) {
145
+            if (pastSellIn(index)) {
146
+                changeQuality(index, -2);
147
+            } else {
148
+                changeQuality(index, -1);
149
+            }
150
+            pastZeroQuality(index);
151
+        }
152
+    }
153
+    
154
+    public void changeQuality(int index, int amount) {
155
+        items[index].setQuality(items[index].getQuality() + amount);
156
+    }
157
+    
158
+    public void pastMaxQuality(int index) {
159
+        if (items[index].getQuality() > 50) {
160
+            items[index].setQuality(50);
161
+        }
162
+    }
163
+    
164
+    public void pastZeroQuality(int index) {
165
+        if (items[index].getQuality() < 0) {
166
+            items[index].setQuality(0);
167
+        }
168
+    }
64 169
 }

+ 4
- 4
package.bluej Целия файл

@@ -5,17 +5,17 @@ dependency1.type=UsesDependency
5 5
 dependency2.from=InventoryTest
6 6
 dependency2.to=Inventory
7 7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
8
+editor.fx.0.height=709
9 9
 editor.fx.0.width=800
10
-editor.fx.0.x=320
11
-editor.fx.0.y=50
10
+editor.fx.0.x=198
11
+editor.fx.0.y=29
12 12
 objectbench.height=164
13 13
 objectbench.width=776
14 14
 package.divider.horizontal=0.6
15 15
 package.divider.vertical=0.6845018450184502
16 16
 package.editor.height=364
17 17
 package.editor.width=674
18
-package.editor.x=577
18
+package.editor.x=480
19 19
 package.editor.y=61
20 20
 package.frame.height=600
21 21
 package.frame.width=800