/// <summary> /// 消息提示信息HTML作成 /// </summary> /// <param name="item">題型參數</param> /// <returns>HTML模板</returns> private string GetTooltipHtml(SchoolClockFormula item) { StringBuilder html = new StringBuilder(); html.AppendLine(string.Format(TOOLTIP_HTML_FORMAT, item.LatestTime.GetTimeType.ToTimeSystemString(), item.LatestTime.TimeInterval.ToTimeIntervalTypeString())); return(html.ToString()); }
/// <summary> /// 時間段類型-深夜 /// </summary> /// <param name="formula">答題結果參數</param> /// <param name="type">指定分鐘數值</param> private void LateNightTimeInterval(SchoolClockFormula formula, FourOperationsType type) { // 深夜[22:XX~23:XX] formula.LatestTime.Hours = CommonUtil.GetRandomNumber(22, 23); // 分鐘數值 formula.LatestTime.Minutes = type == FourOperationsType.Random ? CommonUtil.GetRandomNumber(0, 59) : _assignMinutes[CommonUtil.GetRandomNumber(HourDivisionType.IntegralPoint, HourDivisionType.ThreeQuarters)]; // 秒數值 formula.LatestTime.Seconds = CommonUtil.GetRandomNumber(0, 59); }
/// <summary> /// 算式作成 /// </summary> /// <param name="p">題型參數</param> public override void MarkFormulaList(SchoolClockParameter p) { // 當前反推判定次數(一次推算內次數累加) int defeated = 0; // 按照指定數量作成相應的數學計算式 for (var i = 0; i < p.NumberOfQuestions; i++) { // 隨機獲取時間段類型中的一個類型 TimeIntervalType type = CommonUtil.GetRandomNumber(TimeIntervalType.Midnight, TimeIntervalType.LateNight); SchoolClockFormula formula = new SchoolClockFormula { LatestTime = new TimeType() { Hours = 0, Minutes = 0, Seconds = 0 } }; if (_timeIntervals.TryGetValue(type, out Action <SchoolClockFormula, FourOperationsType> timeInterval)) { timeInterval(formula, p.FourOperationsType); if (p.IsShowSeconds) { formula.LatestTime.Seconds = 0; } } else { throw new ArgumentException(MessageUtil.GetMessage(() => MsgResources.E0002L, type.ToString())); } if (CheckIsNeedInverseMethod(p.Formulas, formula)) { defeated++; // 如果大於兩次則認為此題無法作成繼續下一題 if (defeated == INVERSE_NUMBER) { // 當前反推判定次數復原 defeated = 0; continue; } i--; continue; } p.Formulas.Add(formula); } }
/// <summary> /// 判定是否需要反推并重新作成計算式 /// </summary> /// <remarks> /// 情況1:完全一致 /// 情況2:時分秒全零 /// </remarks> /// <param name="preFormulas">已得到的算式</param> /// <param name="currentFormula">當前算式</param> /// <returns>需要反推:true 正常情況: false</returns> private bool CheckIsNeedInverseMethod(IList <SchoolClockFormula> preFormulas, SchoolClockFormula currentFormula) { // 防止出現全零的情況 if (currentFormula.LatestTime.Hours == 0 && currentFormula.LatestTime.Minutes == 0 && currentFormula.LatestTime.Seconds == 0) { return(true); } // 判斷當前算式是否已經出現過 if (preFormulas.ToList().Any(d => d.LatestTime.Hours == currentFormula.LatestTime.Hours && d.LatestTime.Minutes == currentFormula.LatestTime.Minutes)) { return(true); } return(false); }