Explorar el Código

finished p1 of lvl2

John Kim hace 6 años
padre
commit
449454721d
Se han modificado 2 ficheros con 116 adiciones y 11 borrados
  1. 112
    7
      Inventory.java
  2. 4
    4
      package.bluej

+ 112
- 7
Inventory.java Ver fichero

1
-
1
+import java.util.ArrayList;
2
 public class Inventory {
2
 public class Inventory {
3
+    
3
     private Item[] items;
4
     private Item[] items;
4
-
5
+    private ArrayList<String> specialItems;
6
+    
5
     public Inventory(Item[] items) {
7
     public Inventory(Item[] items) {
6
         super();
8
         super();
7
         this.items = items;
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
     public void updateQuality() {
16
     public void updateQuality() {
12
         for (int i = 0; i < items.length; i++) {
17
         for (int i = 0; i < items.length; i++) {
18
+            //if item at ith index doesnt equal aged brie AND BACKSTAGE PASS
13
             if (!items[i].getName().equals("Aged Brie")
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
                 if (items[i].getQuality() > 0) {
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
                     if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
24
                     if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
17
                         items[i].setQuality(items[i].getQuality() - 1);
25
                         items[i].setQuality(items[i].getQuality() - 1);
18
                     }
26
                     }
51
                         }
59
                         }
52
                     } else {
60
                     } else {
53
                         items[i].setQuality(items[i].getQuality()
61
                         items[i].setQuality(items[i].getQuality()
54
-                                - items[i].getQuality());
62
+                            - items[i].getQuality());
55
                     }
63
                     }
56
                 } else {
64
                 } else {
57
                     if (items[i].getQuality() < 50) {
65
                     if (items[i].getQuality() < 50) {
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 Ver fichero

5
 dependency2.from=InventoryTest
5
 dependency2.from=InventoryTest
6
 dependency2.to=Inventory
6
 dependency2.to=Inventory
7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
8
+editor.fx.0.height=709
9
 editor.fx.0.width=800
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
 objectbench.height=164
12
 objectbench.height=164
13
 objectbench.width=776
13
 objectbench.width=776
14
 package.divider.horizontal=0.6
14
 package.divider.horizontal=0.6
15
 package.divider.vertical=0.6845018450184502
15
 package.divider.vertical=0.6845018450184502
16
 package.editor.height=364
16
 package.editor.height=364
17
 package.editor.width=674
17
 package.editor.width=674
18
-package.editor.x=577
18
+package.editor.x=480
19
 package.editor.y=61
19
 package.editor.y=61
20
 package.frame.height=600
20
 package.frame.height=600
21
 package.frame.width=800
21
 package.frame.width=800