using System; using System.Collections.Generic; using System.Linq; using Managers; using TMPro; using UnityEditor; using UnityEngine.InputSystem; namespace GameLogic { public static class MatchLogic { public static MatchRule currentRule; public static MatchResult UpdateMatchResult(Player p, MatchConditionUpdate args, Dictionary mps) { switch (args.Condition) { case WinCondition.Lives: UpdateLives(mps[p], args.count); break; case WinCondition.Score: UpdateScore(mps[p], args.count); break; case WinCondition.Time: UpdateTime(mps[p], args.count); break; } return DetectMatchResult(mps); } public static void UpdateLives(MatchPlayerStatistic mps, int count) { mps.Lives += count; if (mps.Lives <= 0) { mps.IsOut = true; } } public static void UpdateScore(MatchPlayerStatistic mps, int count) { throw new NotImplementedException(); } public static void UpdateTime(MatchPlayerStatistic mps, int count) { throw new NotImplementedException(); } /// /// Detects if a match has concluded. /// Currently only checks if all but on player is out. /// /// Dictonary of the players and their match data. /// Match result object, if the match has concluded private static MatchResult DetectMatchResult(Dictionary mps) { int outPlayers = mps.Count(p => p.Value.IsOut); if (outPlayers == mps.Count - 1) { return new MatchResult(mps); } return null; } } /// /// Data class which records the results of a Match /// public class MatchResult { public Player Winner { get; private set; } public List Opponents { get; private set; } public GUID GameID { get; private set; } public MatchResult(Dictionary mps) { GameID = GUID.Generate(); Winner = mps.First(p => p.Value.IsOut != true).Key; Opponents = mps.Keys.Where(player => player != Winner).ToList(); } } }