php game, formula to calculate a level based on exp

前端 未结 7 2433
心在旅途
心在旅途 2020-12-23 10:34

Im making a browser based PHP game and in my database for the players it has a record of that players total EXP or experience.

What i need is a formula to translate

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-23 11:09

    I take it what you're looking for is the amount of experience to decide what level they are on? Such as: Level 1: 50exp Level 2: 100exp Level 3: 150exp ?

    if that's the case you could use a loop something like:

    $currentExp = x;
    $currentLevel;
    $i; // initialLevel
    
    for($i=1; $i < 100; $i *= 3)
    {
         if( ($i*50 > $currentExp) && ($i < ($i+1)*$currentExp)){
             $currentLevel = $i/3;
             break;
         }
    }
    

    This is as simple as I can make an algorithm for levels, I haven't tested it so there could be errors.

    Let me know if you do use this, cool to think an algorithm I wrote could be in a game!

提交回复
热议问题