我正在跟踪我在youtube上找到的有关使用GUI创建基本RPG的教程。本教程在指导如何处理面板和框架方面非常有帮助,但是它们处理用户决策的方式似乎非常不切实际。他们有一个使用玩家位置的开关盒,然后在其中的另一个开关盒根据用户输入的按钮来处理动作。我并不是说这并没有完成工作,而是让我有了一个长开关盒。我想知道什么是拥有更干净,更易管理的代码的最佳方法。
代码段
//depending on your position, you are given different action options
switch(position) {
//if you are in town, these are your options
case "townGate":
switch(yourOption) {
//talk to the guard
case "c1": talkGaurd(); break;
//attack the guard
case "c2": attackGuard(); break;
}
break;
//if you are talking to the guard, these are your options
case "talkingToGaurd":
switch(yourOption) {
//leave to the outside of the gate
case "c1": townGate(); break;
}
break;
//if you are attacking the guard, these are your options
case "attackingGuard":
switch(yourOption) {
//leave the the outside of the gate
case "c1": townGate(); break;
}
break;
}