dsnnvpobaljihv3490 2013-09-03 19:31
浏览 1114
已采纳

基于文本的游戏 - XP,Rank,Percent

I'm pretty new to programming, but I've learned some PHP and HTML. Now I am trying to make a text based "RPG" game. I've already made a few functions like gambling, killing, and doing crimes (Yes, it's a mafia related game). I've made it possible to "level up" in this game, and stunningly enough, I made it work perfectly, but then I ran over a small issue. I want to let the players see their progress, using a "rank bar", it's the same concept as experience points, but I want it to show as percent. As of now, it looks like this:

$percent = $currentxp / $nextlevelxp;
$percent2 = $percent * 100;
$percent3 = number_format($percent2, 0);

This actually worked for me (you can see your xp, and level up), but the problem is, when you level up, it will show percent to next level using the current XP, which means it might say 50% when you've just leveled up. Is there any way I can make it 0% at the next rank, and make it go up to 100% before you level up? I'd prefer a basic kind of code. Thank you in advance!

  • 写回答

1条回答 默认 最新

  • dongshen6060 2013-09-03 19:36
    关注

    Change the first line to:

    $percent = ($currentxp - $curlevelxp) / ($nextlevelxp - $curlevelxp);
    

    This isn't a programming problem, it's just simple math.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)