Skip to content

Commit

Permalink
New Feature: History Match
Browse files Browse the repository at this point in the history
  • Loading branch information
Minemetero committed Jun 5, 2024
1 parent cd9cb92 commit 8a5acf8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ <h2>Current Match</h2>
<h2>Match Order</h2>
<ul id="matchOrderList"></ul>
</div>
<div class="history" id="historyContainer">
<h2>Match History</h2>
<ul id="historyList"></ul>
</div>
</div>

<script src="script.js"></script>
Expand Down
15 changes: 15 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let totalScores = {};
let currentMatchScores = {};
let currentMatch = [0, 1]; // Indexes of the players in the current match
let winBalls = 5;
let matchHistory = [];

document.addEventListener('DOMContentLoaded', () => {
document.getElementById('addPlayerButton').addEventListener('click', addPlayer);
Expand Down Expand Up @@ -66,11 +67,13 @@ function incrementCurrentMatchScore(playerName) {
if (currentMatchScores[playerName] >= winBalls) {
totalScores[playerName]++;
document.getElementById('result').innerText = `${playerName} Wins this round!`;
matchHistory.push(`${players[currentMatch[0]]} vs ${players[currentMatch[1]]}: ${playerName} won`);
setTimeout(() => {
document.getElementById('result').innerText = '';
updatePlayerScoreList();
updateMatchOrder();
updateMatchOrderList();
updateHistoryList();
startNewMatch();
}, 2000);
}
Expand Down Expand Up @@ -114,6 +117,16 @@ function updateMatchOrderList() {
}
}

function updateHistoryList() {
const historyList = document.getElementById('historyList');
historyList.innerHTML = '';
matchHistory.forEach(match => {
const li = document.createElement('li');
li.textContent = match;
historyList.appendChild(li);
});
}

function updateMatchOrder() {
currentMatch[0] = (currentMatch[0] + 1) % players.length;
currentMatch[1] = (currentMatch[1] + 1) % players.length;
Expand All @@ -127,12 +140,14 @@ function resetScores() {
totalScores = {};
currentMatchScores = {};
currentMatch = [0, 1];
matchHistory = [];
document.getElementById('playerList').innerHTML = '';
document.getElementById('gameBoard').style.display = 'none';
document.getElementById('initialSetup').style.display = 'block';
document.getElementById('playerInputGroup').style.display = 'block';
document.getElementById('playerListGroup').style.display = 'block';
document.getElementById('initialButtons').style.display = 'block';
document.getElementById('historyList').innerHTML = '';
}

window.incrementCurrentMatchScore = incrementCurrentMatchScore;
8 changes: 4 additions & 4 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ h1 {
margin-right: 10px;
}

.player-list ul, #playerScoreList, #matchOrderList {
.player-list ul, #playerScoreList, #matchOrderList, #historyList {
list-style: none;
padding: 0;
}

.player-list li, #playerScoreList li, #matchOrderList li {
.player-list li, #playerScoreList li, #matchOrderList li, #historyList li {
margin: 5px 0;
}

Expand Down Expand Up @@ -92,12 +92,12 @@ label {
box-sizing: border-box;
}

.player-scores, .current-match, .match-order {
.player-scores, .current-match, .match-order, .history {
background-color: var(--secondary-bg-color);
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
width: 30%;
width: 23%;
}

h2 {
Expand Down

0 comments on commit 8a5acf8

Please sign in to comment.