alizalang 6 年之前
父節點
當前提交
1a07184089
共有 2 個文件被更改,包括 66 次插入23 次删除
  1. 61
    18
      Inventory.java
  2. 5
    5
      package.bluej

+ 61
- 18
Inventory.java 查看文件

@@ -9,31 +9,74 @@ public class Inventory {
9 9
 
10 10
     public void updateQuality() {
11 11
         for (int i = 0; i < items.length; i++) {
12
+
13
+            if (items[i].getName().equals("Sulfuras, Hand of Ragnaros")){
14
+                continue;
15
+            }
16
+            else if (items[i].getName().equals("Aged Brie")){
17
+                agedBrieUpdate(i);
18
+            }
19
+            else {
20
+                regularItemUpdate(i);
21
+            }
22
+
23
+            /*
12 24
             if (!items[i].getName().equals("Aged Brie")) {
13
-                if (items[i].getQuality() > 0) {
14
-                    if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
15
-                        items[i].setQuality(items[i].getQuality() - 1);
16
-                    }
17
-                }
25
+            if (items[i].getQuality() > 0) {
26
+            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
27
+            items[i].setQuality(items[i].getQuality() - 1);
28
+            }
29
+            }
18 30
             } else {
19
-                if (items[i].getQuality() < 50) {
20
-                    items[i].setQuality(items[i].getQuality() + 1);
21
-                }
31
+            if (items[i].getQuality() < 50) {
32
+            items[i].setQuality(items[i].getQuality() + 1);
33
+            }
22 34
             }
23 35
 
24 36
             if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
25
-                items[i].setSellIn(items[i].getSellIn() - 1);
37
+            items[i].setSellIn(items[i].getSellIn() - 1);
26 38
             }
27 39
 
28 40
             if (items[i].getSellIn() < 0) {
29
-                if (!items[i].getName().equals("Aged Brie")) {
30
-                  items[i].setQuality(items[i].getQuality() - 1);
31
-                } else {
32
-                    if (items[i].getQuality() < 50) {
33
-                        items[i].setQuality(items[i].getQuality() + 1);
34
-                    }
35
-                }
41
+            if (!items[i].getName().equals("Aged Brie")) {
42
+            items[i].setQuality(items[i].getQuality() - 1);
43
+            } else {
44
+            if (items[i].getQuality() < 50) {
45
+            items[i].setQuality(items[i].getQuality() + 1);
46
+            }
36 47
             }
48
+            }
49
+             */
37 50
         }
38
-}
39
-}
51
+    }
52
+
53
+    public void agedBrieUpdate(int i){
54
+        //decrease the sellin by 1 every day
55
+        items[i].setSellIn(items[i].getSellIn()-1);
56
+
57
+        //increase the quality every day (as long as quality is not more than 50)
58
+        //increase the quality by 1 if sellin is greater than 0  and by 2 if sellin is 0
59
+        if  (items[i].getSellIn() > 0 && items[i].getQuality() < 50)
60
+            items[i].setQuality(items[i].getQuality()+1);
61
+        else if (items[i].getSellIn() <= 0 && (items[i].getQuality() < 49))
62
+            items[i].setQuality(items[i].getQuality()+2);
63
+        else if (items[i].getSellIn() <= 0 && items[i].getQuality() == 49)
64
+            items[i].setQuality(items[i].getQuality()+1);
65
+    }
66
+
67
+    public void regularItemUpdate(int i){
68
+        //decrease the sellin by 1 every day
69
+        items[i].setSellIn(items[i].getSellIn()-1);
70
+
71
+        //decrease the quality every day (as long as quality is greater than 0)
72
+        //decrease the quality by 1 if sellin is greater than 0  and by 2 if sellin is 0
73
+        if (items[i].getQuality() > 0){
74
+            if (items[i].getSellIn() > 0){
75
+                items[i].setQuality(items[i].getQuality() -1);
76
+            }
77
+            else {
78
+                items[i].setQuality(items[i].getQuality() -2);
79
+            }
80
+        }
81
+    }
82
+}

+ 5
- 5
package.bluej 查看文件

@@ -5,12 +5,12 @@ dependency1.type=UsesDependency
5 5
 dependency2.from=InventoryTest
6 6
 dependency2.to=Inventory
7 7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
9
-editor.fx.0.width=800
10
-editor.fx.0.x=320
11
-editor.fx.0.y=50
8
+editor.fx.0.height=787
9
+editor.fx.0.width=1113
10
+editor.fx.0.x=327
11
+editor.fx.0.y=40
12 12
 objectbench.height=164
13
-objectbench.width=776
13
+objectbench.width=461
14 14
 package.divider.horizontal=0.6
15 15
 package.divider.vertical=0.6845018450184502
16 16
 package.editor.height=364