所以我正在做一个文字冒险来提高我的编程技能(只是一个初学者),我正在为它开发一个新的战斗系统,因为旧的战斗系统真的很无聊。所以我遇到了一个剪刀石头布系统,但我想要一个像剪刀石头布一样的系统,有 5 个选项供玩家选择,以及攻击玩家的敌人或怪物。
我使用了很多 if 语句,实际上并没有花太长时间,但我想知道是否有更好的方法来做到这一点,以便我的代码更高效,而不是那么大。
public static void ResultsOfMoves(string PlayerMove, string MonsterMove, Monster CurrentMonster, Weapon CurrentWeapon, Armor CurrentArmor, Player CurrentPlayer)
{
//Monster Responses to Player
if (PlayerMove == "dodge" && MonsterMove == "heavy"||MonsterMove == "stealth")
{
if (MonsterMove == "heavy") { MonsterHeavyAttack(); }
if (MonsterMove == "stealth") { MonsterStealthAttack(); }
}
else if (PlayerMove == "charge" && MonsterMove == "dodge"||MonsterMove == "stealth")
{
if (MonsterMove == "dodge") { MonsterDodge(); }
if (MonsterMove == "stealth") { MonsterStealthAttack(); }
}
else if (PlayerMove == "block" && MonsterMove == "charge" || MonsterMove == "dodge")
{
if (MonsterMove == "charge") { MonsterChargeAttack(); }
if (MonsterMove == "dodge") { MonsterDodge(); }
}
else if (PlayerMove == "heavy" && MonsterMove == "block" || MonsterMove == "charge")
{
if (MonsterMove == "block") { MonsterBlock(); }
if (MonsterMove == "charge") { MonsterChargeAttack(); }
}
else if (PlayerMove == "stealth" && MonsterMove == "heavy" || MonsterMove == "block")
{
if (MonsterMove == "heavy") { MonsterHeavyAttack(); }
if (MonsterMove == "block") { MonsterBlock(); }
}
//Players Responses To Monster
if (MonsterMove == "dodge" && PlayerMove == "heavy" || PlayerMove == "stealth")
{
if (PlayerMove == "heavy") { MonsterHeavyAttack(); }
if (PlayerMove == "stealth") { MonsterStealthAttack(); }
}
else if (MonsterMove == "charge" && PlayerMove == "dodge" || PlayerMove == "stealth")
{
if (PlayerMove == "dodge") { MonsterDodge(); }
if (PlayerMove == "stealth") { MonsterStealthAttack(); }
}
else if (MonsterMove == "block" && PlayerMove == "charge" || PlayerMove == "dodge")
{
if (PlayerMove == "charge") { MonsterChargeAttack(); }
if (PlayerMove == "dodge") { MonsterDodge(); }
}
else if (MonsterMove == "heavy" && PlayerMove == "block" || PlayerMove == "charge")
{
if (PlayerMove == "block") { MonsterBlock(); }
if (PlayerMove == "charge") { MonsterChargeAttack(); }
}
else if (MonsterMove == "stealth" && PlayerMove == "heavy" || PlayerMove == "block")
{
if (PlayerMove == "heavy") { MonsterHeavyAttack(); }
if (PlayerMove == "block") { MonsterBlock(); }
}
}