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
e8d06e8c
Commit
e8d06e8c
authored
Nov 28, 2020
by
Corentin Guillevic
Browse files
Add of TAskAction in common and client (core) ; Create some methods to ask actions in Game.java
parent
a32eb3d0
Changes
6
Hide whitespace changes
Inline
Side-by-side
not-alone-core/src/main/thrift/common.thrift
View file @
e8d06e8c
...
...
@@ -46,4 +46,10 @@ struct TPair {
struct TAction {
1: string type,
2: list<TPair> params
}
struct TAskAction {
1: string type,
2: string message,
3: list<TPair> choices
}
\ No newline at end of file
not-alone-core/src/main/thrift/game-client.thrift
View file @
e8d06e8c
...
...
@@ -63,7 +63,7 @@ service GameClientService {
void sendStartPhase(common.TPhaseId phaseId, TPlayerTeam team, THand hand, TScore score, TPlanet planet, list<TCardReserve> reserve, list<TTraque> traquesInformation, TCreature creatureInformation)
common.TAction askAction(common.TAction actionAsked)
common.TAction askAction(common.TA
skA
ction actionAsked)
}
...
...
not-alone-server/src/main/java/fr/univnantes/alma/game/Game.java
View file @
e8d06e8c
...
...
@@ -4,22 +4,22 @@ import fr.univnantes.alma.data.DatabaseFactory;
import
fr.univnantes.alma.data.NotAloneDatabase
;
import
fr.univnantes.alma.game.item.Phase
;
import
fr.univnantes.alma.game.item.Reserve
;
import
fr.univnantes.alma.game.item.action.Action
;
import
fr.univnantes.alma.game.item.action.ActionChooseCard
;
import
fr.univnantes.alma.game.item.action.ActionChoosePower
;
import
fr.univnantes.alma.game.item.action.ActionType
;
import
fr.univnantes.alma.game.item.action.*
;
import
fr.univnantes.alma.game.item.board.Board
;
import
fr.univnantes.alma.game.item.card.*
;
import
fr.univnantes.alma.game.item.jeton.JetonSymbol
;
import
fr.univnantes.alma.game.item.jeton.PlacedJeton
;
import
fr.univnantes.alma.game.item.pioche.Pioche
;
import
fr.univnantes.alma.game.item.planet.Place
;
import
fr.univnantes.alma.game.item.planet.Planet
;
import
fr.univnantes.alma.game.item.player.Creature
;
import
fr.univnantes.alma.game.item.player.Player
;
import
fr.univnantes.alma.game.item.player.Traque
;
import
fr.univnantes.alma.game.item.power.Power
;
import
fr.univnantes.alma.game.utilitary.Pair
;
import
fr.univnantes.alma.thrift.Response
;
import
fr.univnantes.alma.thrift.TAction
;
import
fr.univnantes.alma.thrift.TAskAction
;
import
fr.univnantes.alma.thrift.TPair
;
import
java.util.*
;
...
...
@@ -27,8 +27,7 @@ import java.util.stream.Collectors;
import
static
fr
.
univnantes
.
alma
.
game
.
PowerApplicator
.
applyPlayerCard
;
import
static
fr
.
univnantes
.
alma
.
game
.
PowerApplicator
.
revealPlace
;
import
static
fr
.
univnantes
.
alma
.
game
.
item
.
action
.
ActionType
.
CHOOSE_CARD
;
import
static
fr
.
univnantes
.
alma
.
game
.
item
.
action
.
ActionType
.
CHOOSE_POWER
;
import
static
fr
.
univnantes
.
alma
.
game
.
item
.
action
.
ActionType
.*;
import
static
fr
.
univnantes
.
alma
.
game
.
item
.
jeton
.
JetonSymbol
.
ARTEMIA
;
import
static
fr
.
univnantes
.
alma
.
game
.
item
.
jeton
.
JetonSymbol
.
CIBLE
;
import
static
fr
.
univnantes
.
alma
.
game
.
item
.
player
.
PlayerTeam
.
CREATURE
;
...
...
@@ -466,7 +465,8 @@ public class Game implements GameInterface {
}
@Override
public
Action
askAction
(
int
inGameIdPlayer
,
TAction
askedAction
)
{
public
Action
askAction
(
int
inGameIdPlayer
,
TAskAction
askedAction
)
{
//TODO
return
null
;
}
...
...
@@ -830,7 +830,7 @@ public class Game implements GameInterface {
}
public
List
<
Card
>
chooseCardsAction
(
int
idPlayer
,
int
max
,
List
<
Card
>
cardsToChoose
)
{
TAction
askAction
=
createTActionForChooseCardsAction
(
max
,
cardsToChoose
);
TA
skA
ction
askAction
=
createTActionForChooseCardsAction
(
max
,
cardsToChoose
);
List
<
Card
>
cards
=
new
ArrayList
<>();
List
<
CardName
>
cardNames
;
Action
action
;
...
...
@@ -844,13 +844,14 @@ public class Game implements GameInterface {
return
cards
;
}
private
TAction
createTActionForChooseCardsAction
(
int
max
,
List
<
Card
>
cardsToChoose
){
private
TA
skA
ction
createTActionForChooseCardsAction
(
int
max
,
List
<
Card
>
cardsToChoose
){
List
<
TPair
>
params
=
new
ArrayList
<>();
params
.
add
(
new
TPair
(
"number"
,
""
+
max
));
for
(
int
i
=
0
;
i
<
cardsToChoose
.
size
()
;
++
i
)
{
params
.
add
(
new
TPair
(
""
+
(
i
+
1
),
cardsToChoose
.
get
(
i
).
getCardName
().
toString
()));
}
return
new
TAction
(
CHOOSE_CARD
.
toString
(),
params
);
String
message
=
"Choose a maximum of "
+
max
+
"cards"
;
return
new
TAskAction
(
CHOOSE_CARD
.
toString
(),
message
,
params
);
}
private
List
<
Card
>
computeCardListFromCardNames
(
List
<
CardName
>
cardNames
,
List
<
Card
>
cardsToChoose
){
...
...
@@ -870,7 +871,8 @@ public class Game implements GameInterface {
number
=
""
+
(
i
+
1
);
params
.
add
(
new
TPair
(
number
,
powersDescription
.
get
(
i
)));
}
TAction
askAction
=
new
TAction
(
CHOOSE_POWER
.
toString
(),
params
);
String
message
=
"Choose a power"
;
TAskAction
askAction
=
new
TAskAction
(
CHOOSE_POWER
.
toString
(),
message
,
params
);
int
idPower
=
-
1
;
Action
action
;
do
{
...
...
@@ -882,8 +884,57 @@ public class Game implements GameInterface {
return
idPower
;
}
/*
TODO : Implements other actions
*/
public
int
targetPlayer
(
int
idPlayer
)
{
String
message
=
"Choose one traque"
;
TAskAction
askAction
=
new
TAskAction
(
TARGET_PLAYER
.
toString
(),
message
,
new
ArrayList
<>());
int
idTargetPlayer
=
-
1
;
Action
action
;
Set
<
Integer
>
playersIdList
=
playersMap
.
keySet
();
do
{
action
=
askAction
(
idPlayer
,
askAction
);
if
(
action
.
getActionType
().
equals
(
TARGET_PLAYER
))
{
idTargetPlayer
=
((
ActionMovePlayer
)
action
).
getIdPlayer
();
}
}
while
(!
playersIdList
.
contains
(
idTargetPlayer
)
&&
creature
.
getInGameId
()
!=
idTargetPlayer
);
return
idTargetPlayer
;
}
public
List
<
Place
>
choosePlace
(
int
idPlayer
,
int
number
)
{
String
message
=
number
>
1
?
"Choose"
+
number
+
" places"
:
"Choose 1 place"
;
return
choosePlace
(
idPlayer
,
number
,
message
);
}
public
List
<
Place
>
choosePlace
(
int
idPlayer
,
int
number
,
String
message
)
{
if
(
number
<=
0
||
number
>
10
)
{
throw
new
IllegalArgumentException
(
"number must be between 1 and 10"
);
}
List
<
TPair
>
params
=
new
ArrayList
<>();
params
.
add
(
new
TPair
(
"number"
,
number
+
""
));
TAskAction
askAction
=
new
TAskAction
(
CHOOSE_PLACE
.
toString
(),
message
,
params
);
List
<
Place
>
places
=
new
ArrayList
<>();
Action
action
;
do
{
action
=
askAction
(
idPlayer
,
askAction
);
if
(
action
.
getActionType
().
equals
(
CHOOSE_PLACE
))
{
places
=
((
ActionChoosePlace
)
action
).
getPlaces
();
}
}
while
(
places
.
size
()
!=
number
);
return
places
;
}
public
Pair
<
Player
,
Place
>
movePlayer
(
int
idPlayer
)
{
//TODO
return
null
;
}
public
Pair
<
JetonSymbol
,
JetonSymbol
>
swapJetons
(
int
idPlayer
)
{
//TODO
return
null
;
}
public
Map
<
CardName
,
Place
>
associateCardNamesToPlaces
(
int
idPlayer
,
List
<
Card
>
cards
)
{
//TODO
return
null
;
}
}
not-alone-server/src/main/java/fr/univnantes/alma/game/GameInterface.java
View file @
e8d06e8c
...
...
@@ -7,6 +7,7 @@ import fr.univnantes.alma.game.item.jeton.PlacedJeton;
import
fr.univnantes.alma.game.item.power.Power
;
import
fr.univnantes.alma.thrift.Response
;
import
fr.univnantes.alma.thrift.TAction
;
import
fr.univnantes.alma.thrift.TAskAction
;
import
java.util.List
;
...
...
@@ -99,7 +100,7 @@ public interface GameInterface {
* @param askedAction The asked action
* @return An Action
*/
public
Action
askAction
(
int
inGameIdPlayer
,
TAction
askedAction
);
public
Action
askAction
(
int
inGameIdPlayer
,
TA
skA
ction
askedAction
);
/**
* Send that the game start
...
...
not-alone-server/src/main/java/fr/univnantes/alma/game/item/action/Action.java
View file @
e8d06e8c
...
...
@@ -12,7 +12,4 @@ public abstract class Action {
public
abstract
ActionType
getActionType
();
public
static
TAction
createTAction
(
ActionType
type
,
List
<
Pair
<
String
,
String
>>
params
)
{
return
null
;
}
}
not-alone-server/src/main/java/fr/univnantes/alma/handler/GameClientHandler.java
View file @
e8d06e8c
...
...
@@ -32,7 +32,7 @@ public class GameClientHandler implements GameClientService.Iface {
}
@Override
public
TAction
askAction
(
TAction
actionAsked
)
throws
TException
{
public
TAction
askAction
(
TA
skA
ction
actionAsked
)
throws
TException
{
return
null
;
}
}
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