Skip to content

Commit 4cbaebd

Browse files
fix finishing matches that goes to extra 2 points
1 parent db25c19 commit 4cbaebd

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ <h1>Histórico de Partidas</h1>
124124
src="https://code.jquery.com/jquery-3.7.1.min.js"
125125
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
126126
crossorigin="anonymous"></script>
127-
<script src="./index.js?v=7"></script>
127+
<script src="./index.js?v=8"></script>
128128
<script>
129129
if('serviceWorker' in navigator) {
130130
navigator.serviceWorker.register('./serviceWorker.js', { scope: '/peladaManager/' });

index.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const LOCAL_STORAGE_KEY = "matche_days";
22
let maxPoints;
3+
let currentMatchMaxPoints;
34
let playersPerTeam;
45
let players = [];
56
let playingTeams = [];
@@ -341,6 +342,7 @@ function startNewMatch(winningPlayers, losingPlayers) {
341342
}
342343
}
343344

345+
currentMatchMaxPoints = maxPoints;
344346
randomServe();
345347
updateCurrentMatch(generateRandomTeams(newPlayers));
346348
saveOnLocalStorage();
@@ -377,14 +379,17 @@ $(".score-point").click(function() {
377379
}
378380

379381
const diff = Math.abs(team1Score - team2Score);
380-
if (diff >= 2 ) {
381-
if (team1Score >= maxPoints) {
382-
endMatch(0);
383-
startNewMatch(playingTeams[0], playingTeams[1]);
384-
} else if (team2Score >= maxPoints) {
385-
endMatch(1);
386-
startNewMatch(playingTeams[1], playingTeams[0]);
387-
}
382+
383+
if ((team1Score === currentMatchMaxPoints || team2Score === currentMatchMaxPoints) && diff < 2) {
384+
currentMatchMaxPoints += 1;
385+
}
386+
387+
if (team1Score >= currentMatchMaxPoints && diff >= 2) {
388+
endMatch(0);
389+
startNewMatch(playingTeams[0], playingTeams[1]);
390+
} else if (team2Score >= currentMatchMaxPoints && diff >= 2) {
391+
endMatch(1);
392+
startNewMatch(playingTeams[1], playingTeams[0]);
388393
}
389394

390395
if (autoSwitchTeamsPoints > 0) {
@@ -579,6 +584,7 @@ $(document).ready(function (){
579584
matches = lastGameDay.matches;
580585
currentId = lastGameDay.id;
581586

587+
currentMatchMaxPoints = maxPoints;
582588
updatePlayerList();
583589
updateCurrentMatch(playingTeams);
584590
$("#new-match-day").hide();

0 commit comments

Comments
 (0)