Home > Blockchain >  Messing around with an incremental game. How do I make a number go up every X amount of times anothe
Messing around with an incremental game. How do I make a number go up every X amount of times anothe

Time:10-14

I am new to JS and am having a difficult time understanding a lot of the logic around it so please forgive me if this theses are really basic questions.

  1. In the game I'm messing around with, I want to have a reputation system. The system would automatically go up as the player clicks so many. But I don't just want it to go up by 1. I want it to almost scale to the clicks. For example let's say the player clicks 50 times, I then want them to gain 1 reputation. Then if the player clicks 60 more times I want them to gain maybe 2 reputation. And so on. I'm struggling how to figure it out though.

  2. And that leads into my second question. How do I implement scaling into the game? Like if the numbers get really big I don't want the player only getting a set amount of reputation. I want the number to actually matter, and be useful. For example, let's say the player has 5 million clicks. At that point, they shouldn't be getting something like 1 reputation every 60 clicks. I want them to be getting something like 100 or so (maybe more) reputation for every thousand clicks or something. And I want that to apply to everything, right? Like the game's numbers scale as the player progresses.

Here's the JS I have so far if that's useful:

let score = 0;
let reputation = 0;

function addToScore(amount) {
    score = score   amount;
    document.getElementById("score").innerHTML = score;

    if (score === 2 * 10 || score === 2) {
        reputation = reputation   amount;
        document.getElementById("reputation").innerHTML = reputation;
    }
}

Anyway, sorry if any of that was confusing. I can clear up any questions. Any help is appreciated.

CodePudding user response:

// count and reputation 
let count = 0;
let reputation = 0;

// creating a list of ceiling values 
const firstCeiling = 50;
const secondCeiling = 60;
const thirdCeiling = 100;

//method to increment reputation 
const increment = () => {
  count  ;
};


// conditional statement to assign values to reputation 
if (count > firstCeiling && count < secondCeiling) {
  reputation  ;
} else if (count > secondCeiling && count < thirdCeiling) {
  reputation  ;
}

You can substitute the nested if else with a switch case and you can also use an array to store the ceiling values if you want. Also you can use the same pattern and just increment the reputation inside the if condition based on your requirement. Hope this helps.

CodePudding user response:

Below is one possible way to implement the scaling system. I hope it answers both of your questions.

let score = 0;
let reputation = 0;

// initial reputation boundary multiplier.
let reputationBoundaryMultiplier = 1;

// initial reputation boundary (should earn score of 10 to win first reputation)
let reputationBoundary = 10;

// reputation amount to increase depending on score
let reputationToAdd = 0;

function addToScore(amount) {

    score = score   amount;

    document.getElementById("score").innerHTML = score;

    if (score > 100) {
        // if score is greater than 100, increase the reputation. 
        // The variable reputationToAdd is decided when winning a reputation boundary and fixed until the next reputation boundary
        reputation = reputation   reputationToAdd;

    }

    if (score >= reputationBoundary) {
        // at each reputation boundary, decide the amount to increase the reputation
        // The same amount is used to increase reputation at each 100th score
        reputationToAdd = Math.round(score/10);

        // increase  reputation
        reputation = reputation   reputationToAdd;

        // increase the next reputation boundary multiplier by 0.5 when winning reputation each time
        reputationBoundaryMultiplier = reputationBoundaryMultiplier   0.5;

        // next score boundary eligible to win reputation
        reputationBoundary = reputationBoundaryMultiplier * score

        document.getElementById("reputation").innerHTML = reputation;
    }
}

for(let i = 1; i<100;i  ) {
    addToScore(i);
}

I have maintained a reputationBoundary. Initially, it is set to 10.

let reputationBoundary = 10;

Whenever the score exceeds or is equal to the reputationBoundary, I raise the bar for the next reputationBoundary. (There is a reputationMultiplier initialized to zero and when player achieves the boundary, I increment the reputationMultiplier by 0.5. I set the next reputationBoundary by multiplying the current score by reputationMultiplier, so the next reputationBoundary would be hard to achieve than the previous one).

reputationBoundaryMultiplier = reputationBoundaryMultiplier 0.5;

reputationBoundary = reputationBoundaryMultiplier * score

I have set the amount to increase the reputation like this: divide the current score by 10 and round it. So when the player wins a boundary, we increase reputation by an amount of reputationToAdd.

reputationToAdd = Math.round(score/10);

It is true, that When the reputationBoundary gets difficult to achieve than the previous one, the player will have to wait for a longer time to increment reputation. So, to avoid that and to make things interesting, if the score is greater than 100, when scores get added each time, I increase reputation by an amount of reputationToAdd. This amount reputationToAdd increases whenever, the player achieves a reputationBoundary

reputation = reputation reputationToAdd;

Let me know if this helps you.

  • Related