0

所以我正在学习 C#,我正在尝试制作一个简单的基于文本的 RPG,但是当我运行角色创建时,这种情况不断发生:

还剩 5 分

力量?

输入:4

点数太高!按 Enter。

这是代码。

public static void Start()
{
    Console.Clear();
    int charcreatepts = 10;
    Console.WriteLine ("{0} Points Left", charcreatepts);
    Console.WriteLine ("Intelligence?");
    int CCPint1 = Convert.ToInt32 (Console.ReadLine ());
    charcreatepts = charcreatepts - CCPint1;
    if (CCPint1 > charcreatepts) {
        Console.WriteLine ("Point amount too high! Press Enter.");
        Console.ReadLine ();
        Start ();
    }else{
        Console.Clear ();
            Console.WriteLine ("{0} Points Left", charcreatepts);
            Console.WriteLine ("Strength?");
            int CCPint2 = Convert.ToInt32 (Console.ReadLine ());
            charcreatepts = charcreatepts - CCPint2;
            if (CCPint2 > charcreatepts) {
                Console.WriteLine ("Point amount too high! Press Enter.");
                Console.ReadLine ();
                Start ();
            }else{
                Console.Clear ();
                Console.WriteLine ("{0} Points Left", charcreatepts);
                Console.WriteLine ("Social Skills?");
                int CCPint3 = Convert.ToInt32 (Console.ReadLine ());
                charcreatepts = charcreatepts - CCPint3;
                if (CCPint3 > charcreatepts) {
                    Console.WriteLine ("Point amount too high! Press Enter.");
                    Console.ReadLine ();
                    Start();
                }
            }
        }
    }
}

我正在努力得到它,所以如果你愿意,你可以在这种情况下使用剩余的 5 点,力量,但由于某种原因,我什至不能使用 4。

4

1 回答 1

1

看起来你减得太早了。给定:charcreatepts = charcreatepts - CCPint1,charcreatepts = 5然后CCPint1 = 4charcreatepts = 5 - 4 = 1

然后:

if (CCPInt1 > charcreatepts) { ... }将会if (4 > 1) { ... }

在尝试计算新值之前,您应该检查是否CCPint1大于。charcreatepts

于 2013-05-05T06:18:02.877 回答