Update extracted item[i] to variable

This commit is contained in:
Jon 2022-02-18 17:24:37 +00:00
parent d11808fa8f
commit 617871422e

View File

@ -13,31 +13,32 @@ class GildedRose {
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
// ----- Block 1 ----- Reduce quality of item by 1 for a day if not AB, BptaTc or SHoR // ----- Block 1 ----- Reduce quality of item by 1 for a day if not AB, BptaTc or SHoR
if (!items[i].name.equals("Aged Brie") Item item = items[i];
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { if (!item.name.equals("Aged Brie")
if (items[i].quality > 0) { && !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { if (item.quality > 0) {
items[i].quality = items[i].quality - 1; if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
item.quality = item.quality - 1;
} }
} }
// If Aged Brie or BptaTc // If Aged Brie or BptaTc
} else { } else {
// Increase quality of item by + 1 // Increase quality of item by + 1
if (items[i].quality < 50) { if (item.quality < 50) {
items[i].quality = items[i].quality + 1; item.quality = item.quality + 1;
// If pass has less than 11 days to sell, quality increases by + 1 // If pass has less than 11 days to sell, quality increases by + 1
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
if (items[i].sellIn < 11) { if (item.sellIn < 11) {
if (items[i].quality < 50) { if (item.quality < 50) {
items[i].quality = items[i].quality + 1; item.quality = item.quality + 1;
} }
} }
// If pass has 6 days to sell, quality increases by + 2 // If pass has 6 days to sell, quality increases by + 2
if (items[i].sellIn < 6) { if (item.sellIn < 6) {
if (items[i].quality < 50) { if (item.quality < 50) {
items[i].quality = items[i].quality + 1; item.quality = item.quality + 1;
} }
} }
} }
@ -45,30 +46,30 @@ class GildedRose {
} }
// ----- Block 2 ------ Item reduces by a day - 1 (unless SHoR) // ----- Block 2 ------ Item reduces by a day - 1 (unless SHoR)
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
items[i].sellIn = items[i].sellIn - 1; item.sellIn = item.sellIn - 1;
} }
// ----- Block 3 ----- Item sell date is less than 0 // ----- Block 3 ----- Item sell date is less than 0
if (items[i].sellIn < 0) { if (item.sellIn < 0) {
// Reduce quality of items by - 1 if greater than 0 and not AB, BptaTc or SHoR // Reduce quality of items by - 1 if greater than 0 and not AB, BptaTc or SHoR
if (!items[i].name.equals("Aged Brie")) { if (!item.name.equals("Aged Brie")) {
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
if (items[i].quality > 0) { if (item.quality > 0) {
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
items[i].quality = items[i].quality - 1; item.quality = item.quality - 1;
} }
} }
} else { } else {
// Item quality goes to 0 of BptaTc as item sell date is less than 0 // Item quality goes to 0 of BptaTc as item sell date is less than 0
items[i].quality = items[i].quality - items[i].quality; item.quality = item.quality - item.quality;
} }
// Increase quality of item if AB // Increase quality of item if AB
} else { } else {
if (items[i].quality < 50) { if (item.quality < 50) {
items[i].quality = items[i].quality + 1; item.quality = item.quality + 1;
} }
} }
} }