1
我創建了一個控制檯應用程序,可以創建一個角色,修改一個角色,以及裝備武器並顯示用戶輸入的角色數據。我的第一個問題是。我如何去捕獲我的用戶條目並將這些值傳遞給我的構造函數。我創建了一個字符類,並創建了我的構造函數變量。我的角色課也包括了getters和setter。補充一點,我該如何爲這個角色裝備武器?將數據傳遞給構造類
static void CreateCharacter()
{
//Declare my variables
string charName;
int charBaseAttack;
int charHealth;
int charAge;
int charSaiyanLevel;
//Ask for user input
Console.Write("Please enter the name of your character");
charName = Console.ReadLine();
Console.Write("Thanks for that, now enter a Base Attack level please: ");
charBaseAttack = Convert.ToInt32(Console.ReadLine());
Console.Write("Thanks for that, now enter a Health level please: ");
charHealth = Convert.ToInt32(Console.ReadLine());
Console.Write("Thanks for that, now how old is your character: ");
charAge = Convert.ToInt32(Console.ReadLine());
Console.Write("Thanks for that, his or her Super Saiyan level please: ");
charSaiyanLevel = Convert.ToInt32(Console.ReadLine());
//Instantiate my person
Character userCharacter = new Character(charName, charBaseAttack, charHealth, charAge, charSaiyanLevel);
//我的角色等級
private string mName;
private int mBaseAttack;
private int mHealth;
private int mAge;
private int mSaiyanLevel;
public Character(string _mName, int _mBaseAttack, int _mHealth, int _mAge, int _mSaiyanLevel)
{
//Initializing my member varaibles
mName = _mName;
mBaseAttack = _mBaseAttack;
mHealth = _mHealth;
mAge = _mAge;
mSaiyanLevel = _mSaiyanLevel;
}
public Character()
{
Character userCharacter = new Character();
}
public string getName()
{
return mName;
}
public int getBaseAttack()
{
return mBaseAttack;
}
public int getHealth()
{
return mHealth;
}
public int getAge()
{
return mAge;
}
public int getSaiyanLevel()
{
return mSaiyanLevel;
}
public void setName(string _mName)
{
mName = _mName;
}
public void setBaseAttack(int _mBaseAttack)
{
mBaseAttack = _mBaseAttack;
}
public void setHealth(int _mHealth)
{
mHealth = _mHealth;
}
public void setAge(int _mAge)
{
mAge = _mAge;
}
public void setSaiyanLevel(int _SaiyanLevel)
{
mSaiyanLevel = _SaiyanLevel;
當您運行CreateCharacter()會發生什麼?它會提示用戶輸入他/她的內容嗎? – StaticBeagle
是的先生,這是正確的,它會提示用戶輸入字符屬性。 – JGreen5278
你是什麼意思,「我如何去捕獲我的用戶條目並將這些值傳遞給我的構造函數」? CreateCharacter方法似乎正確地創建了Character。 – StaticBeagle