File tree Expand file tree Collapse file tree 4 files changed +66
-0
lines changed
src/main/java/cmf/commitField/domain/pet Expand file tree Collapse file tree 4 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -46,4 +46,9 @@ public Pet getPetById(@PathVariable Long petId) {
4646 public void deletePet (@ PathVariable Long petId ) {
4747 petService .deletePet (petId );
4848 }
49+
50+ public void getExpPet (User user , int commitCount ){
51+ petService .getExpPet (user , commitCount );
52+
53+ }
4954}
Original file line number Diff line number Diff line change @@ -51,4 +51,10 @@ public Pet(String name, User user){
5151 public enum Grow {
5252 EGG , HATCH , GROWN
5353 }
54+
55+ public int addExp (int commit ){
56+ exp +=commit ;
57+
58+ return exp ;
59+ }
5460}
Original file line number Diff line number Diff line change 1+ package cmf .commitField .domain .pet .entity ;
2+
3+ import lombok .Getter ;
4+
5+ @ Getter
6+ public enum PetGrowthLevel {
7+ LEVEL_1 (150 ),
8+ LEVEL_2 (300 );
9+
10+ private final int requiredExp ;
11+
12+ PetGrowthLevel (int requiredExp ) {
13+ this .requiredExp = requiredExp ;
14+ }
15+
16+ public int getRequiredExp () {
17+ return requiredExp ;
18+ }
19+
20+ // 현재 경험치에 맞는 레벨 찾기
21+ public static PetGrowthLevel getLevelByExp (int exp ) {
22+ PetGrowthLevel currentLevel = LEVEL_1 ;
23+ for (PetGrowthLevel level : values ()) {
24+ if (exp >= level .getRequiredExp ()) {
25+ currentLevel = level ;
26+ }
27+ }
28+ return currentLevel ;
29+ }
30+ }
Original file line number Diff line number Diff line change 11package cmf .commitField .domain .pet .service ;
22
33import cmf .commitField .domain .pet .entity .Pet ;
4+ import cmf .commitField .domain .pet .entity .PetGrowthLevel ;
45import cmf .commitField .domain .pet .repository .PetRepository ;
56import cmf .commitField .domain .user .entity .User ;
67import cmf .commitField .global .aws .s3 .S3Service ;
@@ -49,4 +50,28 @@ public void deletePet(Long petId) {
4950 petRepository .deleteById (petId );
5051 }
5152
53+ // 펫 성장
54+ public Pet getExpPet (User user , int commitCount ) {
55+ Pet pet = user .getPets ().get (0 );
56+ pet .addExp (commitCount ); // 경험치 증가
57+
58+ // 경험치 증가 후, 만약 레벨업한다면 레벨업 시킨다.
59+ if ( (pet .getGrow ()== Pet .Grow .EGG && pet .getExp ()>= PetGrowthLevel .LEVEL_1 .getRequiredExp ()) ||
60+ (pet .getGrow ()== Pet .Grow .HATCH && pet .getExp ()>=PetGrowthLevel .LEVEL_2 .getRequiredExp ()))
61+ levelUp (pet );
62+
63+ return petRepository .save (pet );
64+ }
65+
66+ // 펫 레벨 업
67+ public void levelUp (Pet pet ){
68+ switch (pet .getGrow ()){
69+ case EGG :
70+ pet .setGrow (Pet .Grow .HATCH );
71+ break ;
72+ case HATCH :
73+ pet .setGrow (Pet .Grow .GROWN );
74+ break ;
75+ }
76+ }
5277}
You can’t perform that action at this time.
0 commit comments