private static DateTime GetCorrespondingDayInCurrentMonth(RankingPosition rankingPosition, DayOfWeek dayOfWeek, DateTime currentMonth) { // Look at the first occurence of the day of week in the month DateTime matchingDayOfWeek = new DateTime(currentMonth.Year, currentMonth.Month, 1, currentMonth.Hour, currentMonth.Minute, currentMonth.Second); while (matchingDayOfWeek.DayOfWeek != dayOfWeek) { matchingDayOfWeek = matchingDayOfWeek.AddDays(1); } // Here we have the correct day of week // Now we add the number of weeks corresponding to the rankingPosition parameter value DateTime correspondingDate = matchingDayOfWeek; switch (rankingPosition) { case RankingPosition.First: // Do nothing break; case RankingPosition.Second: correspondingDate = correspondingDate.AddDays(7); break; case RankingPosition.Third: correspondingDate = correspondingDate.AddDays(14); break; case RankingPosition.Fourth: correspondingDate = correspondingDate.AddDays(21); break; case RankingPosition.Last: // Try to add 4 weeks correspondingDate = correspondingDate.AddDays(28); if (correspondingDate.Month > currentMonth.Month) { // If we are on the next month, subtract 1 week correspondingDate = correspondingDate.AddDays(-7); } break; } return(correspondingDate); }
protected override void ParseValue(string value) { if (String.IsNullOrEmpty(value)) { this.rankingPosition = RankingPosition.First; this.dayOfWeek = DayOfWeek.Monday; } else { string[] values = value.Split(valueSeparator); if (values.Length != 2) { throw new ArgumentException("Invalid value", "value"); } try { int rankingInt; if (!int.TryParse(values[0], out rankingInt)) { throw new ArgumentException("Invalid scale value", "value"); } this.rankingPosition = (RankingPosition)rankingInt; } catch (InvalidCastException) { throw new ArgumentException("Invalid scale value", "value"); } try { int dayInt; if (!int.TryParse(values[1], out dayInt)) { throw new ArgumentException("Invalid scale value", "value"); } this.dayOfWeek = (DayOfWeek)dayInt; } catch (InvalidCastException) { throw new ArgumentException("Invalid scale value", "value"); } } this.invalidateDisplayValue = true; }
public static ExchangeDayOfWeekIndex ToExchangeDayIndex(this RankingPosition position) { switch (position) { case RankingPosition.First: return(ExchangeDayOfWeekIndex.First); case RankingPosition.Second: return(ExchangeDayOfWeekIndex.Second); case RankingPosition.Third: return(ExchangeDayOfWeekIndex.Third); case RankingPosition.Fourth: return(ExchangeDayOfWeekIndex.Fourth); case RankingPosition.Last: return(ExchangeDayOfWeekIndex.Last); } return(ExchangeDayOfWeekIndex.First); }
private static string GetStringValue(RankingPosition position) { switch (position) { case RankingPosition.First: return(StringResources.CustomFrequency_First); case RankingPosition.Second: return(StringResources.CustomFrequency_Second); case RankingPosition.Third: return(StringResources.CustomFrequency_Third); case RankingPosition.Fourth: return(StringResources.CustomFrequency_Fourth); case RankingPosition.Last: return(StringResources.CustomFrequency_Last); } // We never go here return(String.Empty); }
/// <summary> /// Gets the players' ranking. /// </summary> /// <returns>The ranking.</returns> public RankingPosition[] GetRanking() { RankingPosition[] ranking; int playerIndex; if (playersKills != null) { ranking = new RankingPosition[Configuration.instance.GetNumberOfPlayers()]; for (playerIndex = 0; playerIndex < Configuration.instance.GetNumberOfPlayers(); playerIndex++) { ranking [playerIndex] = new RankingPosition(playerIndex, playersKills [playerIndex], playersIcons [playerIndex]); } } else { // Execution is out of normal game flow, we are in a testing session Debug.LogWarning("Statistics: Execution is out of normal game flow, testing session is assumed! Test case " + debugTestCase + " executed."); ranking = TestUtilities.GetDummyRanking(debugTestCase); } Array.Sort(ranking); return(ranking); }
// 3º) GET GLOBAL RANKING POSITION FROM SERVER private IEnumerator GetGlobalPosition(Ranking you, bool reverse) { UnityWebRequest www = UnityWebRequest.Get(BASE_URL + "/ranking/" + you.id + "/position?circuit=" + you.circuit + "&reverse=" + reverse.ToString().ToLower()); yield return(www.SendWebRequest()); int position = -1; if (www.isNetworkError || www.isHttpError) { Debug.LogWarning(www.error); } else { RankingPosition positionObj = (RankingPosition)JsonUtility.FromJson(www.downloadHandler.text, typeof(RankingPosition)); if (positionObj != null) { position = positionObj.position; } } // Next step StartCoroutine(GetRanking(you, position, reverse)); }
/// <summary> /// Produce a dummy ranking. /// </summary> /// <returns>The dummy ranking.</returns> /// <param name="debugTestCase">Test case to generate.</param> public static RankingPosition[] GetDummyRanking(int debugTestCase) { RankingPosition[] ranking; int playerIndex; playerIndex = 0; switch (debugTestCase) { case 1: // Two players ranking = new RankingPosition[2]; ranking [playerIndex] = new RankingPosition(playerIndex, 10, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, -5, madameHo); break; case 2: // Two players with same score ranking = new RankingPosition[2]; ranking [playerIndex] = new RankingPosition(playerIndex, 10, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, madameHo); break; case 3: // Three players ranking = new RankingPosition[3]; ranking [playerIndex] = new RankingPosition(playerIndex, 10, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, -5, madameHo); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 7, sisterRedenta); break; case 4: // Three players with two with same score ranking = new RankingPosition[3]; ranking [playerIndex] = new RankingPosition(playerIndex, 10, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 7, madameHo); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, sisterRedenta); break; case 5: // Three players with two with same score ranking = new RankingPosition[3]; ranking [playerIndex] = new RankingPosition(playerIndex, 7, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, madameHo); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 7, sisterRedenta); break; case 6: // Three players with same score ranking = new RankingPosition[3]; ranking [playerIndex] = new RankingPosition(playerIndex, 7, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 7, madameHo); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 7, sisterRedenta); break; case 7: // Four players with two with same score ranking = new RankingPosition[4]; ranking [playerIndex] = new RankingPosition(playerIndex, 10, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, madameHo); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 7, sisterRedenta); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 0, catLady); break; case 8: // Four players with three with same score ranking = new RankingPosition[4]; ranking [playerIndex] = new RankingPosition(playerIndex, 10, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, madameHo); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, sisterRedenta); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 0, catLady); break; case 9: // Four players with three with same score ranking = new RankingPosition[4]; ranking [playerIndex] = new RankingPosition(playerIndex, 10, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, madameHo); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, sisterRedenta); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 22, catLady); break; case 10: // Four players with same score ranking = new RankingPosition[4]; ranking [playerIndex] = new RankingPosition(playerIndex, 10, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, madameHo); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, sisterRedenta); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 10, catLady); break; case 11: default: // Four players ranking = new RankingPosition[4]; ranking [playerIndex] = new RankingPosition(playerIndex, 10, chefAgata); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, -5, madameHo); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 7, sisterRedenta); playerIndex++; ranking [playerIndex] = new RankingPosition(playerIndex, 0, catLady); break; } Array.Sort(ranking); return(ranking); }