generated from Game-as-a-Service/Gaas-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add 4ColorsCard usecase #99
Open
ChanWu77
wants to merge
7
commits into
develop
Choose a base branch
from
add-fourColorUsecases
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1201a5a
add 4ColorsCard usecase
ChanWu77 a7da8c4
adjust functionName & redCardForestTest:playerA flipped Trainstation
9a936f4
add 4ColorsCard usecase
ChanWu77 951637f
adjust functionName & redCardForestTest:playerA flipped Trainstation
3e924c2
adjust Game isTwoDices into boolean value
65f1c58
Merge remote-tracking branch 'origin/add-fourColorUsecases' into add-…
16bf948
add four colors card usecases
ChanWu77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
package domain; | ||
|
||
import domain.card.establishment.AppleOrchard; | ||
import domain.card.establishment.Bakery; | ||
import domain.card.establishment.Cafe; | ||
import domain.card.establishment.ConvenienceStore; | ||
import domain.card.establishment.Establishment; | ||
import domain.card.establishment.WheatField; | ||
import domain.card.establishment.*; | ||
import domain.card.landmark.Landmark; | ||
import domain.card.landmark.ShoppingMall; | ||
import domain.card.landmark.TrainStation; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
@@ -22,6 +19,20 @@ | |
|
||
|
||
class GameTest { | ||
private Bank bank; | ||
private Player playerA; | ||
private Player playerB; | ||
private Player playerC; | ||
private Player playerD; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
playerA = Player.builder().id("A01").name("A").build(); | ||
playerB = Player.builder().id("B01").name("B").build(); | ||
playerC = Player.builder().id("C01").name("C").build(); | ||
playerD = Player.builder().id("D01").name("D").build(); | ||
bank = new Bank(); | ||
} | ||
|
||
@Test | ||
@DisplayName(""" | ||
|
@@ -78,13 +89,8 @@ private long getEstablishmentCount(Player player, Establishment establishment) { | |
|
||
@Test | ||
void test1() { | ||
Bank bank = new Bank(); | ||
var players = List.of(new Player("A"), new Player("B"), new Player("C"), new Player("D")); | ||
var players = List.of(playerA, playerB, playerC, playerD); | ||
Game game = new Game(bank, players, new Marketplace()); | ||
var playerA = players.get(0); | ||
var playerB = players.get(1); | ||
var playerC = players.get(2); | ||
var playerD = players.get(3); | ||
|
||
playerA.gainCoin(30); | ||
playerB.gainCoin(30); | ||
|
@@ -132,31 +138,182 @@ void test1() { | |
// given | ||
Dice dice = Mockito.mock(Dice.class); | ||
|
||
HandCard handCard = new HandCard(); | ||
handCard.addHandCard(new ConvenienceStore()); | ||
handCard.addHandCard(new ConvenienceStore()); | ||
handCard.flipLandMark(ShoppingMall.class); | ||
Player playerA = Player.builder().id("id").name("A").coins(0).handCard(handCard).build(); | ||
Landmark shoppingMall = playerA.getLandMark("購物中心"); | ||
playerA.addCardToHandCard(new ConvenienceStore()); | ||
playerA.addCardToHandCard(new ConvenienceStore()); | ||
//避免玩家沒有足夠的錢建造購物中心建築物 | ||
playerA.gainCoin(10); | ||
playerA.flipLandMark(shoppingMall, bank); | ||
|
||
Game game = Game.builder() | ||
.players(List.of(playerA)) | ||
.turnPlayer(playerA) | ||
.currentDicePoint(4) | ||
.dices(List.of(dice)) | ||
.bank(new Bank()) | ||
.bank(bank) | ||
.build(); | ||
|
||
var originalBankCoins = game.getBank().getTotalCoin(); | ||
|
||
// when | ||
Mockito.when(dice.throwDice()).thenReturn(4); | ||
game.rollDice(playerA.getId(), false); | ||
int covenienceSize = handCard.getEstablishments(ConvenienceStore.class).size(); | ||
int covenienceSize = playerA.getHandCard().getEstablishments().stream() | ||
.mapToInt(e -> e instanceof ConvenienceStore ? 1 : 0) | ||
.sum(); | ||
|
||
// then | ||
var effectCoins = (ConvenienceStore.EFFECT_COINS + ShoppingMall.BONUS) * covenienceSize; | ||
assertThat(playerA.getTotalCoins()).isEqualTo(effectCoins); | ||
assertThat(game.getBank().getTotalCoin()).isEqualTo(originalBankCoins - effectCoins); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName(""" | ||
當玩家B有2張麵包店,且輪到B擲骰子 | ||
當骰子擲出點數為2時 | ||
B可以從銀行得到2元 | ||
""") | ||
void greenCardbackeryCardTest() { | ||
// given | ||
Dice dice = Mockito.mock(Dice.class); | ||
|
||
playerB.addCardToHandCard(new Bakery()); | ||
playerB.addCardToHandCard(new Bakery()); | ||
|
||
Game game = Game.builder() | ||
.players(List.of(playerB)) | ||
.turnPlayer(playerB) | ||
.currentDicePoint(2) | ||
.dices(List.of(dice)) | ||
.bank(bank) | ||
.build(); | ||
|
||
var originalBankCoins = game.getBank().getTotalCoin(); | ||
|
||
// when | ||
Mockito.when(dice.throwDice()).thenReturn(2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
game.rollDice(playerB.getId(), false); | ||
|
||
// then | ||
//TODO 命名為具有領域意義的名稱,會更好理解 | ||
int totalBakeryBonuses = playerB.getHandCard().getEstablishments().stream() | ||
.mapToInt(e -> e instanceof Bakery ? 1 : 0) | ||
.sum(); | ||
assertThat(playerB.getTotalCoins()).isEqualTo(totalBakeryBonuses); | ||
assertThat(game.getBank().getTotalCoin()).isEqualTo(originalBankCoins - totalBakeryBonuses); | ||
} | ||
|
||
@Test | ||
@DisplayName(""" | ||
當玩家A有2張麵包店,且輪到A擲骰子 | ||
當玩家B有2張森林 | ||
當玩家C有1張森林 | ||
當A骰子擲出點數為5時, | ||
B可以從銀行得到2元,C可以從銀行得到1元 | ||
""") | ||
void buleCardForestTest() { | ||
// given | ||
Dice dice = Mockito.mock(Dice.class); | ||
|
||
playerA.addCardToHandCard(new Bakery()); | ||
playerA.addCardToHandCard(new Bakery()); | ||
playerB.addCardToHandCard(new Forest()); | ||
playerB.addCardToHandCard(new Forest()); | ||
playerC.addCardToHandCard(new Forest()); | ||
|
||
Game game = Game.builder() | ||
.players(List.of(playerA, playerB, playerC)) | ||
.turnPlayer(playerA) | ||
.currentDicePoint(5) | ||
.dices(List.of(dice)) | ||
.bank(bank) | ||
.build(); | ||
|
||
var originalBankCoins = game.getBank().getTotalCoin(); | ||
|
||
// when | ||
Mockito.when(dice.throwDice()).thenReturn(5); | ||
game.rollDice(playerA.getId(), false); | ||
|
||
// then | ||
assertThat(playerA.getTotalCoins()).isEqualTo(0); | ||
assertThat(playerB.getTotalCoins()).isEqualTo(2); | ||
assertThat(playerC.getTotalCoins()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
@DisplayName(""" | ||
當玩家A有1張體育館,且輪到A擲骰子 | ||
當玩家B有10元 | ||
當玩家C有6元 | ||
當A骰子擲出點數為6時, | ||
B跟C玩家各自要給A 2元 | ||
""") | ||
void purpleStatdiumTest() { | ||
// given | ||
Dice dice = Mockito.mock(Dice.class); | ||
Stadium stadium = new Stadium(); | ||
|
||
playerA.addCardToHandCard(stadium); | ||
playerB.gainCoin(10); | ||
playerC.gainCoin(6); | ||
|
||
Game game = Game.builder() | ||
.players(List.of(playerA, playerB, playerC)) | ||
.turnPlayer(playerA) | ||
.currentDicePoint(6) | ||
.dices(List.of(dice)) | ||
.bank(bank) | ||
.build(); | ||
|
||
var originalBankCoins = game.getBank().getTotalCoin(); | ||
|
||
// when | ||
Mockito.when(dice.throwDice()).thenReturn(6); | ||
game.rollDice(playerA.getId(), false); | ||
// then | ||
assertThat(playerA.getTotalCoins()).isEqualTo(4); | ||
assertThat(playerB.getTotalCoins()).isEqualTo(8); | ||
assertThat(playerC.getTotalCoins()).isEqualTo(4); | ||
} | ||
|
||
@Test | ||
@DisplayName(""" | ||
當玩家A有2張麵包店、火車站跟10元,且輪到A擲骰子 | ||
當玩家B有1張家庭餐廳 | ||
當A骰子擲出點數為10時, | ||
A要給B 2塊 | ||
""") | ||
void redCardFamilyRestaurantTest() { | ||
// given | ||
Dice dice1 = Mockito.mock(Dice.class); | ||
Dice dice2 = Mockito.mock(Dice.class); | ||
playerA.addCardToHandCard(new Bakery()); | ||
playerA.addCardToHandCard(new Bakery()); | ||
|
||
Landmark trainStation = playerA.getLandMark("火車站"); | ||
//避免玩家沒有足夠的錢建造購物中心建築物 | ||
playerA.gainCoin(10); | ||
playerA.flipLandMark(trainStation, bank); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
playerB.addCardToHandCard(new FamilyRestaurant()); | ||
|
||
Game game = Game.builder() | ||
.players(List.of(playerA, playerB)) | ||
.turnPlayer(playerA) | ||
.currentDicePoint(10) | ||
.dices(List.of(dice1, dice2)) | ||
.bank(bank)//這裡不是很確定 | ||
.build(); | ||
|
||
// when | ||
Mockito.when(dice1.throwDice()).thenReturn(5); | ||
Mockito.when(dice2.throwDice()).thenReturn(5); | ||
game.rollDice(playerA.getId(), true); | ||
|
||
//then | ||
assertThat(playerA.getTotalCoins()).isEqualTo(4);//10-4-2 | ||
assertThat(playerB.getTotalCoins()).isEqualTo(2); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放在 mock 骰子物件下方。
這不是 when 的程式碼,而是 given 模擬的資料。
整個檔案出現類似的程式碼都套用這個規則