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

我想做的就是,当玩家或怪物的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()

                    };

        }

    }

}


慕盖茨4494581
浏览 115回答 1
1回答

aluckdog

while 条件看起来不对。只要怪物和玩家的当前生命值大于0,它就应该循环。而且,您还需要在循环内减少其生命值。
打开App,查看更多内容
随时随地看视频慕课网APP