Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Not Alone
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mamadou Saliou DIALLO
Not Alone
Commits
0deb14b9
Commit
0deb14b9
authored
Dec 08, 2020
by
Mamadou Saliou DIALLO
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: implement test for Creature and Tracked
parent
c30b5bf4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
231 additions
and
1 deletion
+231
-1
not-alone-server/src/main/java/fr/univnantes/alma/model/player/Creature.java
...c/main/java/fr/univnantes/alma/model/player/Creature.java
+115
-0
not-alone-server/src/main/java/fr/univnantes/alma/model/player/Player.java
...src/main/java/fr/univnantes/alma/model/player/Player.java
+1
-0
not-alone-server/src/main/java/fr/univnantes/alma/model/player/Tracked.java
...rc/main/java/fr/univnantes/alma/model/player/Tracked.java
+114
-0
not-alone-server/src/test/java/fr/univnantes/alma/model/player/TrackedTest.java
...est/java/fr/univnantes/alma/model/player/TrackedTest.java
+1
-1
No files found.
not-alone-server/src/main/java/fr/univnantes/alma/model/player/Creature.java
View file @
0deb14b9
...
...
@@ -7,11 +7,23 @@ import fr.univnantes.alma.references.associations.BidirectionalOneToOne;
import
fr.univnantes.alma.references.interfaces.OneToManyAssociation
;
import
fr.univnantes.alma.references.interfaces.OneToOneAssociation
;
import
java.util.List
;
/**
* Single Creature game player.
*/
public
class
Creature
extends
Player
{
/**
* Initial size of player hands.
*/
public
static
final
int
INIT_HAND_SIZE
=
3
;
/**
* Max length of player hand.
*/
public
static
final
int
MAX_HAND_SIZE
=
3
;
/**
* Creature token.
*/
...
...
@@ -93,4 +105,107 @@ public class Creature extends Player {
public
OneToManyAssociation
<
Creature
,
TrackingCard
>
getDiscard
()
{
return
discard
;
}
/**
* Add place card to the hand.
* @param card card to add
* @return true if the card is added and false otherwise
*/
public
Boolean
addCardToHand
(
TrackingCard
card
)
{
if
(
card
==
null
)
{
throw
new
IllegalArgumentException
(
"Card can't be null"
);
}
if
(
hand
.
size
()
>
MAX_HAND_SIZE
)
{
return
false
;
}
if
(
hand
.
contains
(
card
))
{
throw
new
IllegalArgumentException
(
"Card already in hand"
);
}
return
hand
.
add
(
card
);
}
/**
* Remove Place from hand.
* @param card card to remove
* @return true if the card is removed and false otherwise
*/
public
Boolean
removeCardFromHand
(
TrackingCard
card
)
{
if
(
card
==
null
)
{
throw
new
IllegalArgumentException
(
"Card can't be null"
);
}
return
hand
.
remove
(
card
);
}
/**
* Remove card form player hand and put it to his discard.
* @param card card to discard
* @return true if the card is discarded and false otherwise
*/
public
Boolean
discard
(
TrackingCard
card
)
{
if
(!
hand
.
contains
(
card
))
{
throw
new
IllegalArgumentException
(
"Card not exist in player hand"
);
}
if
(
discard
.
size
()
>=
MAX_HAND_SIZE
)
{
return
false
;
}
hand
.
remove
(
card
);
return
discard
.
add
(
card
);
}
/**
* Remove card form player discard and put it to his hand.
* @param card card to put in the hand
* @return true if the card is added to hand and false otherwise
*/
public
Boolean
putCardBackInHand
(
TrackingCard
card
)
{
if
(!
discard
.
contains
(
card
))
{
throw
new
IllegalArgumentException
(
"Card not exist in player discard"
);
}
if
(
hand
.
size
()
>=
MAX_HAND_SIZE
)
{
return
false
;
}
discard
.
remove
(
card
);
return
hand
.
add
(
card
);
}
/**
* Player hand size.
* @return Hand size
*/
public
int
getHandSize
()
{
return
hand
.
size
();
}
/**
* Player discard size.
* @return discard size
*/
public
int
getDiscardSize
()
{
return
discard
.
size
();
}
/**
* Init player hand with place cards.
* @param cards Card List
*/
public
void
initHand
(
List
<
TrackingCard
>
cards
)
{
if
(
cards
==
null
)
{
throw
new
IllegalArgumentException
(
"Card list cannot be null"
);
}
if
(
cards
.
size
()
!=
INIT_HAND_SIZE
)
{
throw
new
IllegalArgumentException
(
"Card list must be exactly "
+
INIT_HAND_SIZE
);
}
if
(
hand
.
size
()
>
0
)
{
throw
new
UnsupportedOperationException
(
"Hand already initialized"
);
}
hand
.
addAll
(
cards
);
}
}
not-alone-server/src/main/java/fr/univnantes/alma/model/player/Player.java
View file @
0deb14b9
...
...
@@ -4,6 +4,7 @@ package fr.univnantes.alma.model.player;
* Single game player.
*/
public
abstract
class
Player
{
/**
* Player state.
*/
...
...
not-alone-server/src/main/java/fr/univnantes/alma/model/player/Tracked.java
View file @
0deb14b9
...
...
@@ -5,10 +5,21 @@ import fr.univnantes.alma.model.card.place.PlaceCard;
import
fr.univnantes.alma.references.associations.BidirectionalOneToMany
;
import
fr.univnantes.alma.references.interfaces.OneToManyAssociation
;
import
java.util.List
;
/**
* Single Tracked game player.
*/
public
class
Tracked
extends
Player
{
/**
* Initial size of player hands.
*/
public
static
final
int
INIT_HAND_SIZE
=
5
;
/**
* Max length of player hand.
*/
public
static
final
int
MAX_HAND_SIZE
=
10
;
/**
* Tracked player hand.
...
...
@@ -63,4 +74,107 @@ public class Tracked extends Player {
public
OneToManyAssociation
<
Tracked
,
Pawn
>
getPawns
()
{
return
pawns
;
}
/**
* Add place card to the hand.
* @param card card to add
* @return true if the card is added and false otherwise
*/
public
Boolean
addCardToHand
(
PlaceCard
card
)
{
if
(
card
==
null
)
{
throw
new
IllegalArgumentException
(
"Card can't be null"
);
}
if
(
hand
.
size
()
>
MAX_HAND_SIZE
)
{
return
false
;
}
if
(
hand
.
contains
(
card
))
{
throw
new
IllegalArgumentException
(
"Card already in hand"
);
}
return
hand
.
add
(
card
);
}
/**
* Remove Place from hand.
* @param card card to remove
* @return true if the card is removed and false otherwise
*/
public
Boolean
removeCardFromHand
(
PlaceCard
card
)
{
if
(
card
==
null
)
{
throw
new
IllegalArgumentException
(
"Card can't be null"
);
}
return
hand
.
remove
(
card
);
}
/**
* Remove card form player hand and put it to his discard.
* @param card card to discard
* @return true if the card is discarded and false otherwise
*/
public
Boolean
discard
(
PlaceCard
card
)
{
if
(!
hand
.
contains
(
card
))
{
throw
new
IllegalArgumentException
(
"Card not exist in player hand"
);
}
if
(
discard
.
size
()
>=
MAX_HAND_SIZE
)
{
return
false
;
}
hand
.
remove
(
card
);
return
discard
.
add
(
card
);
}
/**
* Remove card form player discard and put it to his hand.
* @param card card to put in the hand
* @return true if the card is added to hand and false otherwise
*/
public
Boolean
putCardBackInHand
(
PlaceCard
card
)
{
if
(!
discard
.
contains
(
card
))
{
throw
new
IllegalArgumentException
(
"Card not exist in player discard"
);
}
if
(
hand
.
size
()
>=
MAX_HAND_SIZE
)
{
return
false
;
}
discard
.
remove
(
card
);
return
hand
.
add
(
card
);
}
/**
* Player hand size.
* @return Hand size
*/
public
int
getHandSize
()
{
return
hand
.
size
();
}
/**
* Player discard size.
* @return discard size
*/
public
int
getDiscardSize
()
{
return
discard
.
size
();
}
/**
* Init player hand with place cards.
* @param cards Card List
*/
public
void
initHand
(
List
<
PlaceCard
>
cards
)
{
if
(
cards
==
null
)
{
throw
new
IllegalArgumentException
(
"Card list cannot be null"
);
}
if
(
cards
.
size
()
!=
INIT_HAND_SIZE
)
{
throw
new
IllegalArgumentException
(
"Card list must be exactly "
+
INIT_HAND_SIZE
);
}
if
(
hand
.
size
()
>
0
)
{
throw
new
UnsupportedOperationException
(
"Hand already initialized"
);
}
hand
.
addAll
(
cards
);
}
}
not-alone-server/src/test/java/fr/univnantes/alma/model/player/TrackedTest.java
View file @
0deb14b9
...
...
@@ -251,7 +251,7 @@ class TrackedTest {
});
/**
* (2) When card list size is different to {@link
Player
#INIT_HAND_SIZE}.
* (2) When card list size is different to {@link
Tracked
#INIT_HAND_SIZE}.
*/
int
expectedSize
=
cards1
.
size
()
-
1
;
cards1
.
remove
(
0
);
...
...
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