Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
李楚霏
/
refactorTest
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e3923306
authored
May 24, 2020
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
task-8-if-conditions -- refactor updateQuality
function And refactor updateQualityAfterExpired Fun simply
parent
13c57e5a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
63 deletions
+69
-63
gildedRose/src/AgedBrie.js
+12
-6
gildedRose/src/BackstagePass.js
+26
-4
gildedRose/src/Sulfuras.js
+5
-5
gildedRose/src/item.js
+26
-48
No files found.
gildedRose/src/AgedBrie.js
View file @
e3923306
import
{
Item
}
from
"./item"
;
import
{
Item
}
from
'./item'
export
class
AgedBrie
extends
Item
{
constructor
(
sell_in
,
quality
)
{
super
(
sell_in
,
quality
);
this
.
name
=
'Aged Brie'
;
};
constructor
(
sell_in
,
quality
)
{
super
(
sell_in
,
quality
)
this
.
name
=
'Aged Brie'
}
isAgedBrie
()
{
return
'Aged Brie'
;
return
'Aged Brie'
}
updateQuality
(
item
)
{
if
(
item
.
quality
<
50
)
{
item
.
quality
=
item
.
quality
+
1
}
}
}
gildedRose/src/BackstagePass.js
View file @
e3923306
import
{
Item
}
from
"./item"
;
import
{
Item
}
from
'./item'
export
class
BackstagePass
extends
Item
{
constructor
(
sell_in
,
quality
)
{
super
(
sell_in
,
quality
);
this
.
name
=
'Backstage passes to a TAFKAL80ETC concert'
;
super
(
sell_in
,
quality
)
this
.
name
=
'Backstage passes to a TAFKAL80ETC concert'
}
isBackStage
()
{
return
'Backstage passes to a TAFKAL80ETC concert'
;
return
'Backstage passes to a TAFKAL80ETC concert'
}
updateQuality
(
item
)
{
if
(
item
.
name
===
this
.
isBackStagePass
())
{
if
(
item
.
quality
<
50
)
{
if
(
item
.
sell_in
<
11
)
{
if
(
item
.
quality
<
50
)
{
item
.
quality
=
item
.
quality
+
1
}
}
if
(
item
.
sell_in
<
6
)
{
if
(
item
.
quality
<
50
)
{
item
.
quality
=
item
.
quality
+
1
;
}
}
}
return
;
}
}
updateQualityAfterExpired
(
item
)
{
if
(
item
.
quality
<
50
)
{
item
.
quality
=
item
.
quality
+
1
}
}
}
gildedRose/src/Sulfuras.js
View file @
e3923306
import
{
Item
}
from
"./item"
;
import
{
Item
}
from
'./item'
export
class
Sulfuras
extends
Item
{
constructor
(
sell_in
,
quality
)
{
super
(
sell_in
,
quality
);
this
.
name
=
'Sulfuras, Hand of Ragnaros'
;
super
(
sell_in
,
quality
)
this
.
name
=
'Sulfuras, Hand of Ragnaros'
}
isSulfuras
()
{
return
'Sulfuras, Hand of Ragnaros'
;
return
'Sulfuras, Hand of Ragnaros'
}
updateQuality
(
item
)
{}
}
gildedRose/src/item.js
View file @
e3923306
...
...
@@ -10,15 +10,15 @@ export class Item {
}
isAgedBrie
()
{
return
'Aged Brie'
;
return
'Aged Brie'
}
isSulfuras
()
{
return
'Sulfuras, Hand of Ragnaros'
;
return
'Sulfuras, Hand of Ragnaros'
}
isBackStagePass
()
{
return
'Backstage passes to a TAFKAL80ETC concert'
;
return
'Backstage passes to a TAFKAL80ETC concert'
}
toString
()
{
...
...
@@ -26,84 +26,62 @@ export class Item {
}
createBackStagePass
(
sell_in
,
quality
)
{
new
BackStagePass
(
'Backstage passes to a TAFKAL80ETC concert'
,
sell_in
,
quality
);
new
BackStagePass
(
'Backstage passes to a TAFKAL80ETC concert'
,
sell_in
,
quality
)
}
createSulfuras
(
sell_in
,
quality
)
{
new
Sulfuras
(
sell_in
,
quality
)
;
new
Sulfuras
(
sell_in
,
quality
)
}
createNormalItem
(
name
,
sell_in
,
quality
)
{
new
Item
(
name
,
sell_in
,
quality
)
;
new
Item
(
name
,
sell_in
,
quality
)
}
createAgedBrie
(
sell_in
,
quality
)
{
new
AgedBrie
(
sell_in
,
quality
)
;
new
AgedBrie
(
sell_in
,
quality
)
}
_updateItem
(
item
)
{
this
.
updateQuality
InOneDay
(
item
);
this
.
updateSellIn
InOneDay
(
item
);
this
.
updateQualityAfter
Devaluation
(
item
);
this
.
updateQuality
(
item
)
this
.
updateSellIn
(
item
)
this
.
updateQualityAfter
Expired
(
item
)
}
updateQualityInOneDay
(
item
)
{
if
(
item
.
name
!=
this
.
isAgedBrie
()
&&
item
.
name
!=
this
.
isBackStagePass
())
{
updateQuality
(
item
)
{
if
(
item
.
quality
>
0
)
{
if
(
item
.
name
!=
this
.
isSulfuras
())
{
item
.
quality
=
item
.
quality
-
1
}
}
}
else
{
if
(
item
.
quality
<
50
)
{
this
.
updateQualityAfterExpired
(
item
)
if
(
item
.
name
==
this
.
isBackStagePass
())
{
if
(
item
.
sell_in
<
11
)
{
if
(
item
.
quality
<
50
)
{
this
.
updateQualityAfterExpired
(
item
);
}
}
if
(
item
.
sell_in
<
6
)
{
if
(
item
.
quality
<
50
)
{
this
.
updateQualityAfterExpired
(
item
);
}
}
}
}
}
}
updateSellIn
InOneDay
(
item
)
{
if
(
item
.
name
!
=
this
.
isSulfuras
())
{
this
.
decreaseSellIn
(
item
)
updateSellIn
(
item
)
{
if
(
item
.
name
==
=
this
.
isSulfuras
())
{
return
}
this
.
decreaseSellInOneDay
(
item
)
}
updateQualityAfterDevaluation
(
item
)
{
updateQualityAfterExpired
(
item
)
{
if
(
item
.
sell_in
>=
0
)
{
return
}
if
(
item
.
sell_in
<
0
)
{
if
(
item
.
name
!=
this
.
isAgedBrie
())
{
if
(
item
.
name
!=
this
.
isBackStagePass
())
{
if
(
item
.
name
!==
this
.
isAgedBrie
())
{
if
(
item
.
quality
>
0
)
{
if
(
item
.
name
!
=
this
.
isSulfuras
())
{
if
(
item
.
name
!=
=
this
.
isSulfuras
())
{
item
.
quality
=
item
.
quality
-
1
}
}
else
{
item
.
quality
=
item
.
quality
-
item
.
quality
}
}
else
{
if
(
item
.
quality
<
50
)
{
this
.
updateQualityAfterExpired
(
item
);
}
}
}
}
}
decreaseSellIn
(
item
)
{
decreaseSellIn
OneDay
(
item
)
{
item
.
sell_in
=
item
.
sell_in
-
1
}
updateQualityAfterExpired
(
item
)
{
item
.
quality
=
item
.
quality
+
1
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment