Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
naomod
Object-Oriented Software Analysis and Design (OOAD)
Projet 2020 - Not Alone
Commits
a60e88b2
Commit
a60e88b2
authored
Dec 04, 2020
by
Corentin Guillevic
Browse files
Small refactoring
parent
7cd1354f
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
not-alone-server/src/main/java/fr/univnantes/alma/server/game/PowerApplicator.java
View file @
a60e88b2
This diff is collapsed.
Click to expand it.
not-alone-server/src/main/java/fr/univnantes/alma/server/game/item/power/recurrent/PowerRecurrent.java
View file @
a60e88b2
package
fr.univnantes.alma.server.game.item.power.recurrent
;
import
fr.univnantes.alma.server.game.Game
;
import
fr.univnantes.alma.server.game.item.Phase
;
import
fr.univnantes.alma.server.game.item.power.Power
;
import
fr.univnantes.alma.server.game.item.power.PowerType
;
import
java.util.function.BiConsumer
;
import
java.util.function.Bi
Function
;
import
java.util.function.Bi
Predicate
;
public
class
PowerRecurrent
extends
Power
{
private
BiConsumer
<
Integer
,
Game
>
action
;
private
BiFunction
<
Integer
,
Game
,
Boolean
>
condition
;
private
Phase
phase
;
private
final
BiConsumer
<
Integer
,
Game
>
action
;
private
final
BiPredicate
<
Integer
,
Game
>
condition
;
public
PowerRecurrent
(
int
inGameIdPlayer
,
BiConsumer
<
Integer
,
Game
>
action
,
Bi
Function
<
Integer
,
Game
,
Boolean
>
condition
)
{
public
PowerRecurrent
(
int
inGameIdPlayer
,
BiConsumer
<
Integer
,
Game
>
action
,
Bi
Predicate
<
Integer
,
Game
>
condition
)
{
super
(
inGameIdPlayer
);
this
.
action
=
action
;
this
.
condition
=
condition
;
...
...
@@ -25,7 +23,7 @@ public class PowerRecurrent extends Power {
}
public
boolean
conditionIsTrue
(
Game
game
)
{
return
condition
.
apply
(
inGameIdPlayer
,
game
);
return
condition
.
test
(
inGameIdPlayer
,
game
);
}
@Override
...
...
not-alone-server/src/test/java/fr/univnantes/alma/server/PowerApplicatorTest.java
→
not-alone-server/src/test/java/fr/univnantes/alma/server/
game/
PowerApplicatorTest.java
View file @
a60e88b2
package
fr.univnantes.alma.server
;
package
fr.univnantes.alma.server
.game
;
import
fr.univnantes.alma.common.NotAloneDatabase
;
import
fr.univnantes.alma.data.DatabaseFactory
;
...
...
@@ -1404,6 +1404,33 @@ class PowerApplicatorTest {
assertEquals
(
Collections
.
singletonList
(
nexus
),
traque
.
getPlaceCards
());
}
@Test
void
testResolvePlace_archipelCantPickSurvivalCard
()
throws
TException
{
Game
game
=
new
Game
(
2
,
1
,
planetExtension
,
board
,
room
,
gameClientHandler
);
game
.
setTraqueCanPickSurvivalCards
(
false
);
TAction
chooseADefausseCard
=
new
TAction
(
CHOOSE_CARD
.
toString
(),
Collections
.
singletonList
(
new
TPair
(
TPairType
.
CARD
.
toString
(),
NEXUS
.
toString
())));
when
(
gameClientHandler
.
askAction
(
any
(
TAskAction
.
class
)))
.
thenReturn
(
chooseSecondPower
)
.
thenReturn
(
chooseADefausseCard
);
Traque
traque
=
(
Traque
)
game
.
getPlayer
(
2
);
List
<
PlaceCard
>
throwAwayCards
=
Arrays
.
asList
(
nexus
,
oasis
,
fjord
,
dome
,
labyrinthe
);
traque
.
throwAwayPlaceCard
(
throwAwayCards
);
traque
.
addPlaceCard
(
archipel
);
traque
.
playPlaceCard
(
archipel
);
PowerApplicator
.
resolvePlace
(
traque
.
getInGameId
(),
archipel
,
game
);
//Verify that traque has only Nexus
assertEquals
(
Collections
.
singletonList
(
nexus
),
traque
.
getPlaceCards
());
}
@Test
void
testResolvePlace_poleFirstPower
()
throws
TException
,
NotFoundException
{
Game
game
=
new
Game
(
2
,
1
,
planetExtension
,
board
,
room
,
gameClientHandler
);
...
...
@@ -1533,6 +1560,64 @@ class PowerApplicatorTest {
assertEquals
(
Collections
.
singletonList
(
nexus
),
traque
.
getPlaceCards
());
}
@Test
void
testResolvePlace_fungiFistPowerCantPickSurvival
()
throws
TException
{
Game
game
=
new
Game
(
2
,
1
,
planetExtension
,
board
,
room
,
gameClientHandler
);
game
.
setTraqueCanPickSurvivalCards
(
false
);
when
(
gameClientHandler
.
askAction
(
any
(
TAskAction
.
class
)))
.
thenReturn
(
chooseFirstPower
);
Traque
traque
=
(
Traque
)
game
.
getPlayer
(
2
);
traque
.
subWillingness
(
2
);
List
<
PlaceCard
>
throwAwayCards
=
Arrays
.
asList
(
nexus
,
oasis
,
fjord
,
dome
,
labyrinthe
);
traque
.
throwAwayPlaceCard
(
throwAwayCards
);
traque
.
addPlaceCard
(
fungi
);
traque
.
playPlaceCard
(
fungi
);
PowerApplicator
.
resolvePlace
(
traque
.
getInGameId
(),
fungi
,
game
);
assertTrue
(
game
.
getGameRoundVariables
().
isPawnWillingnessOnBoard
());
game
.
nextRound
();
assertEquals
(
2
,
traque
.
getNumberWillingness
());
assertTrue
(
game
.
getGameRoundVariables
().
isPawnWillingnessOnBoard
());
game
.
nextRound
();
assertEquals
(
3
,
traque
.
getNumberWillingness
());
assertFalse
(
game
.
getGameRoundVariables
().
isPawnWillingnessOnBoard
());
}
@Test
void
testResolvePlace_fungiSecondPowerCantPickSurvival
()
throws
TException
{
Game
game
=
new
Game
(
2
,
1
,
planetExtension
,
board
,
room
,
gameClientHandler
);
game
.
setTraqueCanPickSurvivalCards
(
false
);
TAction
chooseADefausseCard
=
new
TAction
(
CHOOSE_CARD
.
toString
(),
Collections
.
singletonList
(
new
TPair
(
TPairType
.
CARD
.
toString
(),
NEXUS
.
toString
())));
when
(
gameClientHandler
.
askAction
(
any
(
TAskAction
.
class
)))
.
thenReturn
(
chooseSecondPower
)
.
thenReturn
(
chooseADefausseCard
);
Traque
traque
=
(
Traque
)
game
.
getPlayer
(
2
);
List
<
PlaceCard
>
throwAwayCards
=
Arrays
.
asList
(
nexus
,
oasis
,
fjord
,
dome
,
labyrinthe
);
traque
.
throwAwayPlaceCard
(
throwAwayCards
);
traque
.
addPlaceCard
(
fungi
);
traque
.
playPlaceCard
(
fungi
);
PowerApplicator
.
resolvePlace
(
traque
.
getInGameId
(),
fungi
,
game
);
//Verify that traque has only Nexus
assertEquals
(
Collections
.
singletonList
(
nexus
),
traque
.
getPlaceCards
());
}
@Test
void
testResolvePlace_PortailFirstPower
()
throws
TException
{
Game
game
=
new
Game
(
2
,
1
,
planetExtension
,
board
,
room
,
gameClientHandler
);
...
...
@@ -2163,6 +2248,23 @@ class PowerApplicatorTest {
assertTrue
(
planet
.
isBlockedPlace
(
antre
));
}
@Test
void
testApplyPlayerCard_flashbackTrackingTrashEmpty
()
throws
TException
{
Game
game
=
new
Game
(
2
,
1
,
planet
,
board
,
room
,
gameClientHandler
);
TrackingCard
desespoir
=
database
.
findTrackingCard
(
DESESPOIR
.
toString
());
TrackingCard
flashback
=
database
.
findTrackingCard
(
FLASHBACK
.
toString
());
TrackingCard
cataclysme
=
database
.
findTrackingCard
(
CATACLYSME
.
toString
());
Creature
creature
=
game
.
getCreature
();
creature
.
getTrackingCardHand
().
clear
();
creature
.
addTrackingCard
(
flashback
);
assertTrue
(
game
.
playerPlayCard
(
creature
.
getInGameId
(),
flashback
).
state
);
}
@Test
void
testApplyPlayerCard_gargantua
()
{
Game
game
=
new
Game
(
3
,
1
,
planet
,
board
,
room
,
gameClientHandler
);
...
...
@@ -3010,16 +3112,18 @@ class PowerApplicatorTest {
@Test
void
testApplyPlayerCard_amplificateurWithExtension
()
{
Game
game
=
new
Game
(
4
,
1
,
planetExtension
,
board
,
room
,
gameClientHandler
);
Game
game
=
new
Game
(
2
,
1
,
planetExtension
,
board
,
room
,
gameClientHandler
);
Traque
traque
=
(
Traque
)
game
.
getPlayer
(
2
);
planet
.
forceMovePlanetPawn
();
planet
.
forceMovePlanetPawn
();
planet
Extension
.
forceMovePlanetPawn
();
planet
Extension
.
forceMovePlanetPawn
();
PowerApplicator
.
applySurvivalCardPower
(
traque
.
getInGameId
(),
game
,
AMPLIFICATEUR
);
assertTrue
(
planet
.
planetPawnIsActive
());
Score
score
=
new
Score
(
2
);
score
.
moveBackCreature
(
1
);
assertEquals
(
score
,
game
.
getBoard
().
getScore
());
}
@Test
...
...
@@ -3184,6 +3288,21 @@ class PowerApplicatorTest {
assertTrue
(
traque
.
getSurvivalCardsHand
().
contains
(
survivalCard
));
}
@Test
void
testApplyPlayerCard_equipementCantPickSurvivalCard
()
throws
TException
{
Game
game
=
new
Game
(
2
,
1
,
planet
,
board
,
room
,
gameClientHandler
);
game
.
getGameRoundVariables
().
setTraqueCanPickSurvivalCards
(
false
);
SurvivalCard
survivalCard
=
game
.
getSurvivalCardPioche
().
getCards
().
get
(
0
);
Traque
traque
=
(
Traque
)
game
.
getPlayer
(
2
);
PowerApplicator
.
applySurvivalCardPower
(
traque
.
getInGameId
(),
game
,
EQUIPEMENT
);
assertFalse
(
traque
.
getSurvivalCardsHand
().
contains
(
survivalCard
));
}
@Test
void
testApplyPlayerCard_equipementFirstPower
()
throws
TException
{
Game
game
=
new
Game
(
2
,
1
,
planet
,
board
,
room
,
gameClientHandler
);
...
...
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