generated from Game-as-a-Service/Gaas-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'CreateAndGetGame' of github.com:Game-as-a-Service/citad…
…els-game into CreateAndGetGame # Conflicts: # packages/backend/app/src/main/java/tw/waterballsa/gaas/citadels/app/repositories/GameRepository.java # packages/backend/app/src/main/java/tw/waterballsa/gaas/citadels/app/usecases/GetGameUseCase.java # packages/backend/app/src/main/java/tw/waterballsa/gaas/citadels/app/usecases/StartGameUseCase.java # packages/backend/domain/src/main/java/tw/waterballsa/gaas/citadels/domain/Player.java # packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/controllers/GameController.java # packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/controllers/viewmodel/GameView.java # packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/controllers/viewmodel/GetGameView.java # packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/controllers/viewmodel/PlayerView.java # packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/controllers/viewmodel/StartGameView.java # packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/repositories/GameRepositoryImpl.java # packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/repositories/dao/GameDAO.java # packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/repositories/data/GameData.java # packages/backend/spring/src/main/java/tw/waterballsa/gaas/citadels/spring/repositories/data/PlayerData.java # packages/backend/spring/src/test/java/tw/waterballsa/gaas/citadels/spring/controllers/CreateGameAndGetGameTest.java
- Loading branch information
Showing
7 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/backend/domain/src/main/java/tw/waterballsa/gaas/citadels/domain/BuildCard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package tw.waterballsa.gaas.citadels.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class BuildCard { | ||
private String name; | ||
private int coins; | ||
private Color color; | ||
|
||
public enum Color { | ||
PURPLE("特別地區"), | ||
YELLOW("貴族地區"), | ||
RED("軍事地區"), | ||
BLUE("商業地區"), | ||
GREEN("宗教地區"); | ||
private final String area; | ||
|
||
Color(String area) { | ||
this.area = area; | ||
} | ||
} | ||
|
||
} | ||
|
11 changes: 11 additions & 0 deletions
11
packages/backend/domain/src/main/java/tw/waterballsa/gaas/citadels/domain/CharacterCard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package tw.waterballsa.gaas.citadels.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class CharacterCard { | ||
private int sequence; | ||
private String name; | ||
} |
119 changes: 119 additions & 0 deletions
119
packages/backend/domain/src/main/java/tw/waterballsa/gaas/citadels/domain/Game.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package tw.waterballsa.gaas.citadels.domain; | ||
|
||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static java.util.UUID.randomUUID; | ||
import static tw.waterballsa.gaas.citadels.domain.Game.Status.PLAYING; | ||
|
||
|
||
@Getter | ||
public class Game { | ||
private final String id; | ||
private final String roomId; | ||
private final String name; | ||
private final Status status; | ||
private final LocalDateTime createTime; | ||
private final List<Player> players; | ||
private final List<CharacterCard> characterCards; | ||
private final List<BuildCard> buildCards; | ||
public static final Integer DEFAULT_COINS = 2; | ||
public static final Integer DEFAULT_CARD_QUANTITY = 2; | ||
|
||
public Game(String roomId, String name, List<Player> players, List<CharacterCard> characterCards, List<BuildCard> buildCards) { | ||
this.id = randomUUID().toString(); | ||
this.roomId = roomId; | ||
this.name = name; | ||
this.createTime = LocalDateTime.now(); | ||
this.players = players; | ||
this.status = PLAYING; | ||
this.characterCards = characterCards; | ||
this.buildCards = buildCards; | ||
} | ||
|
||
public Game(String id, String roomId, String name, Status status, | ||
LocalDateTime createTime, List<Player> players, List<CharacterCard> characterCards, | ||
List<BuildCard> buildCards) { | ||
this.id = id; | ||
this.roomId = roomId; | ||
this.name = name; | ||
this.status = status; | ||
this.createTime = createTime; | ||
this.players = players; | ||
this.characterCards = characterCards; | ||
this.buildCards = buildCards; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getRoomId() { | ||
return roomId; | ||
} | ||
|
||
public Status getStatus() { | ||
return status; | ||
} | ||
|
||
public List<Player> getPlayers() { | ||
return players; | ||
} | ||
|
||
|
||
public LocalDateTime getCreateTime() { | ||
return createTime; | ||
} | ||
|
||
public void randomlyAwardCrownToOnePlayer() { | ||
Collections.shuffle(players); | ||
Player kingPlayer = players.get(0); | ||
kingPlayer.acquireCrown(); | ||
} | ||
|
||
public void start() { | ||
randomlyAwardCrownToOnePlayer(); | ||
distributingCardsAndCoinsToEachPlayer(); | ||
} | ||
|
||
private void distributingCardsAndCoinsToEachPlayer() { | ||
players.forEach(player -> { | ||
player.plusCards(getTwoCards()); | ||
player.plusCoins(2); | ||
}); | ||
|
||
} | ||
|
||
public List<BuildCard> getTwoCards(){ | ||
return Arrays.asList(new BuildCard("test",3, BuildCard.Color.BLUE) | ||
,new BuildCard("test",2, BuildCard.Color.BLUE)); | ||
} | ||
|
||
public enum Status { | ||
PLAYING, | ||
CLOSE | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Game{" + | ||
"id='" + id + '\'' + | ||
", roomId='" + roomId + '\'' + | ||
", name='" + name + '\'' + | ||
", status=" + status + | ||
", createTime=" + createTime + | ||
", players=" + players + | ||
", districtCards=" + buildCards + | ||
'}'; | ||
} | ||
} | ||
|
||
|
25 changes: 25 additions & 0 deletions
25
...rc/main/java/tw/waterballsa/gaas/citadels/spring/controllers/viewmodel/BuildCardView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package tw.waterballsa.gaas.citadels.spring.controllers.viewmodel; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import tw.waterballsa.gaas.citadels.domain.BuildCard; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class BuildCardView { | ||
private String name; | ||
private int coins; | ||
private BuildCard.Color color; | ||
|
||
public static List<BuildCardView> toViewModels(List<BuildCard> buildCards) { | ||
return buildCards.stream().map(BuildCardView::toViewModel).collect(Collectors.toList()); | ||
} | ||
|
||
public static BuildCardView toViewModel(BuildCard buildCard) { | ||
return new BuildCardView(buildCard.getName(), buildCard.getCoins(), buildCard.getColor()); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...ain/java/tw/waterballsa/gaas/citadels/spring/controllers/viewmodel/CharacterCardView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package tw.waterballsa.gaas.citadels.spring.controllers.viewmodel; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import tw.waterballsa.gaas.citadels.domain.CharacterCard; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class CharacterCardView { | ||
private int sequence; | ||
private String name; | ||
|
||
public static CharacterCardView toViewModel(CharacterCard characterCard) { | ||
return (characterCard != null) ? new CharacterCardView(characterCard.getSequence(), characterCard.getName()) : null; | ||
} | ||
|
||
public static List<CharacterCardView> toViewModels(List<CharacterCard> characterCards) { | ||
return characterCards.stream().map(CharacterCardView::toViewModel).collect(Collectors.toList()); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ng/src/main/java/tw/waterballsa/gaas/citadels/spring/repositories/data/BuildCardData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package tw.waterballsa.gaas.citadels.spring.repositories.data; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
import tw.waterballsa.gaas.citadels.domain.BuildCard; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
@Document | ||
@AllArgsConstructor | ||
public class BuildCardData { | ||
@Id | ||
private String name; | ||
private int coins; | ||
private BuildCard.Color color; | ||
|
||
public static BuildCardData toData(BuildCard buildCard) { | ||
return new BuildCardData(buildCard.getName(), buildCard.getCoins(), buildCard.getColor()); | ||
} | ||
|
||
public static List<BuildCardData> toData(List<BuildCard> buildCards) { | ||
return buildCards.stream().map(BuildCardData::toData).collect(Collectors.toList()); | ||
} | ||
|
||
public static BuildCard toDomain(BuildCardData buildCardData) { | ||
return new BuildCard(buildCardData.getName(), buildCardData.getCoins(), buildCardData.getColor()); | ||
} | ||
|
||
public static List<BuildCard> toDomains(List<BuildCardData> buildCardDataList) { | ||
return buildCardDataList.stream().map(BuildCardData::toDomain).collect(Collectors.toList()); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...rc/main/java/tw/waterballsa/gaas/citadels/spring/repositories/data/CharacterCardData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package tw.waterballsa.gaas.citadels.spring.repositories.data; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
import tw.waterballsa.gaas.citadels.domain.CharacterCard; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
@Document | ||
@AllArgsConstructor | ||
public class CharacterCardData { | ||
@Id | ||
private int sequence; | ||
private String name; | ||
|
||
public static CharacterCardData toData(CharacterCard characterCard) { | ||
return (characterCard != null) ? new CharacterCardData(characterCard.getSequence(), characterCard.getName()) : null; | ||
} | ||
|
||
public static List<CharacterCardData> toData(List<CharacterCard> characterCards) { | ||
return characterCards.stream().map(CharacterCardData::toData).collect(Collectors.toList()); | ||
} | ||
|
||
public static CharacterCard toDomain(CharacterCardData characterCardData) { | ||
return characterCardData != null ? new CharacterCard(characterCardData.getSequence(), characterCardData.getName()) : null; | ||
} | ||
|
||
public static Map<Integer, CharacterCard> toDomains(List<CharacterCardData> characterCardDataList) { | ||
Map<Integer, CharacterCard> cards = new LinkedHashMap<>(); | ||
characterCardDataList.forEach(characterCardData -> cards.put(characterCardData.getSequence(), toDomain(characterCardData))); | ||
return cards; | ||
} | ||
|
||
public static List<CharacterCard> toDomainList(List<CharacterCardData> characterCardDataList) { | ||
return characterCardDataList.stream().map(CharacterCardData::toDomain).collect(Collectors.toList()); | ||
} | ||
} |