|
1 | 1 | const LOCAL_STORAGE_KEY = "matche_days";
|
2 | 2 | let maxPoints;
|
| 3 | +let currentMatchMaxPoints; |
3 | 4 | let playersPerTeam;
|
4 | 5 | let players = [];
|
5 | 6 | let playingTeams = [];
|
@@ -341,6 +342,7 @@ function startNewMatch(winningPlayers, losingPlayers) {
|
341 | 342 | }
|
342 | 343 | }
|
343 | 344 |
|
| 345 | + currentMatchMaxPoints = maxPoints; |
344 | 346 | randomServe();
|
345 | 347 | updateCurrentMatch(generateRandomTeams(newPlayers));
|
346 | 348 | saveOnLocalStorage();
|
@@ -377,14 +379,17 @@ $(".score-point").click(function() {
|
377 | 379 | }
|
378 | 380 |
|
379 | 381 | 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]); |
388 | 393 | }
|
389 | 394 |
|
390 | 395 | if (autoSwitchTeamsPoints > 0) {
|
@@ -579,6 +584,7 @@ $(document).ready(function (){
|
579 | 584 | matches = lastGameDay.matches;
|
580 | 585 | currentId = lastGameDay.id;
|
581 | 586 |
|
| 587 | + currentMatchMaxPoints = maxPoints; |
582 | 588 | updatePlayerList();
|
583 | 589 | updateCurrentMatch(playingTeams);
|
584 | 590 | $("#new-match-day").hide();
|
|
0 commit comments