Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Menteur
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
Menteur
Commits
9a6529c0
Unverified
Commit
9a6529c0
authored
May 03, 2020
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(Cards): Display yours and other counts
parent
b43278a5
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
61 additions
and
33 deletions
+61
-33
TODO.md
TODO.md
+3
-2
App.vue
client/src/App.vue
+1
-1
Player.vue
client/src/components/Player.vue
+11
-4
vuex-store.js
client/src/vuex-store.js
+8
-2
lobby.py
server/game/lobby.py
+17
-7
manager.py
server/game/manager.py
+1
-1
color.py
server/model/color.py
+0
-0
game.py
server/model/game.py
+15
-11
value.py
server/model/value.py
+0
-0
test_lobby.py
server/test/test_lobby.py
+5
-5
No files found.
TODO.md
View file @
9a6529c0
# Credits
-
Byron Knoll
\ No newline at end of file
-
Byron Knoll for the card fronts
-
[
DDara
](
https://www.flaticon.com/authors/ddara
)
for the back card SVG
client/src/App.vue
View file @
9a6529c0
...
...
@@ -6,7 +6,7 @@
<p>
{{
players
.
length
}}
en ligne :
</p>
<div
v-for=
"player in players"
v-bind:key=
"player + ''"
>
<Player
:name=
"player"
/>
<Player
:name=
"player
.name"
:nb-cards=
"player.nbCards
"
/>
</div>
</div>
<div
id=
"game"
>
...
...
client/src/components/Player.vue
View file @
9a6529c0
<
template
>
<div
id=
"player"
class=
"mr-5 ml-5"
>
<b-badge
:variant=
"Math.random() >= 0.5? 'dark' : 'danger'"
>
Player
{{
name
}}
Player
{{
name
}}
(
{{
nbCards
}}
)
</b-badge>
<b-img
class=
"icon-card"
v-for=
"index in nbCards"
:key=
"index"
fluid
src=
"/img/unknown.svg"
/>
</div>
</
template
>
<
script
>
console
.
log
(
"Init player!"
);
export
default
{
name
:
"Player"
,
components
:
{},
props
:
{
name
:
String
name
:
String
,
nbCards
:
Number
},
methods
:
{}
};
</
script
>
<
style
>
img
.icon-card
{
max-width
:
20px
;
}
</
style
>
\ No newline at end of file
client/src/vuex-store.js
View file @
9a6529c0
...
...
@@ -17,8 +17,9 @@ export const store = new Vuex.Store({
isConnected
:
state
=>
state
.
isConnected
,
name
:
state
=>
state
.
name
,
socketMessage
:
state
=>
state
.
socketMessage
,
players
:
state
=>
state
.
players
,
gameState
:
state
=>
state
.
gameState
gameState
:
state
=>
state
.
gameState
,
cards
:
state
=>
state
.
cards
,
players
:
state
=>
state
.
players
},
mutations
:
{
SOCKET_CONNECT
(
state
)
{
...
...
@@ -50,6 +51,7 @@ export const store = new Vuex.Store({
if
(
message
)
{
if
(
message
.
data
)
{
let
players
=
message
.
data
.
players
;
let
cards
=
message
.
data
.
cards
;
let
gameState
=
message
.
data
.
state
;
let
text
=
message
.
data
.
text
;
let
extras
=
message
.
data
.
extras
;
...
...
@@ -61,6 +63,10 @@ export const store = new Vuex.Store({
console
.
log
(
"Setting state:"
,
gameState
);
state
.
state
=
gameState
;
}
if
(
cards
)
{
console
.
log
(
"Setting cards:"
,
cards
);
state
.
cards
=
cards
;
}
if
(
text
)
{
console
.
log
(
"Setting text:"
,
text
);
state
.
text
=
text
;
...
...
server/game/lobby.py
View file @
9a6529c0
...
...
@@ -115,8 +115,12 @@ class LobbyManager(ClientManager):
async
def
send
(
self
,
to
:
Player
,
message
:
MessageToPlayer
,
extras
=
None
):
sid
=
self
.
metadata
[
to
.
name
]
.
sid
data
=
{
"state"
:
str
(
message
.
name
),
"players"
:
[
p
.
name
for
p
in
self
.
players
]}
data
=
to
.
hand
.
json
()
# Start with "cards": []
data
=
json
.
loads
(
data
)
# JSONEncode and decode, starting with dict would miss `json()` encoders
data
[
"state"
]
=
str
(
message
.
name
)
data
[
"players"
]
=
[{
"name"
:
p
.
name
,
"nbCards"
:
len
(
p
.
hand
)}
for
p
in
self
.
players
]
if
extras
:
data
[
"extras"
]
=
extras
...
...
@@ -158,7 +162,6 @@ class LobbyManager(ClientManager):
message
=
MessageToPlayer
.
ReadyToStart
extras
[
"playersReady"
]
=
[
p
.
name
for
p
in
self
.
players_ready
]
elif
option
==
MessageFromPlayer
.
Bet
:
# FIXME vraie annonce, pas juste carre d'as lol
announce
=
Announce
(
bet
=
CARRE_ACE
)
...
...
@@ -174,13 +177,17 @@ class LobbyManager(ClientManager):
extras
[
"youBet"
]
=
False
if
message
:
if
message
==
MessageToPlayer
.
NewGame
:
print
(
"Creating game task..."
)
game
=
asyncio
.
create_task
(
self
.
maybe_start_game
())
print
(
"Sending message..."
)
await
self
.
send
(
sender
,
message
,
extras
)
print
(
"Awaiting game..."
)
await
game
print
(
"Sending message..."
)
await
self
.
send
(
sender
,
message
,
extras
)
print
(
"Message sent."
)
print
(
"LOBBY: Message handled."
)
def
which_player
(
self
,
sid
)
->
Player
:
...
...
@@ -207,6 +214,9 @@ class LobbyManager(ClientManager):
# MSGIN| 3c5e8962c4db465aaf2fd916bea2acc9 (Chihuahua): MENTEUR.
# LOBBY: Message handled.
# received
await
self
.
send
(
player
,
MessageToPlayer
.
YourTurn
,
extras
=
{
"bet"
:
game
.
current_bet
.
json
()})
extras
=
{
"bet"
:
game
.
current_bet
.
json
()}
await
self
.
send
(
player
,
MessageToPlayer
.
YourTurn
,
extras
)
extras
[
"waitingFor"
]
=
player
.
name
for
p
in
[
p
for
p
in
game
.
players
if
p
!=
player
]:
await
self
.
send
(
p
,
MessageToPlayer
.
Waiting
,
extras
=
{
"waitingFor"
:
p
.
name
}
)
await
self
.
send
(
p
,
MessageToPlayer
.
Waiting
,
extras
)
server/game/manager.py
View file @
9a6529c0
...
...
@@ -22,5 +22,5 @@ class ClientManager(ABC):
async
def
send
(
self
,
to
:
Player
,
message
:
MessageToPlayer
,
extra
=
None
):
extras
=
None
):
raise
NotImplementedError
(
"Send a message to clients "
)
server/model/color.py
View file @
9a6529c0
server/model/game.py
View file @
9a6529c0
...
...
@@ -28,13 +28,13 @@ class Game:
async
def
message
(
self
,
message
:
MessageToPlayer
,
*
to
:
Player
,
extra
=
None
extra
s
=
None
)
->
None
:
if
self
.
manager
:
if
not
to
:
to
=
self
.
players
for
player
in
to
:
await
self
.
manager
.
send
(
player
,
message
,
extra
)
await
self
.
manager
.
send
(
player
,
message
,
extra
s
)
@property
def
global_hand
(
self
)
->
Hand
:
...
...
@@ -57,7 +57,7 @@ class Game:
winner
=
self
.
players
[
0
]
await
self
.
message
(
MessageToPlayer
.
Win
,
winner
)
await
self
.
message
(
MessageToPlayer
.
WinnerIs
,
extra
=
winner
)
await
self
.
message
(
MessageToPlayer
.
WinnerIs
,
extra
s
=
winner
)
print
(
f
"Game over - {winner.name} wins with {len(winner.hand)} cards!"
)
async
def
new_turn
(
self
)
->
Player
:
...
...
@@ -66,10 +66,13 @@ class Game:
:return: the player that lost this turn.
"""
print
(
"New turn!"
)
# Distribution
self
.
deck
.
reset
()
await
self
.
message
(
MessageToPlayer
.
WaitTurn
)
print
(
"Told players to wait!"
)
for
current_player
in
self
.
players
:
current_player
.
clear
()
count_player_cards
=
self
.
defeats
[
current_player
]
+
1
...
...
@@ -77,9 +80,10 @@ class Game:
for
i
in
range
(
count_player_cards
):
card
=
self
.
deck
.
random_card
()
current_player
.
give
(
card
)
print
(
f
"{card}"
)
print
(
","
.
join
([
str
(
c
)
for
c
in
current_player
.
hand
.
cards
])
)
await
self
.
message
(
MessageToPlayer
.
GiveHand
,
current_player
,
extra
=
current_player
.
hand
.
json
())
print
(
"Sending cards..."
)
await
self
.
message
(
MessageToPlayer
.
GiveHand
,
current_player
)
print
(
f
"Cards sent."
)
# Tour
...
...
@@ -90,7 +94,7 @@ class Game:
if
loser
is
not
None
:
self
.
players
.
remove
(
loser
)
self
.
players
.
insert
(
0
,
loser
)
await
self
.
message
(
MessageToPlayer
.
LoseRound
,
extra
=
loser
.
name
)
await
self
.
message
(
MessageToPlayer
.
LoseRound
,
extra
s
=
loser
.
name
)
return
loser
last_player
=
current_player
...
...
@@ -145,7 +149,7 @@ class Game:
if
not
self
.
current_bet
:
# First player, has to bet something
print
(
"Game: First awaiting current bet"
)
await
self
.
message
(
MessageToPlayer
.
YourTurn
,
current_player
,
extra
=
self
.
current_bet
)
await
self
.
message
(
MessageToPlayer
.
YourTurn
,
current_player
,
extra
s
=
self
.
current_bet
)
while
not
self
.
current_bet
:
# Ask a valid bet
print
(
"Game: While no bet, awaiting"
)
announce
=
await
current_player
.
announce
(
self
.
current_bet
)
...
...
@@ -154,7 +158,7 @@ class Game:
print
(
f
"{current_player} starts the round: {self.current_bet}"
)
print
(
"Game: Awaiting start announce"
)
await
self
.
message
(
MessageToPlayer
.
Announce
,
extra
=
{
"player"
:
current_player
.
name
,
"announce"
:
announce
.
json
()})
extra
s
=
{
"player"
:
current_player
.
name
,
"announce"
:
announce
.
json
()})
else
:
print
(
f
"You cannot say Menteur on first round, {current_player}!"
)
...
...
@@ -166,7 +170,7 @@ class Game:
announce
=
Announce
()
# MENTEUR obligatoire
else
:
print
(
"Game: Awaiting bet"
)
await
self
.
message
(
MessageToPlayer
.
YourTurn
,
current_player
,
extra
=
self
.
current_bet
)
await
self
.
message
(
MessageToPlayer
.
YourTurn
,
current_player
,
extra
s
=
self
.
current_bet
)
announce
=
await
current_player
.
announce
(
self
.
current_bet
)
if
announce
.
bet
:
...
...
@@ -177,7 +181,7 @@ class Game:
# Valid bet:
print
(
f
" {current_player} bets {self.current_bet}."
)
self
.
message
(
MessageToPlayer
.
Announce
,
extra
=
{
"player"
:
current_player
,
"announce"
:
announce
})
self
.
message
(
MessageToPlayer
.
Announce
,
extra
s
=
{
"player"
:
current_player
,
"announce"
:
announce
})
else
:
# Menteur! Who lost the round?
menteur
=
self
.
is_menteur
(
self
.
current_bet
)
...
...
server/model/value.py
View file @
9a6529c0
server/test/test_lobby.py
View file @
9a6529c0
...
...
@@ -31,8 +31,8 @@ class MockPlayer(Player):
async
def
announce
(
self
,
current_bet
:
Optional
[
Hand
])
->
Announce
:
return
Announce
(
bet
=
self
.
bets
.
pop
()
if
self
.
bets
else
CARRE_ACE
)
def
receive
(
self
,
message
:
MessageToPlayer
,
extra
:
Optional
[
Any
]
=
None
):
self
.
messages
.
append
((
message
,
extra
))
def
receive
(
self
,
message
:
MessageToPlayer
,
extra
s
:
Optional
[
Any
]
=
None
):
self
.
messages
.
append
((
message
,
extra
s
))
def
print_msgs
(
self
)
->
str
:
return
'|'
.
join
([
f
"{m}[{e}]"
if
e
else
str
(
m
)
for
(
m
,
e
)
in
self
.
messages
])
...
...
@@ -43,10 +43,10 @@ class MockManager(ClientManager):
super
()
.
__init__
()
self
.
players
=
players
def
send
(
self
,
to
:
Player
,
message
:
MessageToPlayer
,
extra
=
None
):
def
send
(
self
,
to
:
Player
,
message
:
MessageToPlayer
,
extra
s
=
None
):
if
isinstance
(
to
,
MockPlayer
):
to
.
receive
(
message
,
extra
)
print
(
f
"Sent {message} {'(' + str(extra
) + ') ' if extra
else ''}to {to}"
)
to
.
receive
(
message
,
extra
s
)
print
(
f
"Sent {message} {'(' + str(extra
s) + ') ' if extras
else ''}to {to}"
)
class
TestManager
(
TestCase
):
...
...
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