Replies: 23 comments 4 replies
-
Cliff Lee CL (程式、專案管理) 我的答案public class Question2 : MonoBehaviour
{
/// <summary>
/// Check if dodge occured
/// </summary>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is dodged or not</returns>
public bool Dodge(float dodgeRate, float rand)
{
return dodgeRate > rand;
}
/// <summary>
/// Check if block occured
/// </summary>
/// <param name="blockRate">The block rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is blocked or not</returns>
public bool Block(float blockRate, float rand)
{
return blockRate > rand;
}
/// <summary>
/// Modify attack point if dodge, block, or both occured
/// </summary>
/// <param name="atk">The attack point</param>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="blockRate">The block rate</param>
/// <param name="dodgeRand">The dodge random value</param>
/// <param name="blockRand">The block random value</param>
/// <returns>Modified attack point</returns>
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if (atk <= 0 || Dodge(dodgeRate, dodgeRand) || Block(blockRate, blockRand))
return 0;
return (int)atk;
}
} |
Beta Was this translation helpful? Give feedback.
-
JIA(程式新手) 我的答案public bool CheckProbability(float rate, float rand)
{
bool isRateGreaterThanZero = rate > 0;
bool isRate = rand <= rate;
return isRate && isRateGreaterThanZero;
}
public bool Dodge(float dodgeRate, float rand)
{
return CheckProbability(dodgeRate, rand);
}
public bool Block(float blockRate, float rand)
{
return CheckProbability(blockRate, rand);
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
bool isAtkLessThenZero = atk <= 0;
bool isDodge = Dodge(dodgeRate, dodgeRand);
bool isBlock = Block(blockRate, blockRand);
if (isAtkLessThenZero || isDodge || isBlock) return 0;
return (int)atk;
} |
Beta Was this translation helpful? Give feedback.
-
Syuan(新人) 我的答案 public bool Dodge(float dodgeRate, float rand)
{
return dodgeRate > rand;
}
public bool Block(float blockRate, float rand)
{
return blockRate > rand;
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if (atk <= 0 || Dodge(dodgeRate, dodgeRand) || Block(blockRate, blockRand)) return 0;
return (int)atk;
} |
Beta Was this translation helpful? Give feedback.
-
吉米(不知道要學什麼但是喜歡創作的新人) 我的答案在這/// <summary>
/// Check if dodge occured
/// </summary>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is dodged or not</returns>
public bool Dodge(float dodgeRate, float rand)
{
return dodgeRate > rand ? true:false;
}
/// <summary>
/// Check if block occured
/// </summary>
/// <param name="blockRate">The block rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is blocked or not</returns>
public bool Block(float blockRate, float rand)
{
return blockRate > rand ? true:false;
}
/// <summary>
/// Modify attack point if dodge, block, or both occured
/// </summary>
/// <param name="atk">The attack point</param>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="blockRate">The block rate</param>
/// <param name="dodgeRand">The dodge random value</param>
/// <param name="blockRand">The block random value</param>
/// <returns>Modified attack point</returns>
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if(atk < 0 || Block(blockRate, blockRand) || Dodge(dodgeRate, dodgeRand))
return 0;
else
return (int)atk;
} 更多..知識!! |
Beta Was this translation helpful? Give feedback.
-
罐頭(新人) 我的答案ヾ(•ω•`)o public class Question2 : MonoBehaviour
{
public bool Dodge(float dodgeRate, float rand)
{
return rand < dodgeRate;
}
public bool Block(float blockRate, float rand)
{
return rand < blockRate;
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if (atk < 0 || Dodge(dodgeRate, dodgeRand) || Block(blockRate, blockRand))
return 0;
return (int)atk;
}
} 如果也能閃閃+格擋躲避老闆的攻擊就好了(❤´艸`❤) |
Beta Was this translation helpful? Give feedback.
-
TWEdward(新人/程式) 我的答案public class Question2 : MonoBehaviour
{
bool A, B;
/// <summary>
/// Check if dodge occured
/// </summary>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is dodged or not</returns>
public bool Dodge(float dodgeRate, float rand)
{
//throw new NotImplementedException("code something here ...");
return rand < dodgeRate;
}
/// <summary>
/// Check if block occured
/// </summary>
/// <param name="blockRate">The block rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is blocked or not</returns>
public bool Block(float blockRate, float rand)
{
//throw new NotImplementedException("code something here ...");
return rand < blockRate;
}
/// <summary>
/// Modify attack point if dodge, block, or both occured
/// </summary>
/// <param name="atk">The attack point</param>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="blockRate">The block rate</param>
/// <param name="dodgeRand">The dodge random value</param>
/// <param name="blockRand">The block random value</param>
/// <returns>Modified attack point</returns>
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
//throw new NotImplementedException("code something here ...");
if (atk< 0)
{
return 0;
}
A = Dodge(dodgeRate, dodgeRand);
B = Block(blockRate, blockRand);
if (A||B)
{
return 0;
}
return (int)atk;
}
} 跟第一題一樣,也是單元測試的關係,程式碼重寫好幾次順便找原因在哪邊,多多經過單元測試的洗禮,我相信我程式能力一定可以進步很多 |
Beta Was this translation helpful? Give feedback.
-
riverRobot (新人/企劃/程式) 我的答案public class Question2 : MonoBehaviour
{
/// <summary>
/// Check if dodge occured
/// </summary>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is dodged or not</returns>
public bool Dodge(float dodgeRate, float rand)
{
return dodgeRate > rand;
}
/// <summary>
/// Check if block occured
/// </summary>
/// <param name="blockRate">The block rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is blocked or not</returns>
public bool Block(float blockRate, float rand)
{
return blockRate > rand;
}
/// <summary>
/// Modify attack point if dodge, block, or both occured
/// </summary>
/// <param name="atk">The attack point</param>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="blockRate">The block rate</param>
/// <param name="dodgeRand">The dodge random value</param>
/// <param name="blockRand">The block random value</param>
/// <returns>Modified attack point</returns>
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if(atk < 0)
return 0;
if( Dodge(dodgeRate, dodgeRand) || Block(blockRate, blockRand) )
return 0;
return (int)atk;
}
} 課程/作業心得單元測試在驗證上感覺蠻方便的,若能在設計功能時也設計好驗證項目,在測試跟Debug上應該能提升不少效率,感謝老師提供的作業檔案同時也可以作為基礎的範例來研究 |
Beta Was this translation helpful? Give feedback.
-
小4 ( 程式 ) public bool Dodge(float dodgeRate, float rand)
{
return dodgeRate > rand;
}
public bool Block(float blockRate, float rand)
{
return blockRate > rand;
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if (atk <= 0)
{
return 0;
}
bool isDodge = Dodge(dodgeRate, dodgeRand);
bool isBlock = Block(blockRate, blockRand);
return isDodge || isBlock ? 0 : (int)atk;
} |
Beta Was this translation helpful? Give feedback.
-
肥羊(程式) 我的答案public class Question2 : MonoBehaviour
{
public bool Dodge(float dodgeRate, float rand)
{
return dodgeRate > rand;
}
public bool Block(float blockRate, float rand)
{
return blockRate > rand;
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
bool isDodge = Dodge(dodgeRate, dodgeRand);
bool isBlock = Block(blockRate, blockRand);
if (atk < 0 || isDodge || isBlock)
return 0;
else
return (int)atk;
}
} 第一次接觸單元測試受益良多 |
Beta Was this translation helpful? Give feedback.
-
Suncacao(程式) 我的答案public class Question2 : MonoBehaviour
{
public bool Dodge(float dodgeRate, float rand)
{
if(dodgeRate > rand){
return true;
}else{
return false;
}
}
public bool Block(float blockRate, float rand)
{
if(blockRate > rand){
return true;
}else{
return false;
}
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if(atk <= 0f||Dodge(dodgeRate,dodgeRand)|| Block(blockRate,blockRand)){
return 0;
}else{
return (int)atk;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
老蕭OLDShaw(程式) 我的答案 public bool Dodge(float dodgeRate, float rand)
{
return rand < dodgeRate;
}
public bool Block(float blockRate, float rand)
{
return rand < blockRate;
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if (atk < 0) return 0;
if(Dodge(dodgeRate, dodgeRand) || Block(blockRate, blockRand))
{
return 0;
}
return (int)atk;
} |
Beta Was this translation helpful? Give feedback.
-
Snoweve (程式) 我的答案 public bool Dodge(float dodgeRate, float rand)
{
return dodgeRate > rand;
}
public bool Block(float blockRate, float rand)
{
return blockRate > rand;
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if (atk <= 0 || Dodge(dodgeRate, dodgeRand) || Block(blockRate, blockRand))
return 0;
return (int)atk;
} <<反饋>> |
Beta Was this translation helpful? Give feedback.
-
肉鬆(程式 / 音樂) 我的答案 public bool Dodge(float dodgeRate, float rand)
{
return rand < dodgeRate;
}
public bool Block(float blockRate, float rand)
{
return rand < blockRate;
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if (atk <= 0 || Dodge(dodgeRate, dodgeRand) || Block(blockRate, blockRand))
{
return 0;
}
return (int)atk;
} 謝謝勞贖 |
Beta Was this translation helpful? Give feedback.
-
ChiaBurn(程式 | 企劃) 作業程式碼 public bool Dodge(float dodgeRate, float rand)
{
return dodgeRate > rand;
}
public bool Block(float blockRate, float rand)
{
return blockRate > rand;
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if (atk <= 0)
{
return 0;
}
bool isDodgeSuccess = Dodge(dodgeRate, dodgeRand);
bool isBlockSuccess = Block(blockRate, blockRand);
if (isDodgeSuccess || isBlockSuccess)
{
return 0;
}
return (int)atk;
} 想法與反饋動工前我有先去看一下單元測試內容,發現這次的案例列得好多、好大一串!看完以後有種莫名的興奮感!(類似看到101的感覺?) |
Beta Was this translation helpful? Give feedback.
-
Tina( 程式 ) 我的答案using System;
using UnityEngine;
namespace PG0001.Questions
{
public class Question2 : MonoBehaviour
{
/// <summary>
/// Check if dodge occured
/// </summary>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is dodged or not</returns>
public bool Dodge(float dodgeRate, float rand)
{
return dodgeRate > rand;
}
/// <summary>
/// Check if block occured
/// </summary>
/// <param name="blockRate">The block rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is blocked or not</returns>
public bool Block(float blockRate, float rand)
{
return blockRate > rand;
}
/// <summary>
/// Modify attack point if dodge, block, or both occured
/// </summary>
/// <param name="atk">The attack point</param>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="blockRate">The block rate</param>
/// <param name="dodgeRand">The dodge random value</param>
/// <param name="blockRand">The block random value</param>
/// <returns>Modified attack point</returns>
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if(atk < 0){
Console.WriteLine("Wrong atk value.");
return 0;
}
bool isDodge = Dodge(dodgeRate, dodgeRand);
Console.WriteLine("Have dodge? " + isDodge);
bool isBlock = Block(blockRate, blockRand);
Console.WriteLine("Have block? " + isBlock);
if(isDodge || isBlock)
return 0;
else
return (int) atk;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
阿邦(企劃) 我的解答public bool Dodge(float dodgeRate, float rand)
{
if(rand < dodgeRate)
return true;
else
return false;
}
public bool Block(float blockRate, float rand)
{
if(rand < blockRate)
return true;
else
return false;
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if(atk < 0 || dodgeRand < dodgeRate || blockRand < blockRate)
return 0;
else
return (int)atk;
} 謝謝老師指教! |
Beta Was this translation helpful? Give feedback.
-
JSheng(程式) 我的答案public bool Dodge(float dodgeRate, float rand)
{
return rand < dodgeRate;
}
public bool Block(float blockRate, float rand)
{
return rand < blockRate;
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if(this.Dodge(dodgeRate, dodgeRand) || this.Block(blockRate, blockRand))
return 0;
return (int)Mathf.Max(atk, 0);
} |
Beta Was this translation helpful? Give feedback.
-
鮪魚腹排(新人) 謝謝OWO |
Beta Was this translation helpful? Give feedback.
-
七七(程式) 我的答案public class Question2 : MonoBehaviour
{
public bool Dodge(float dodgeRate, float rand)
{
if (dodgeRate > rand)
{
return true;
}
return false;
}
public bool Block(float blockRate, float rand)
{
if (blockRate > rand)
{
return true;
}
return false;
}
public int Damage(
float atk,
float dodgeRate,
float blockRate,
float dodgeRand,
float blockRand
)
{
if (atk < 0)
return 0;
if (Dodge(dodgeRate, dodgeRand) || Block(blockRate, blockRand))
{
return 0;
}
return (int)atk;
}
} 回頭補作業 ‹‹( ˙▿˙ )/››‹‹( ˙▿˙ )/›› |
Beta Was this translation helpful? Give feedback.
-
小鲨 (程式) 答案public class Question2 : MonoBehaviour
{
/// <summary>
/// Check if dodge occured
/// </summary>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is dodged or not</returns>
public bool Dodge(float dodgeRate, float rand)
{
return rand < dodgeRate;
}
/// <summary>
/// Check if block occured
/// </summary>
/// <param name="blockRate">The block rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is blocked or not</returns>
public bool Block(float blockRate, float rand)
{
return rand < blockRate;
}
/// <summary>
/// Modify attack point if dodge, block, or both occured
/// </summary>
/// <param name="atk">The attack point</param>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="blockRate">The block rate</param>
/// <param name="dodgeRand">The dodge random value</param>
/// <param name="blockRand">The block random value</param>
/// <returns>Modified attack point</returns>
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if (atk <= 0)
{
return 0;
}
return (int)(atk * (Dodge(dodgeRate, dodgeRand) ? 0 : 1) * (Block(blockRate, blockRand) ? 0 : 1));
}
} |
Beta Was this translation helpful? Give feedback.
-
歐雷(程式) 答案 public class Question2 : MonoBehaviour
{
/// <summary>
/// Check if dodge occured
/// </summary>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is dodged or not</returns>
public bool Dodge(float dodgeRate, float rand)
{
if (dodgeRate > rand) return true;
else return false;
}
/// <summary>
/// Check if block occured
/// </summary>
/// <param name="blockRate">The block rate</param>
/// <param name="rand">The random value</param>
/// <returns>Is blocked or not</returns>
public bool Block(float blockRate, float rand)
{
if (blockRate > rand) return true;
else return false;
}
/// <summary>
/// Modify attack point if dodge, block, or both occured
/// </summary>
/// <param name="atk">The attack point</param>
/// <param name="dodgeRate">The dodge rate</param>
/// <param name="blockRate">The block rate</param>
/// <param name="dodgeRand">The dodge random value</param>
/// <param name="blockRand">The block random value</param>
/// <returns>Modified attack point</returns>
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if (Dodge(dodgeRate, dodgeRand) || Block(blockRate, blockRand)) return 0;
else
{
if (atk < 0) return 0;
return (int)atk;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
極光(程式) 我的答案public bool Dodge(float dodgeRate, float rand)
{
if(dodgeRate>rand)
{
return true;
}
else
{
return false;
}
}
public bool Block(float blockRate, float rand)
{
if(blockRate>rand)
{
return true;
}
else
{
return false;
}
}
public int Damage(float atk, float dodgeRate, float blockRate, float dodgeRand, float blockRand)
{
if(atk<0)
{
return 0;
}
if(dodgeRate>dodgeRand||blockRate>blockRand)
{
return 0;
}
else
{
return (int)atk;
}
} 非常好課程 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
寫出計算格擋、迴避與傷害的函式
請注意題目有更改,把
rand
改成dodgeRand
並新增了blockRand
完整題目如下:
Answer
解答
與爆擊計算同理,這邊也只用小於符號去判斷。
Beta Was this translation helpful? Give feedback.
All reactions