Replies: 12 comments 4 replies
-
小4 ( 程式 ) 答案using System;
namespace PG0005.Questions
{
public class Question1
{
public class Job
{
public string Name { get; }
#region -- Constructor --
public Job(string name)
{
Name = name;
}
#endregion
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level++;
}
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
int originalLevel = character.Level;
character.Level = 1;
for (int i = 0; i < originalLevel - 1; i++)
{
OnLevelUp(character);
}
}
}
public class Novice : Job
{
//初心者(Novice )
//每級提升
//MaxHp + 10
//MaxMp + 5
//PhyAtk + 1
public Novice(string name) : base(name)
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += 10;
character.MaxMp += 5;
character.PhyAtk += 1;
}
}
public class Knight : Job
{
//騎士(Knight)
//每級提升
//MaxHp + 25
//MaxMp + 5
//PhyAtk + 5
//PhyDef + 3
public Knight(string name) : base(name)
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += 25;
character.MaxMp += 5;
character.PhyAtk += 5;
character.PhyDef += 3;
}
}
public class Magician : Job
{
//魔法師(Magician)
//每級提升
//MaxHp + 5
//MaxMp + 30
//MagAtk + 8
//MagDef + 3
public Magician(string name) : base(name)
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += 5;
character.MaxMp += 30;
character.MagAtk += 8;
character.MagDef += 3;
}
}
public class Character
{
public int Level = 1;
public int MaxHp = 100;
public int MaxMp = 50;
public int PhyAtk = 10;
public int PhyDef = 10;
public int MagAtk = 5;
public int MagDef = 5;
}
}
} 反饋好耶頭香 一開始的Job.OnLevelUp想了好久 才知道是把Test的basic手動輸入進去 做完偷看老師做的覺得自己的code跟醜八怪一樣 |
Beta Was this translation helpful? Give feedback.
-
老蕭OLDShaw(程式) 我的答案 public class Question1
{
public class Job
{
public string Name { get; }
#region -- Constructor --
public Job(string name)
{
/* ト~ゥモョノ。AーOアoォナァiォリコc、lィテェスアオシg、Jツセキ~ヲWコル */
Name = name;
}
#endregion
/// <summary>
/// Call on level up, fix the properties of the character
/// </summary>
/// <param name="character">the characher will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
/// <exception cref="ArgumentException">character level is highest</exception>
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level++;
}
/// <summary>
/// Call on job selected, fix the properties of the character
/// </summary>
/// <param name="character">the character will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
int originalLevel = character.Level;
character.ResetStats();
character.Level = originalLevel;
}
}
public class Novice : Job
{
int MaxHpGrowth = 10;
int MaxMpGrowth = 5;
int PhyAtkGrowth = 1;
public Novice(string name) : base(name)
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += MaxHpGrowth;
character.MaxMp += MaxMpGrowth;
character.PhyAtk += PhyAtkGrowth;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp += (character.Level - 1) * MaxHpGrowth;
character.MaxMp += (character.Level - 1) * MaxMpGrowth;
character.PhyAtk += (character.Level - 1) * PhyAtkGrowth;
}
}
public class Knight : Job
{
int MaxHpGrowth = 25;
int MaxMpGrowth = 5;
int PhyAtkGrowth = 5;
int PhyDefGrowth = 3;
public Knight(string name) : base(name)
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += MaxHpGrowth;
character.MaxMp += MaxMpGrowth;
character.PhyAtk += PhyAtkGrowth;
character.PhyDef += PhyDefGrowth;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp += (character.Level - 1) * MaxHpGrowth;
character.MaxMp += (character.Level - 1) * MaxMpGrowth;
character.PhyAtk += (character.Level - 1) * PhyAtkGrowth;
character.PhyDef += (character.Level - 1) * PhyDefGrowth;
}
}
public class Magician : Job
{
int MaxHpGrowth = 5;
int MaxMpGrowth = 30;
int MagAtkGrowth = 8;
int MagDefGrowth = 3;
public Magician(string name) : base(name)
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += MaxHpGrowth;
character.MaxMp += MaxMpGrowth;
character.MagAtk += MagAtkGrowth;
character.MagDef += MagDefGrowth;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp += (character.Level - 1) * MaxHpGrowth;
character.MaxMp += (character.Level - 1) * MaxMpGrowth;
character.MagAtk += (character.Level - 1) * MagAtkGrowth;
character.MagDef += (character.Level - 1) * MagDefGrowth;
}
}
public class Character
{
int _baseLevel = 1;
int _baseMaxHp = 100;
int _baseMaxMp = 50;
int _basePhyAtk = 10;
int _basePhyDef = 10;
int _baseMagAtk = 5;
int _baseMagDef = 5;
public int Level;
public int MaxHp;
public int MaxMp;
public int PhyAtk;
public int PhyDef;
public int MagAtk;
public int MagDef;
public Character()
{
ResetStats();
}
public void ResetStats()
{
Level = _baseLevel;
MaxHp = _baseMaxHp;
MaxMp = _baseMaxMp;
PhyAtk = _basePhyAtk;
PhyDef = _basePhyDef;
MagAtk = _baseMagAtk;
MagDef = _baseMagDef;
}
}
} 一開始不知道有固定的初始值,我全部填0,測試一直過不了。 還有不知道是Github還是VS轉碼的問題,我的Job的建構子註解裡面有一行變亂碼。 |
Beta Was this translation helpful? Give feedback.
-
JIA(程式新手) 我的答案using System;
namespace PG0005.Questions
{
public class Question1
{
public class Job
{
public virtual int MaxHpGrow => 0;
public virtual int MaxMpGrow => 0;
public virtual int PhyAtkGrow => 0;
public virtual int PhyDefGrow => 0;
public virtual int MagAtkGrow => 0;
public virtual int MagDefGrow => 0;
public string Name { get; }
public Job(string name)
{
Name = name;
}
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level += 1;
var notCorrection = character.Level <= 1;
if (notCorrection) return;
character.MaxHp += MaxHpGrow;
character.MaxMp += MaxMpGrow;
character.PhyAtk += PhyAtkGrow;
character.PhyDef += PhyDefGrow;
character.MagAtk += MagAtkGrow;
character.MagDef += MagDefGrow;
}
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
var level = character.Level;
character.Reset();
character.Level = level;
var notCorrection = character.Level <= 1;
if (notCorrection) return;
var correctionMultiple = level - 1;
character.MaxHp += MaxHpGrow * correctionMultiple;
character.MaxMp += MaxMpGrow * correctionMultiple;
character.PhyAtk += PhyAtkGrow * correctionMultiple;
character.PhyDef += PhyDefGrow * correctionMultiple;
character.MagAtk += MagAtkGrow * correctionMultiple;
character.MagDef += MagDefGrow * correctionMultiple;
}
}
public class Novice : Job
{
public override int MaxHpGrow => 10;
public override int MaxMpGrow => 5;
public override int PhyAtkGrow => 1;
public Novice(string name) : base(name) { }
}
public class Knight : Job
{
public override int MaxHpGrow => 25;
public override int MaxMpGrow => 5;
public override int PhyAtkGrow => 5;
public override int PhyDefGrow => 3;
public Knight(string name) : base(name) { }
}
public class Magician : Job
{
public override int MaxHpGrow => 5;
public override int MaxMpGrow => 30;
public override int MagAtkGrow => 8;
public override int MagDefGrow => 3;
public Magician(string name) : base(name) { }
}
public class Character
{
public int Level;
public int MaxHp;
public int MaxMp;
public int PhyAtk;
public int PhyDef;
public int MagAtk;
public int MagDef;
public Character()
{
Reset();
}
public void Reset()
{
Level = 1;
MaxHp = 100;
MaxMp = 50;
PhyAtk = 10;
PhyDef = 10;
MagAtk = 5;
MagDef = 5;
}
}
}
} 我的反饋1. 建議投影片中加入職業的基本數值(我一開始以為基礎數值都是0,直到看到單元測試那邊的基礎數值設定) |
Beta Was this translation helpful? Give feedback.
-
小鲨 (程式) 答案public class Question1
{
public class Job
{
public string Name { get; }
#region -- Constructor --
public Job(string name)
{
/* 繼承時,記得宣告建構子並直接寫入職業名稱 */
Name = name;
}
#endregion
/// <summary>
/// Call on level up, fix the properties of the character
/// </summary>
/// <param name="character">the characher will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
/// <exception cref="ArgumentException">character level is highest</exception>
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level += 1;
UpdateStat(character);
}
/// <summary>
/// Call on job selected, fix the properties of the character
/// </summary>
/// <param name="character">the character will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
UpdateStat(character);
}
protected virtual void UpdateStat(Character character)
{
character.SetStatToBasic();
}
}
public class Novice : Job
{
private const int NoviceMaxHpGrow = 10;
private const int NoviceMaxMpGrow = 5;
private const int NovicePhyAtkGrow = 1;
public Novice() : base("Novice") { }
public override void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level += 1;
UpdateStat(character);
}
public override void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
UpdateStat(character);
}
protected override void UpdateStat(Character character)
{
base.UpdateStat(character);
character.MaxHp += NoviceMaxHpGrow * (character.Level - 1);
character.MaxMp += NoviceMaxMpGrow * (character.Level - 1);
character.PhyAtk += NovicePhyAtkGrow * (character.Level - 1);
}
}
public class Knight : Job
{
private const int KnightMaxHpGrow = 25;
private const int KnightMaxMpGrow = 5;
private const int KnightPhyAtkGrow = 5;
private const int KnightPhyDefGrow = 3;
public Knight() : base("Knight") { }
public override void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level += 1;
UpdateStat(character);
}
public override void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
UpdateStat(character);
}
protected override void UpdateStat(Character character)
{
base.UpdateStat(character);
character.MaxHp += KnightMaxHpGrow * (character.Level - 1);
character.MaxMp += KnightMaxMpGrow * (character.Level - 1);
character.PhyAtk += KnightPhyAtkGrow * (character.Level - 1);
character.PhyDef += KnightPhyDefGrow * (character.Level - 1);
}
}
public class Magician : Job
{
public const int MagicianMaxHpGrow = 5;
public const int MagicianMaxMpGrow = 30;
public const int MagicianMagAtkGrow = 8;
public const int MagicianMagDefGrow = 3;
public Magician() : base("Magician") { }
public override void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level += 1;
UpdateStat(character);
}
public override void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
UpdateStat(character);
}
protected override void UpdateStat(Character character)
{
base.UpdateStat(character);
character.MaxHp += MagicianMaxHpGrow * (character.Level - 1);
character.MaxMp += MagicianMaxMpGrow * (character.Level - 1);
character.MagAtk += MagicianMagAtkGrow * (character.Level - 1);
character.MagDef += MagicianMagDefGrow * (character.Level - 1);
}
}
public class Character
{
public int Level;
public int MaxHp, MaxMp;
public int PhyAtk, PhyDef;
public int MagAtk, MagDef;
public const int BasicMaxHp = 100;
public const int BasicMaxMp = 50;
public const int BasicPhyAtk = 10;
public const int BasicPhyDef = 10;
public const int BasicMagAtk = 5;
public const int BasicMagDef = 5;
public Character()
{
Level = 1;
SetStatToBasic();
}
public void SetStatToBasic()
{
MaxHp = BasicMaxHp;
MaxMp = BasicMaxMp;
PhyAtk = BasicPhyAtk;
PhyDef = BasicPhyDef;
MagAtk = BasicMagAtk;
MagDef = BasicMagDef;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
七七(程式) 我的答案public class Question1
{
public class Job
{
public string Name { get; }
#region -- Constructor --
public Job(string name)
{
Name = name;
}
#endregion
/// <summary>
/// Call on level up, fix the properties of the character
/// </summary>
/// <param name="character">the character will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
/// <exception cref="ArgumentException">character level is highest</exception>
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level++;
}
/// <summary>
/// Call on job selected, fix the properties of the character
/// </summary>
/// <param name="character">the character will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
var level = character.Level;
character.Reset();
character.Level = level;
}
}
public class Novice : Job
{
int addHp = 10;
int addMp = 5;
int addPhyAtk = 1;
public Novice()
: base("Novice") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += addHp;
character.MaxMp += addMp;
character.PhyAtk += addPhyAtk;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
int levelGap = character.Level - 1;
character.MaxHp += levelGap * addHp;
character.MaxMp += levelGap * addMp;
character.PhyAtk += levelGap * addPhyAtk;
}
}
public class Knight : Job
{
int addHp = 25;
int addMp = 5;
int addPhyAtk = 5;
int addPhyDef = 3;
public Knight()
: base("Knight") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += addHp;
character.MaxMp += addMp;
character.PhyAtk += addPhyAtk;
character.PhyDef += addPhyDef;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
int levelGap = character.Level - 1;
character.MaxHp += levelGap * addHp;
character.MaxMp += levelGap * addMp;
character.PhyAtk += levelGap * addPhyAtk;
character.PhyDef += levelGap * addPhyDef;
}
}
public class Magician : Job
{
int addHp = 5;
int addMp = 30;
int addMagAtk = 8;
int addMagDef = 3;
public Magician()
: base("Magician") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += addHp;
character.MaxMp += addMp;
character.MagAtk += addMagAtk;
character.MagDef += addMagDef;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
int levelGap = character.Level - 1;
character.MaxHp += levelGap * addHp;
character.MaxMp += levelGap * addMp;
character.MagAtk += levelGap * addMagAtk;
character.MagDef += levelGap * addMagDef;
}
}
public class Character
{
public const int BasicLevel = 1;
public const int BasicMaxHp = 100;
public const int BasicMaxMp = 50;
public const int BasicPhyAtk = 10;
public const int BasicPhyDef = 10;
public const int BasicMagAtk = 5;
public const int BasicMagDef = 5;
public int Level;
public int MaxHp,
MaxMp;
public int PhyAtk,
PhyDef;
public int MagAtk,
MagDef;
public Character()
{
Level = BasicLevel;
MaxHp = BasicMaxHp;
MaxMp = BasicMaxMp;
PhyAtk = BasicPhyAtk;
PhyDef = BasicPhyDef;
MagAtk = BasicMagAtk;
MagDef = BasicMagDef;
}
public void Reset()
{
Level = BasicLevel;
MaxHp = BasicMaxHp;
MaxMp = BasicMaxMp;
PhyAtk = BasicPhyAtk;
PhyDef = BasicPhyDef;
MagAtk = BasicMagAtk;
MagDef = BasicMagDef;
}
}
} 回饋: |
Beta Was this translation helpful? Give feedback.
-
罐頭(程式) 我的答案ヾ(•ω•`)opublic class Question1
{
public class Job
{
public string Name { get; }
#region -- Constructor --
public Job(string name)
{
/* 繼承時,記得宣告建構子並直接寫入職業名稱 */
Name = name;
}
#endregion
/// <summary>
/// Call on level up, fix the properties of the character
/// </summary>
/// <param name="character">the characher will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
/// <exception cref="ArgumentException">character level is highest</exception>
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level++;
}
/// <summary>
/// Call on job selected, fix the properties of the character
/// </summary>
/// <param name="character">the character will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
character.MaxHp = 100;
character.MaxMp = 50;
character.PhyAtk = 10;
character.PhyDef = 10;
character.MagAtk = 5;
character.MagDef = 5;
}
}
public class Novice : Job
{
public Novice() : base("Novice")
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += 10;
character.MaxMp += 5;
character.PhyAtk += 1;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
int amount = character.Level - 1;
character.MaxHp += 10 * amount;
character.MaxMp += 5 * amount;
character.PhyAtk += amount;
}
}
public class Knight : Job
{
public Knight() : base("Knight")
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += 25;
character.MaxMp += 5;
character.PhyAtk += 5;
character.PhyDef += 3;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
int amount = character.Level - 1;
character.MaxHp += 25 * amount;
character.MaxMp += 5 * amount;
character.PhyAtk += 5 * amount;
character.PhyDef += 3 * amount;
}
}
public class Magician : Job
{
public Magician() : base("Magician")
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += 5;
character.MaxMp += 30;
character.MagAtk += 8;
character.MagDef += 3;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
int amount = character.Level - 1;
character.MaxHp += 5 * amount;
character.MaxMp += 30 * amount;
character.MagAtk += 8 * amount;
character.MagDef += 3 * amount;
}
}
public class Character
{
public int
Level = 1,
MaxHp = 100,
MaxMp = 50,
PhyAtk = 10,
PhyDef = 10,
MagAtk = 5,
MagDef = 5;
}
} 寫完之後雖然都能拿到緣勾勾,但一直覺得沒有寫得很好。(;´д`)ゞ |
Beta Was this translation helpful? Give feedback.
-
Snoweve (程式) 我的答案using System;
namespace PG0005.Questions
{
public class Question1
{
public class Job
{
public string Name { get; }
#region -- Constructor --
public Job(string name)
{
/* 繼承時,記得宣告建構子並直接寫入職業名稱 */
Name = name;
}
#endregion
/// <summary>
/// Call on level up, fix the properties of the character
/// </summary>
/// <param name="character">the characher will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
/// <exception cref="ArgumentException">character level is highest</exception>
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level++;
}
/// <summary>
/// Call on job selected, fix the properties of the character
/// </summary>
/// <param name="character">the character will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
int originalLevel = character.Level;
character.ResetState();
character.Level = originalLevel;
}
}
public class Novice : Job
{
#region GrowAblity
public const int Grow_MaxHP = 10;
public const int Grow_MaxMP = 5;
public const int Grow_PhyAtk = 1;
#endregion
public Novice() : base("Novice") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += Grow_MaxHP;
character.MaxMp += Grow_MaxMP;
character.PhyAtk += Grow_PhyAtk;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp += Grow_MaxHP * (character.Level-1);
character.MaxMp += Grow_MaxMP * (character.Level - 1);
character.PhyAtk += Grow_PhyAtk * (character.Level - 1);
}
}
public class Knight : Job
{
#region GrowAblity
public const int Grow_MaxHP = 25;
public const int Grow_MaxMP = 5;
public const int Grow_PhyAtk = 5;
public const int Grow_PhyDef = 3;
#endregion
public Knight() : base("Knight") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += Grow_MaxHP;
character.MaxMp += Grow_MaxMP;
character.PhyAtk += Grow_PhyAtk;
character.PhyDef += Grow_PhyDef;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp += Grow_MaxHP * (character.Level - 1);
character.MaxMp += Grow_MaxMP * (character.Level - 1);
character.PhyAtk += Grow_PhyAtk * (character.Level - 1);
character.PhyDef += Grow_PhyDef * (character.Level - 1);
}
}
public class Magician : Job
{
#region GrowAblity
public const int Grow_MaxHP = 5;
public const int Grow_MaxMP = 30;
public const int Grow_MagAtk = 8;
public const int Grow_MagDef = 3;
#endregion
public Magician() : base("Magician") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += Grow_MaxHP;
character.MaxMp += Grow_MaxMP;
character.MagAtk += Grow_MagAtk;
character.MagDef += Grow_MagDef;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp += Grow_MaxHP * (character.Level - 1);
character.MaxMp += Grow_MaxMP * (character.Level - 1);
character.MagAtk += Grow_MagAtk * (character.Level - 1);
character.MagDef += Grow_MagDef * (character.Level - 1);
}
}
public class Character
{
#region BasicState
public const int BasicLevel = 1;
public const int BasicMaxHp = 100;
public const int BasicMaxMp = 50;
public const int BasicPhyAtk = 10;
public const int BasicPhyDef = 10;
public const int BasicMagAtk = 5;
public const int BasicMagDef = 5;
#endregion
public int Level;
public int MaxHp, MaxMp;
public int PhyAtk, PhyDef;
public int MagAtk, MagDef;
#region constructor
public Character()
{
Level = BasicLevel;
MaxHp = BasicMaxHp;
MaxMp = BasicMaxMp;
PhyAtk = BasicPhyAtk;
PhyDef = BasicPhyDef;
MagAtk = BasicMagAtk;
MagDef = BasicMagDef;
}
#endregion
public void ResetState()
{
Level = BasicLevel;
MaxHp = BasicMaxHp;
MaxMp = BasicMaxMp;
PhyAtk = BasicPhyAtk;
PhyDef = BasicPhyDef;
MagAtk = BasicMagAtk;
MagDef = BasicMagDef;
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Cliff Lee CL (程式、專案管理) 我的答案 public class Question1
{
public class Job
{
public string Name { get; }
#region -- Constructor --
public Job(string name)
{
/* 繼承時,記得宣告建構子並直接寫入職業名稱 */
Name = name;
}
#endregion
/// <summary>
/// Call on level up, fix the properties of the character
/// </summary>
/// <param name="character">the characher will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
/// <exception cref="ArgumentException">character level is highest</exception>
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level++;
}
/// <summary>
/// Call on job selected, fix the properties of the character
/// </summary>
/// <param name="character">the character will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
character.MaxHp = Character.BasicMaxHp;
character.MaxMp = Character.BasicMaxMp;
character.PhyAtk = Character.BasicPhyAtk;
character.PhyDef = Character.BasicPhyDef;
character.MagAtk = Character.BasicMagAtk;
character.MagDef = Character.BasicMagDef;
}
}
public class Novice : Job
{
public const int NoviceMaxHpGrow = 10;
public const int NoviceMaxMpGrow = 5;
public const int NovicePhyAtkGrow = 1;
public Novice() : base("Novice")
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += NoviceMaxHpGrow;
character.MaxMp += NoviceMaxMpGrow;
character.PhyAtk += NovicePhyAtkGrow;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
var levelDiff = character.Level - 1;
character.MaxHp += NoviceMaxHpGrow * levelDiff;
character.MaxMp += NoviceMaxMpGrow * levelDiff;
character.PhyAtk += NovicePhyAtkGrow * levelDiff;
}
}
public class Knight : Job
{
public const int KnightMaxHpGrow = 25;
public const int KnightMaxMpGrow = 5;
public const int KnightPhyAtkGrow = 5;
public const int KnightPhyDefGrow = 3;
public Knight() : base("Knight")
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += KnightMaxHpGrow;
character.MaxMp += KnightMaxMpGrow;
character.PhyAtk += KnightPhyAtkGrow;
character.PhyDef += KnightPhyDefGrow;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
var levelDiff = character.Level - 1;
character.MaxHp += KnightMaxHpGrow * levelDiff;
character.MaxMp += KnightMaxMpGrow * levelDiff;
character.PhyAtk += KnightPhyAtkGrow * levelDiff;
character.PhyDef += KnightPhyDefGrow * levelDiff;
}
}
public class Magician : Job
{
public const int MagicianMaxHpGrow = 5;
public const int MagicianMaxMpGrow = 30;
public const int MagicianMagAtkGrow = 8;
public const int MagicianMagDefGrow = 3;
public Magician() : base("Magician")
{
}
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += MagicianMaxHpGrow;
character.MaxMp += MagicianMaxMpGrow;
character.MagAtk += MagicianMagAtkGrow;
character.MagDef += MagicianMagDefGrow;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
var levelDiff = character.Level - 1;
character.MaxHp += MagicianMaxHpGrow * levelDiff;
character.MaxMp += MagicianMaxMpGrow * levelDiff;
character.MagAtk += MagicianMagAtkGrow * levelDiff;
character.MagDef += MagicianMagDefGrow * levelDiff;
}
}
public class Character
{
public const int BasicLevel = 1;
public const int BasicMaxHp = 100;
public const int BasicMaxMp = 50;
public const int BasicPhyAtk = 10;
public const int BasicPhyDef = 10;
public const int BasicMagAtk = 5;
public const int BasicMagDef = 5;
public int Level = BasicLevel;
public int MaxHp = BasicMaxHp, MaxMp = BasicMaxMp;
public int PhyAtk = BasicPhyAtk, PhyDef = BasicPhyDef;
public int MagAtk = BasicMagAtk, MagDef = BasicMagDef;
}
} |
Beta Was this translation helpful? Give feedback.
-
Syuan(新人/企劃/程式/美術) 我的答案public class Question1
{
public class Job
{
public string Name { get; }
#region -- Constructor --
public Job(string name)
{
Name = name;
}
#endregion
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.Level++;
}
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
int oldLevel = character.Level;
character.abilityReset();
character.Level = oldLevel;
}
}
public class Novice : Job
{
public const int MaxHpUp = 10;
public const int MaxMpUp = 5;
public const int PhyAtkUp = 1;
public Novice() : base("Novice") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += MaxHpUp;
character.MaxMp += MaxMpUp;
character.PhyAtk += PhyAtkUp;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
int levelUp = character.Level - 1;
character.MaxHp += MaxHpUp * levelUp;
character.MaxMp += MaxMpUp * levelUp;
character.PhyAtk += PhyAtkUp * levelUp;
}
}
public class Knight : Job
{
public const int MaxHpUp = 25;
public const int MaxMpUp = 5;
public const int PhyAtkUp = 5;
public const int PhyDefUp = 3;
public Knight() : base("Knight") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += MaxHpUp;
character.MaxMp += MaxMpUp;
character.PhyAtk += PhyAtkUp;
character.PhyDef += PhyDefUp;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
int levelUp = character.Level - 1;
character.MaxHp += MaxHpUp * levelUp;
character.MaxMp += MaxMpUp * levelUp;
character.PhyAtk += PhyAtkUp * levelUp;
character.PhyDef += PhyDefUp * levelUp;
}
}
public class Magician : Job
{
public const int MaxHpUp = 5;
public const int MaxMpUp = 30;
public const int MagAtkUp = 8;
public const int MagDefUp = 3;
public Magician() : base("Magician") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += MaxHpUp;
character.MaxMp += MaxMpUp;
character.MagAtk += MagAtkUp;
character.MagDef += MagDefUp;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
int levelUp = character.Level - 1;
character.MaxHp += MaxHpUp * levelUp;
character.MaxMp += MaxMpUp * levelUp;
character.MagAtk += MagAtkUp * levelUp;
character.MagDef += MagDefUp * levelUp;
}
}
public class Character
{
public const int BasicLevel = 1;
public const int BasicMaxHp = 100;
public const int BasicMaxMp = 50;
public const int BasicPhyAtk = 10;
public const int BasicPhyDef = 10;
public const int BasicMagAtk = 5;
public const int BasicMagDef = 5;
public int Level;
public int MaxHp;
public int MaxMp;
public int PhyAtk;
public int PhyDef;
public int MagAtk;
public int MagDef;
public Character()
{
abilityReset();
}
public void abilityReset()
{
Level = BasicLevel;
MaxHp = BasicMaxHp;
MaxMp = BasicMaxMp;
PhyAtk = BasicPhyAtk;
PhyDef = BasicPhyDef;
MagAtk = BasicMagAtk;
MagDef = BasicMagDef;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
肥羊(程式) 我的答案public class Question1
{
public class Job
{
public string Name { get; }
#region -- Constructor --
public Job(string name)
{
/* 繼承時,記得宣告建構子並直接寫入職業名稱 */
Name = name;
}
#endregion
/// <summary>
/// Call on level up, fix the properties of the character
/// </summary>
/// <param name="character">the characher will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
/// <exception cref="ArgumentException">character level is highest</exception>
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
character.level++;
}
/// <summary>
/// Call on job selected, fix the properties of the character
/// </summary>
/// <param name="character">the character will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
int level = character.level;
character.JobReset();
character.level = level;
}
}
public class Novice : Job
{
#region Level Scaling
public const int MaxHpGrow = 10;
public const int MaxMPGrow = 5;
public const int PhyAtkGrow = 1;
#endregion
public Novice() : base("Novice") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.maxHp += MaxHpGrow;
character.maxMp += MaxMPGrow;
character.phyAtk += PhyAtkGrow;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
var scalinglevel = character.level - 1;
character.maxHp += MaxHpGrow * scalinglevel;
character.maxMp += MaxMPGrow * scalinglevel;
character.phyAtk += PhyAtkGrow * scalinglevel;
}
}
public class Knight : Job
{
#region Level Scaling
public const int MaxHpGrow = 25;
public const int MaxMPGrow = 5;
public const int PhyAtkGrow = 5;
public const int PhyDefGrow = 3;
#endregion
public Knight() : base("Knight") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.maxHp += MaxHpGrow;
character.maxMp += MaxMPGrow;
character.phyAtk += PhyAtkGrow;
character.phyDef += PhyDefGrow;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
var scalinglevel = character.level - 1;
character.maxHp += MaxHpGrow * scalinglevel;
character.maxMp += MaxMPGrow * scalinglevel;
character.phyAtk += PhyAtkGrow * scalinglevel;
character.phyDef += PhyDefGrow * scalinglevel;
}
}
public class Magician : Job
{
#region Level Scaling
public const int MaxHpGrow = 5;
public const int MaxMPGrow = 30;
public const int MagAtkGrow = 8;
public const int MagDefGrow = 3;
#endregion
public Magician() : base("Magician") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.maxHp += MaxHpGrow;
character.maxMp += MaxMPGrow;
character.magAtk += MagAtkGrow;
character.magDef += MagDefGrow;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
var scalinglevel = character.level - 1;
character.maxHp += MaxHpGrow * scalinglevel;
character.maxMp += MaxMPGrow * scalinglevel;
character.magAtk += MagAtkGrow * scalinglevel;
character.magDef += MagDefGrow * scalinglevel;
}
}
public class Character
{
#region basic state
public const int basicLevel = 1;
public const int basicMaxHp = 100;
public const int basicMaxMp = 50;
public const int basicPhyAtk = 10;
public const int basicPhyDef = 10;
public const int basicMagAtk = 5;
public const int basicMagDef = 5;
#endregion
public int level;
public int maxHp, maxMp;
public int phyAtk, phyDef;
public int magAtk, magDef;
public Character()
{
level = basicLevel;
maxHp = basicMaxHp;
maxMp = basicMaxMp;
phyAtk = basicPhyAtk;
phyDef = basicPhyDef;
magAtk = basicMagAtk;
magDef = basicMagDef;
}
public void JobReset()
{
level = basicLevel;
maxHp = basicMaxHp;
maxMp = basicMaxMp;
phyAtk = basicPhyAtk;
phyDef = basicPhyDef;
magAtk = basicMagAtk;
magDef = basicMagDef;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
肉鬆(程式 / 音樂) Ansusing System;
namespace PG0005.Questions
{
public class Question1
{
public class Job
{
public string Name { get; }
public Job(string name)
{
Name = name;
}
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level was MAX!");
}
character.Level++;
}
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
int originalLevel = character.Level;
character.ResetStats();
character.Level = originalLevel;
}
}
public class Novice : Job
{
int MaxHpGrowth = 10;
int MaxMpGrowth = 5;
int PhyAtkGrowth = 1;
public Novice() : base("Novice") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += MaxHpGrowth;
character.MaxMp += MaxMpGrowth;
character.PhyAtk += PhyAtkGrowth;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp += (character.Level - 1) * MaxHpGrowth;
character.MaxMp += (character.Level - 1) * MaxMpGrowth;
character.PhyAtk += (character.Level - 1) * PhyAtkGrowth;
}
}
public class Knight : Job
{
int MaxHpGrowth = 25;
int MaxMpGrowth = 5;
int PhyAtkGrowth = 5;
int PhyDefGrowth = 3;
public Knight() : base("Knight") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += MaxHpGrowth;
character.MaxMp += MaxMpGrowth;
character.PhyAtk += PhyAtkGrowth;
character.PhyDef += PhyDefGrowth;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp += (character.Level - 1) * MaxHpGrowth;
character.MaxMp += (character.Level - 1) * MaxMpGrowth;
character.PhyAtk += (character.Level - 1) * PhyAtkGrowth;
character.PhyDef += (character.Level - 1) * PhyDefGrowth;
}
}
public class Magician : Job
{
int MaxHpGrowth = 5;
int MaxMpGrowth = 30;
int MagAtkGrowth = 8;
int MagDefGrowth = 3;
public Magician() : base("Magician") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += MaxHpGrowth;
character.MaxMp += MaxMpGrowth;
character.MagAtk += MagAtkGrowth;
character.MagDef += MagDefGrowth;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp += (character.Level - 1) * MaxHpGrowth;
character.MaxMp += (character.Level - 1) * MaxMpGrowth;
character.MagAtk += (character.Level - 1) * MagAtkGrowth;
character.MagDef += (character.Level - 1) * MagDefGrowth;
}
}
public class Character
{
int _baseLevel = 1;
int _baseMaxHp = 100;
int _baseMaxMp = 50;
int _basePhyAtk = 10;
int _basePhyDef = 10;
int _baseMagAtk = 5;
int _baseMagDef = 5;
public int Level;
public int MaxHp;
public int MaxMp;
public int PhyAtk;
public int PhyDef;
public int MagAtk;
public int MagDef;
public Character()
{
ResetStats();
}
public void ResetStats()
{
Level = _baseLevel;
MaxHp = _baseMaxHp;
MaxMp = _baseMaxMp;
PhyAtk = _basePhyAtk;
PhyDef = _basePhyDef;
MagAtk = _baseMagAtk;
MagDef = _baseMagDef;
}
}
}
} 課程回饋謝謝老師 辛苦您了~ |
Beta Was this translation helpful? Give feedback.
-
極光(程式) 我的答案using System;
namespace PG0005.Questions
{
public class Question1
{
public class Job
{
public string Name { get; }
#region -- Constructor --
public Job(string name)
{
/* 繼承時,記得宣告建構子並直接寫入職業名稱 */
Name = name;
}
#endregion
/// <summary>
/// Call on level up, fix the properties of the character
/// </summary>
/// <param name="character">the characher will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
/// <exception cref="ArgumentException">character level is highest</exception>
public virtual void OnLevelUp(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
if (character.Level + 1 > 100)
{
throw new ArgumentException("character level is highest");
}
else
{
character.Level++;
}
}
/// <summary>
/// Call on job selected, fix the properties of the character
/// </summary>
/// <param name="character">the character will be fixed</param>
/// <exception cref="ArgumentNullException">character is null</exception>
public virtual void OnSelected(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character is null");
}
else
{
character.MaxHp = 100;
character.MaxMp = 50;
character.PhyAtk = 10;
character.PhyDef = 10;
character.MagAtk = 5;
character.MagDef = 5;
}
}
}
public class Novice : Job
{
public Novice() : base("Novice") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += 10;
character.MaxMp += 5;
character.PhyAtk += 1;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp = 100 + 10 * (character.Level - 1);
character.MaxMp = 50 + 5 * (character.Level - 1);
character.PhyAtk = 10 + 1 * (character.Level - 1);
}
}
public class Knight : Job
{
public Knight() : base("Knight") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += 25;
character.MaxMp += 5;
character.PhyAtk += 5;
character.PhyDef += 3;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp = 100 + 25 * (character.Level - 1);
character.MaxMp = 50 + 5 * (character.Level - 1);
character.PhyAtk = 10 + 5 * (character.Level - 1);
character.PhyDef = 10 + 3 * (character.Level - 1);
}
}
public class Magician :Job
{
public Magician() : base("Magician") { }
public override void OnLevelUp(Character character)
{
base.OnLevelUp(character);
character.MaxHp += 5;
character.MaxMp += 30;
character.MagAtk += 8;
character.MagDef += 3;
}
public override void OnSelected(Character character)
{
base.OnSelected(character);
character.MaxHp = 100 + 5 * (character.Level - 1);
character.MaxMp = 50 + 30 * (character.Level - 1);
character.MagAtk = 5 + 8 * (character.Level - 1);
character.MagDef = 5 + 3 * (character.Level - 1);
}
}
public class Character
{
public int Level=1;
public int MaxHp=100, MaxMp=50;
public int PhyAtk=10, PhyDef=10;
public int MagAtk=5, MagDef=5;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Introduction
請各位實作一個簡易的職業系統,需求如下:
程式碼Code
角色基礎數值
職業Job
初心者(Novice )
每級提升
MaxHp + 10
MaxMp + 5
PhyAtk + 1
騎士(Knight)
每級提升
MaxHp + 25
MaxMp + 5
PhyAtk + 5
PhyDef + 3
魔法師(Magician)
每級提升
MaxHp + 5
MaxMp + 30
MagAtk + 8
MagDef + 3
規則說明(Rule)
例如:20等初心者HP是290,轉成劍士則會變為575
備註
*測試檔案會有編譯錯誤,請同學們記得使用繼承來解決這個錯誤
Answer
解答
Beta Was this translation helpful? Give feedback.
All reactions