Currently, I'm delving into the creation of a simulation game inspired by Counter Strike for both entertainment and educational purposes.
My Progress: I've meticulously established player objects, organized them into arrays based on their respective teams, and initiated simulated duels. These duels are decided by each player's stats, which were predefined within their individual object properties.
My Objective: The main goal is to implement a system where once a player wins a duel, they are removed from further participation in the ongoing "round" to prevent repetitive encounters after being eliminated.
for ( var i = 0; i < 5; i++ ) {
getConsole = document.querySelector(".console");
setTimeout( function timer(){
getConsole.insertAdjacentHTML ("beforebegin", "<p>Round: " + rounds + "</p>" );
calculateAim();
rounds++
console.log('rounds ' + rounds) }, i * 3000 );
};
}
function calculateAim() {
for ( var r = 0; r < 5; r++ ) {
getConsole = document.querySelector(".console");
let playerTeam = [player1, player2, player3]
let enemyTeam = [player4, player5, player6],
battle1 = playerTeam[Math.floor(Math.random() * playerTeam.length)];
battle2 = enemyTeam[Math.floor(Math.random() * enemyTeam.length)];
console.log("Player Team: " + battle1)
console.log("Enemy Team: " + battle2)
let min1 = 0;
let max2 = 100;
let EncounterRating = Math.floor(Math.random() * (+max2 - +min1)) + +min1;
if (EncounterRating < 5) {
getConsole.insertAdjacentHTML ("beforebegin", "The bomb has exploded and CT's saved their weapons. <br>");
break;
}
else {
if (battle1.aim > battle2.aim) {
getConsole.insertAdjacentHTML ("beforebegin", battle1.name + " killed " + battle2.name + " because your aim is " + battle1.aim + " and his enemie's is " + battle2.aim + " <br>");
}
if (battle1.aim < battle2.aim) {
getConsole.insertAdjacentHTML ("beforebegin", battle2.name + " killed " + battle1.name + " because your aim is " + battle2.aim + " and his enemie's is " + battle1.aim + " <br>");
}
if (battle1.aim == battle2.aim && battle1.luck > battle2.luck) {
getConsole.insertAdjacentHTML ("beforebegin", battle1.name + " killed " + battle2.name + " with a lucky shot<br>");
}
if (battle1.aim == battle2.aim && battle2.luck > battle1.luck) {
getConsole.insertAdjacentHTML ("beforebegin", battle2.name + " killed " + battle1.name + " with a lucky timing<br>");
}
}
}
Despite my coding effort, an issue arises where even after losing a duel as per test results, players continue participating in subsequent "rounds."