Skip to content

Commit ca27964

Browse files
committed
Merge branch 'fix/countdown' of https://github.com/BilelJegham/Geoguess-Master-Web into fix/countdown
2 parents 99c14ea + 5245c9b commit ca27964

33 files changed

Lines changed: 23354 additions & 1430 deletions

jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module.exports = {
77
'!**/node_modules/**',
88
'!src/plugins/*',
99
'!src/lang/*',
10-
'!src/*.js',
10+
'!src/router.js',
11+
'!src/main.js',
12+
'!src/registerServiceWorker.js',
1113
],
1214
transformIgnorePatterns: [
1315
'node_modules/(?!gmap-vue|axios-cache-adapter|cache-control-esm)',

package-lock.json

Lines changed: 21684 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/DialogSummary.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ export default {
116116
},
117117
methods: {
118118
updateRecord() {
119-
var currentRecord = localStorage.getItem('record');
120-
if (currentRecord == null || this.score < currentRecord) {
121-
localStorage.setItem('record', this.score);
122-
}
123119
let history = localStorage.getItem('history');
124120
if (history == null) {
125121
history = [];

src/components/HeaderGame.vue

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
<template>
22
<div>
3-
<v-app-bar
4-
class="header-game"
5-
color="grey darken-4"
6-
>
3+
<v-app-bar class="header-game" color="grey darken-4">
74
<div
85
v-if="remainingTime != null && remainingTime > 0"
96
id="countdown-timer"
107
>
118
<span id="countdown-text">{{ countdownText }}</span>
129
</div>
13-
<div
14-
v-if="roomName"
15-
class="round-score-container room-name"
16-
>
10+
<div v-if="roomName" class="round-score-container room-name">
1711
<span class="sub-text">{{ $t('HeaderGame.room') }} : </span>
1812
<span class="main-text">{{ roomName }}</span>
1913
</div>
@@ -22,15 +16,11 @@
2216
<span class="sub-text">{{ $t('HeaderGame.round') }}: </span>
2317
</div>
2418
<div>
25-
<span
26-
id="roundLabel"
27-
class="main-text"
28-
>{{ round }} / {{ nbRound }}</span>
19+
<span id="roundLabel" class="main-text">
20+
{{ round }} / {{ nbRound }}
21+
</span>
2922
</div>
30-
<div
31-
v-if="isDistanceVisible"
32-
class="round-score-container"
33-
>
23+
<div v-if="isDistanceVisible" class="round-score-container">
3424
<span class="sub-text">{{ $t('HeaderGame.distance') }}: </span>
3525
</div>
3626
<div v-if="isDistanceVisible">

src/components/Maps.vue

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
:disabled="size < 2"
3939
@click="size--"
4040
>
41-
<v-icon dark>
42-
mdi-arrow-bottom-left
43-
</v-icon>
41+
<v-icon dark> mdi-arrow-bottom-left </v-icon>
4442
</v-btn>
4543

4644
<v-btn
@@ -50,20 +48,11 @@
5048
:disabled="size > 3"
5149
@click="size++"
5250
>
53-
<v-icon dark>
54-
mdi-arrow-top-right
55-
</v-icon>
51+
<v-icon dark> mdi-arrow-top-right </v-icon>
5652
</v-btn>
5753

58-
<v-btn
59-
id="btnPin"
60-
fab
61-
x-small
62-
@click="pinActive = !pinActive"
63-
>
64-
<v-icon dark>
65-
mdi-pin{{ pinActive ? '-off' : '' }}
66-
</v-icon>
54+
<v-btn id="btnPin" fab x-small @click="pinActive = !pinActive">
55+
<v-icon dark> mdi-pin{{ pinActive ? '-off' : '' }} </v-icon>
6756
</v-btn>
6857
</div>
6958
</div>
@@ -79,9 +68,7 @@
7968
color="red"
8069
@click="hideMap"
8170
>
82-
<v-icon color="white">
83-
mdi-close
84-
</v-icon>
71+
<v-icon color="white"> mdi-close </v-icon>
8572
</v-btn>
8673
<Map
8774
v-if="this.mode === 'classic'"
@@ -184,7 +171,7 @@ import DetailsMap from '@/components/game/DetailsMap';
184171
import Map from '@/components/map/Map';
185172
import MapCountries from '@/components/map/MapCountries';
186173
import { GAME_MODE } from '../constants';
187-
import { getSelectedPos } from '../utils';
174+
import { getScore, getSelectedPos } from '../utils';
188175
189176
export default {
190177
components: {
@@ -211,6 +198,7 @@ export default {
211198
'timeAttack',
212199
'nbRound',
213200
'countdown',
201+
'scoreMode',
214202
],
215203
data() {
216204
return {
@@ -236,6 +224,7 @@ export default {
236224
date: new Date(),
237225
rounds: [],
238226
},
227+
startTime: null,
239228
};
240229
},
241230
computed: {
@@ -257,6 +246,7 @@ export default {
257246
this.game.difficulty = this.difficulty;
258247
this.game.mode = this.mode;
259248
this.game.timeAttack = this.timeAttack;
249+
this.game.playerName = this.playerName;
260250
261251
if (this.roomName) {
262252
this.room = firebase.database().ref(this.roomName);
@@ -317,11 +307,12 @@ export default {
317307
j
318308
)
319309
.exportVal();
310+
320311
const { points, distance } = roundValues;
312+
321313
players[playerName] = {
314+
...roundValues,
322315
guess: posGuess,
323-
distance,
324-
points,
325316
};
326317
this.$refs.map.drawPolyline(
327318
posGuess,
@@ -483,30 +474,24 @@ export default {
483474
this.$emit('resetLocation');
484475
},
485476
calculateDistance() {
477+
const timePassed = new Date() - this.startTime;
486478
if (this.mode === GAME_MODE.COUNTRY) {
487479
this.point = +(this.country === this.selectedPos);
488-
this.$emit('calculateDistance', null, this.point);
480+
this.distance = null;
489481
} else {
490482
this.distance = Math.floor(
491483
google.maps.geometry.spherical.computeDistanceBetween(
492484
this.randomLatLng,
493485
this.selectedPos
494486
)
495487
);
496-
if (this.distance < 50) {
497-
this.point = 5000;
498-
} else {
499-
this.point = Math.round(
500-
5000 *
501-
Math.exp(-(this.distance / 1000 / this.difficulty))
502-
);
503-
504-
if (this.point > 5000) {
505-
this.point = 5000;
506-
} else if (this.point < 0) {
507-
this.point = 0;
508-
}
509-
}
488+
489+
this.point = getScore(
490+
this.distance,
491+
this.difficulty,
492+
timePassed,
493+
this.scoreMode
494+
);
510495
}
511496
// Save the distance into firebase
512497
if (this.room) {
@@ -516,6 +501,7 @@ export default {
516501
...getSelectedPos(this.selectedPos, this.mode),
517502
distance: this.distance,
518503
points: this.point,
504+
timePassed,
519505
});
520506
} else {
521507
this.game.rounds.push({
@@ -524,13 +510,15 @@ export default {
524510
position: this.randomLatLng,
525511
distance: this.distance,
526512
points: this.point,
513+
timePassed,
527514
});
528515
}
529516
530517
this.$emit('calculateDistance', this.distance, this.point);
531518
},
532519
startNextRound() {
533520
this.$refs.map.startNextRound();
521+
this.startTime = new Date();
534522
},
535523
goToNextRound(isPlayAgain = false) {
536524
if (isPlayAgain) {

src/components/dialogroom/DialogRoom.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default {
9191
moveControl: true,
9292
panControl: true,
9393
countdown: 0,
94+
scoreMode: null,
9495
allPanorama: false,
9596
};
9697
},
@@ -186,7 +187,9 @@ export default {
186187
187188
this.room.once('value', (snapshot) => {
188189
if (snapshot.child('started').val()) {
189-
this.errorMessage = this.$t('DialogRoom.alreadyStarted');
190+
this.errorMessage = this.$t(
191+
'DialogRoom.alreadyStarted'
192+
);
190193
return;
191194
}
192195
const numberOfPlayers = snapshot
@@ -223,7 +226,7 @@ export default {
223226
.set(
224227
this.$t(
225228
'CardRoomPlayerName.anonymousPlayerName'
226-
),
229+
) + this.playerNumber,
227230
(error) => {
228231
if (!error) {
229232
this.currentComponent = 'playerName';
@@ -245,7 +248,8 @@ export default {
245248
zoomControl,
246249
moveControl,
247250
panControl,
248-
countdown
251+
countdown,
252+
scoreMode
249253
) {
250254
this.allPanorama = allPanorama;
251255
this.timeLimitation = timeLimitation;
@@ -255,6 +259,7 @@ export default {
255259
this.moveControl = moveControl;
256260
this.panControl = panControl;
257261
this.countdown = countdown;
262+
this.scoreMode = scoreMode;
258263
if (this.singlePlayer) {
259264
this.$router.push({
260265
name: 'street-view',
@@ -268,6 +273,7 @@ export default {
268273
zoomControl,
269274
moveControl,
270275
panControl,
276+
scoreMode,
271277
},
272278
});
273279
} else {
@@ -283,6 +289,7 @@ export default {
283289
moveControl,
284290
panControl,
285291
countdown,
292+
scoreMode,
286293
},
287294
(error) => {
288295
if (!error) {
@@ -326,6 +333,7 @@ export default {
326333
panControl: this.panControl,
327334
countdown: this.countdown,
328335
allPanorama: this.allPanorama,
336+
scoreMode: this.scoreMode,
329337
};
330338
// Set flag started
331339
this.room.child('started').set(true);
@@ -342,6 +350,7 @@ export default {
342350
panControl: snapshot.child('panControl').val(),
343351
countdown: snapshot.child('countdown').val(),
344352
allPanorama: snapshot.child('allPanorama').val(),
353+
scoreMode: snapshot.child('scoreMode').val(),
345354
};
346355
this.startGameMultiplayer(gameParams);
347356
});

src/components/dialogroom/card/CardRoomPlayerName.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
maxlength="10"
2727
autofocus
2828
:label="$t('CardRoomPlayerName.input')"
29-
@keyup.enter="searchRoom"
29+
:error="invalidName"
3030
/>
3131
</v-col>
3232
</v-row>
@@ -106,6 +106,7 @@ export default {
106106
return {
107107
players: [],
108108
playerName: '',
109+
invalidName: false,
109110
};
110111
},
111112
computed: {
@@ -115,7 +116,12 @@ export default {
115116
},
116117
watch: {
117118
playerName(val) {
118-
this.$emit('setPlayerName', val);
119+
if(!this.players.includes(val)){
120+
this.invalidName = false;
121+
this.$emit('setPlayerName', val);
122+
}else{
123+
this.invalidName = true;
124+
}
119125
},
120126
},
121127
mounted() {

0 commit comments

Comments
 (0)