为了账号安全,请及时绑定邮箱和手机立即绑定

将对象的参数传递和更改为do while循环

将对象的参数传递和更改为do while循环

C#
慕盖茨4494581 2021-05-03 17:34:01
我想做的就是,当玩家或怪物的HP达到0时,战斗就结束了。就目前的情况来看,即使数字变为负数,循环也继续运行。我无法弄清楚这是循环本身还是当播放器选择其类时尝试切换以实例化新播放器类对象的方式出现问题。创建播放器类的代码:using System;using static System.Console;namespace _350_final_project{    public class Story    {        public Player choosenClass; //player's choosen class        Encounter newEncounter = new Encounter();        public Player ChooseClass(string choice)    //to run and allow player to pick from 3 different classes by intantiate an instance depending on their answer        {            switch (choice.ToLower())            {                case "warrior":                    choosenClass = new Player()                    {                        maxPlayerHealth = 150,                        currentPlayerHealth = 150,                        playerDamage = 35,                        playerDef = 120,                        playerStrength = 95,                        playerAgility = 30,                        playerExperience = 0                    };                    WriteLine("You have choosen the path of the Warrior. Live by the sword. Die by the sword! \n");                    return choosenClass;                case "theif":                    choosenClass = new Player()                    {                        maxPlayerHealth = 85,                        currentPlayerHealth = 85,                        playerDamage = 27,                        playerDef = 43,                        playerStrength = 20,                        playerAgility = 125,                        playerExperience = 0                    };                    WriteLine("You have choosen to lurk in the shadows as a theif \n");                    return choosenClass;                case "gunner":                    choosenClass = new Player()                    };        }    }}
查看完整描述

1 回答

?
aluckdog

TA贡献1847条经验 获得超7个赞

while 条件看起来不对。只要怪物和玩家的当前生命值大于0,它就应该循环。而且,您还需要在循环内减少其生命值。


查看完整回答
反对 回复 2021-05-29
  • 1 回答
  • 0 关注
  • 114 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信