我正在尝试为我正在制作的基于文本的 RPG 创建一个调平系统。我遇到的问题是范围似乎不适用于开关盒。这是我所拥有的:
int exp = 0, level = 1, hp = 10, hpmax = 10;
if (exp >= 262144) exp = 262144;
switch (exp)
{
case (4 - 15):
level = 2;
hp = 12;
hpmax = 12;
break;
case (16 - 63):
level = 3;
hp = 14;
hpmax = 14;
break;
case (64 - 255):
level = 4;
hp = 16;
hpmax = 16;
break;
case (256 - 1023):
level = 5;
hp = 18;
hpmax = 18;
break;
case (1024 - 4095):
level = 6;
hp = 20;
hpmax = 20;
break;
case (4096 - 16383):
level = 7;
hp = 20;
hpmax = 20;
break;
case (16384 - 65535):
level = 8;
hp = 22;
hpmax = 22;
break;
case (65536 - 262143):
level = 9;
hp = 24;
hpmax = 24;
break;
case (262144 - 999999999):
level = 10;
hp = 26;
hpmax = 26;
break;
是的,我意识到这并没有达到我想要的效果。我对找到的替代方案不太满意。我正在寻找最简单的解决方案。我是编程新手,因此将不胜感激。