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
3b33b9d2
Commit
3b33b9d2
authored
Dec 11, 2020
by
Mamadou Saliou DIALLO
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://gitlab.univ-nantes.fr/E18C764T/projet-2020
parents
85473dd0
477de5b4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
150 additions
and
5 deletions
+150
-5
not-alone-core/src/main/thrift/game-service.thrift
not-alone-core/src/main/thrift/game-service.thrift
+1
-1
not-alone-server/src/main/java/fr/univnantes/alma/game/Game.java
...ne-server/src/main/java/fr/univnantes/alma/game/Game.java
+142
-3
not-alone-server/src/main/java/fr/univnantes/alma/game/GameController.java
...src/main/java/fr/univnantes/alma/game/GameController.java
+1
-1
not-alone-server/src/main/java/fr/univnantes/alma/model/card/place/BasicPlaceCard.java
...a/fr/univnantes/alma/model/card/place/BasicPlaceCard.java
+6
-0
No files found.
not-alone-core/src/main/thrift/game-service.thrift
View file @
3b33b9d2
...
...
@@ -18,7 +18,7 @@ service GameService {
common.Response resits(common.Player hunted)
common.Response
to
Go(common.Player hunted)
common.Response
let
Go(common.Player hunted)
common.Response playPlaceCard(common.Player hunted, common.Card card)
...
...
not-alone-server/src/main/java/fr/univnantes/alma/game/Game.java
View file @
3b33b9d2
...
...
@@ -2,12 +2,21 @@ package fr.univnantes.alma.game;
import
fr.univnantes.alma.common.GameJoinRequest
;
import
fr.univnantes.alma.model.BoardGame
;
import
fr.univnantes.alma.model.card.BasicCard
;
import
fr.univnantes.alma.model.card.place.*
;
import
fr.univnantes.alma.model.card.player.survival.*
;
import
fr.univnantes.alma.model.card.player.track.*
;
import
fr.univnantes.alma.references.associations.BidirectionalOneToOne
;
import
fr.univnantes.alma.references.interfaces.OneToOneAssociation
;
import
fr.univnantes.alma.thrift.Board
;
import
fr.univnantes.alma.thrift.InvalidOperationException
;
import
fr.univnantes.alma.thrift.Player
;
import
org.atlanmod.commons.log.Log
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.atomic.AtomicInteger
;
...
...
@@ -26,6 +35,11 @@ public class Game {
* The id of the game
*/
private
int
id
;
/**
* The creator of the game
*/
private
Player
creator
;
/**
* Counter used to increment player identifications.
*/
...
...
@@ -41,6 +55,11 @@ public class Game {
*/
private
final
Map
<
Integer
,
Player
>
players
=
new
HashMap
<>();
/**
* The player who is the creature
*/
private
Player
creature
;
/**
* Thread play.
*/
...
...
@@ -51,20 +70,117 @@ public class Game {
*/
private
OneToOneAssociation
<
Game
,
BoardGame
>
boardGame
;
/**
* Deck of survival cards
*/
private
List
<
BasicSurvivalCard
>
survivalCardsDeck
;
/**
* Deck of tracking cards
*/
private
List
<
BasicTrackingCard
>
trackingCardsDeck
;
/**
* Deck of reserve
*/
private
List
<
BasicPlaceCard
>
reserve
;
/**
* Create new instance of game.
* @param expectedPlayersForGame Expected players
*/
public
Game
(
int
expectedPlayersForGame
,
int
id
)
{
public
Game
(
Player
creator
,
int
expectedPlayersForGame
,
int
id
)
{
this
.
creator
=
creator
;
this
.
expectedPlayers
=
new
AtomicInteger
(
expectedPlayersForGame
);
this
.
id
=
id
;
this
.
requests
=
new
ArrayBlockingQueue
<
GameJoinRequest
>(
expectedPlayersForGame
);
boardGame
=
new
BidirectionalOneToOne
<>(
this
,
BoardGame:
:
getGame
);
initilizationSurvivalCards
();
initializationTrackCards
();
initializationReserve
();
play
=
new
Thread
(()
->
this
.
start
());
play
.
start
();
}
private
void
initilizationSurvivalCards
(){
this
.
survivalCardsDeck
.
add
(
new
DodgeCard
());
this
.
survivalCardsDeck
.
add
(
new
FlipFlopCard
());
this
.
survivalCardsDeck
.
add
(
new
RisposteCard
());
this
.
survivalCardsDeck
.
add
(
new
VortexCard
());
}
private
void
initializationTrackCards
(){
this
.
trackingCardsDeck
.
add
(
new
AnguishCard
());
this
.
trackingCardsDeck
.
add
(
new
AnticipationCard
());
this
.
trackingCardsDeck
.
add
(
new
CataclysmCard
());
this
.
trackingCardsDeck
.
add
(
new
CloneCard
());
this
.
trackingCardsDeck
.
add
(
new
DeploymentCard
());
this
.
trackingCardsDeck
.
add
(
new
DespairCard
());
this
.
trackingCardsDeck
.
add
(
new
DetourCard
());
this
.
trackingCardsDeck
.
add
(
new
DominationCard
());
this
.
trackingCardsDeck
.
add
(
new
DreadCard
());
this
.
trackingCardsDeck
.
add
(
new
EpidemicCard
());
this
.
trackingCardsDeck
.
add
(
new
FlashBackCard
());
this
.
trackingCardsDeck
.
add
(
new
ForceFieldCard
());
this
.
trackingCardsDeck
.
add
(
new
GargantuaCard
());
this
.
trackingCardsDeck
.
add
(
new
GripCard
());
this
.
trackingCardsDeck
.
add
(
new
HarassementCard
());
this
.
trackingCardsDeck
.
add
(
new
InertiaCard
());
this
.
trackingCardsDeck
.
add
(
new
InterferenceCard
());
this
.
trackingCardsDeck
.
add
(
new
IntuitionCard
());
this
.
trackingCardsDeck
.
add
(
new
MagnetismCard
());
this
.
trackingCardsDeck
.
add
(
new
MirageCard
());
this
.
trackingCardsDeck
.
add
(
new
MutationCard
());
this
.
trackingCardsDeck
.
add
(
new
PsychosisCard
());
this
.
trackingCardsDeck
.
add
(
new
QuicksandsCard
());
this
.
trackingCardsDeck
.
add
(
new
RelentlessnessCard
());
this
.
trackingCardsDeck
.
add
(
new
ReminiscenceCard
());
this
.
trackingCardsDeck
.
add
(
new
RestrictedZoneCard
());
this
.
trackingCardsDeck
.
add
(
new
ScreamsCard
());
this
.
trackingCardsDeck
.
add
(
new
SpottingCard
());
this
.
trackingCardsDeck
.
add
(
new
StasisCard
());
this
.
trackingCardsDeck
.
add
(
new
TelepathyCard
());
this
.
trackingCardsDeck
.
add
(
new
ThirstyForBloodCard
());
this
.
trackingCardsDeck
.
add
(
new
TimeRiftCard
());
this
.
trackingCardsDeck
.
add
(
new
TornadoCard
());
this
.
trackingCardsDeck
.
add
(
new
ToxinCard
());
this
.
trackingCardsDeck
.
add
(
new
UbiquityCard
());
this
.
trackingCardsDeck
.
add
(
new
VirusCard
());
}
private
void
initializationReserve
(){
int
nb_players
=
players
.
size
();
List
<
BasicPlaceCard
>
liste
=
new
ArrayList
<
BasicPlaceCard
>();
if
(
nb_players
==
2
){
liste
.
addAll
(
generateCard
(
SwampCard
.
class
.
getCanonicalName
(),
1
));
liste
.
addAll
(
generateCard
(
ShelterCard
.
class
.
getCanonicalName
(),
1
));
liste
.
addAll
(
generateCard
(
WreckCard
.
class
.
getCanonicalName
(),
1
));
liste
.
addAll
(
generateCard
(
SourceCard
.
class
.
getCanonicalName
(),
1
));
liste
.
addAll
(
generateCard
(
ArtefactCard
.
class
.
getCanonicalName
(),
1
));
}
else
if
(
nb_players
==
2
||
nb_players
==
3
){
liste
.
addAll
(
generateCard
(
SwampCard
.
class
.
getCanonicalName
(),
2
));
liste
.
addAll
(
generateCard
(
ShelterCard
.
class
.
getCanonicalName
(),
2
));
liste
.
addAll
(
generateCard
(
WreckCard
.
class
.
getCanonicalName
(),
2
));
liste
.
addAll
(
generateCard
(
SourceCard
.
class
.
getCanonicalName
(),
2
));
liste
.
addAll
(
generateCard
(
ArtefactCard
.
class
.
getCanonicalName
(),
2
));
}
else
if
(
nb_players
>=
4
||
nb_players
<=
6
){
liste
.
addAll
(
generateCard
(
SwampCard
.
class
.
getCanonicalName
(),
3
));
liste
.
addAll
(
generateCard
(
ShelterCard
.
class
.
getCanonicalName
(),
3
));
liste
.
addAll
(
generateCard
(
WreckCard
.
class
.
getCanonicalName
(),
3
));
liste
.
addAll
(
generateCard
(
SourceCard
.
class
.
getCanonicalName
(),
3
));
liste
.
addAll
(
generateCard
(
ArtefactCard
.
class
.
getCanonicalName
(),
3
));
}
reserve
.
addAll
(
liste
);
}
/**
* Set the creature
*/
public
void
setCreature
(
Player
creature
){
this
.
creature
=
creature
;
}
/**
* Join a game.
* @param request game join request
...
...
@@ -81,7 +197,7 @@ public class Game {
}
/**
* Lunch the game.
* L
a
unch the game.
*/
private
void
start
()
{
this
.
waitForPlayers
();
...
...
@@ -90,7 +206,7 @@ public class Game {
}
/**
* Wait for players until
expected players not
reached.
* Wait for players until
the expected number of players are
reached.
*/
private
void
waitForPlayers
()
{
Log
.
info
(
"Waiting for request. Expecting {0} players."
,
...
...
@@ -122,4 +238,27 @@ public class Game {
public
OneToOneAssociation
<
Game
,
BoardGame
>
getBoardGame
()
{
return
boardGame
;
}
private
List
<
BasicPlaceCard
>
generateCard
(
String
className
,
int
number
)
{
List
<
BasicPlaceCard
>
result
=
new
ArrayList
<>();
try
{
Class
clazz
=
Class
.
forName
(
className
);
Constructor
<?>
constructor
=
clazz
.
getConstructor
(
String
.
class
);
for
(
int
i
=
0
;
i
<
number
;
i
++)
{
BasicPlaceCard
card
=
(
BasicPlaceCard
)
constructor
.
newInstance
(
new
Object
[
0
]);
result
.
add
(
card
);
}
}
catch
(
ClassNotFoundException
|
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
}
\ No newline at end of file
not-alone-server/src/main/java/fr/univnantes/alma/game/GameController.java
View file @
3b33b9d2
...
...
@@ -28,7 +28,7 @@ public class GameController implements GameInterface {
throw
new
InvalidOperationException
(
400
,
"Player is already registered in a game"
);
}
int
newId
=
idCounter
.
incrementAndGet
();
Game
newGame
=
new
Game
(
expectedPlayers
,
newId
);
Game
newGame
=
new
Game
(
creator
,
expectedPlayers
,
newId
);
games
.
put
(
newId
,
newGame
);
connectedPlayers
.
put
(
newId
,
creator
);
return
newId
;
...
...
not-alone-server/src/main/java/fr/univnantes/alma/model/card/place/BasicPlaceCard.java
View file @
3b33b9d2
...
...
@@ -9,6 +9,11 @@ import fr.univnantes.alma.references.associations.BidirectionalOneToMany;
import
fr.univnantes.alma.references.interfaces.ManyToOneAssociation
;
import
fr.univnantes.alma.references.interfaces.OneToManyAssociation
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Basic place card.
*/
...
...
@@ -82,4 +87,5 @@ public abstract class BasicPlaceCard extends BasicCard implements PlaceCard {
public
OneToManyAssociation
<
PlaceCard
,
Token
>
getToken
()
{
return
tokens
;
}
}
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