Skip to content

Commit a8c5cde

Browse files
committed
✨ [Teams] Add starting team in game
1 parent 64e914c commit a8c5cde

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

imports/ui/GameForm.jsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ function shuffle(a) {
1515
return a;
1616
}
1717

18-
const getGameWords = () => {
18+
const getStartingTeam = () => {
19+
return Math.random() >= 0.5 ? 'red' : 'blue';
20+
}
21+
22+
const getGameWords = (startingTeam) => {
1923
let words = Cards.find({}).fetch();
2024
wordsSample = [];
21-
startingTeam = Math.random() >= 0.5;
2225
redTeamCardsCount = 8;
2326
blueTeamCardsCount = 8;
24-
if (startingTeam) {
27+
if (startingTeam === 'red') {
2528
redTeamCardsCount++;
2629
} else {
2730
blueTeamCardsCount++;
@@ -65,9 +68,11 @@ const GameForm = ({ words }) => (
6568
initialValues={{ name: '' }}
6669
onSubmit={(values, { setSubmitting }) => {
6770
if (values.name.length > 0) {
71+
const startingTeam = getStartingTeam();
6872
Games.insert({
6973
name: values.name,
70-
cards: getGameWords(),
74+
cards: getGameWords(startingTeam),
75+
startingTeam,
7176
isStarted: false,
7277
shownCardsIds: [],
7378
});

imports/ui/GamePage.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ const GamePage = ({ game, blueParticipants, redParticipants, currentParticipant}
8787
</>
8888
</CardContent>
8989
</Card>
90+
<Card style={{marginTop: 16, marginBottom: 16, backgroundColor: game.startingTeam === 'blue' ? '#2980b9' : '#e74c3c'}}>
91+
<CardContent>
92+
<Typography variant='h5' component='h2' style={{color: 'white', textAlign: 'center'}}>
93+
{`L'Équipe ${game.startingTeam === 'blue' ? 'bleue' : 'rouge'} commence`}
94+
</Typography>
95+
</CardContent>
96+
</Card>
9097
<Grid container spacing={3}>
9198
<Grid item xs={6}>
9299
<Card style={{marginTop: 16, marginBottom: 16, backgroundColor: '#2980b9'}}>

0 commit comments

Comments
 (0)