This can be seen as the initial state of the project after the released demo.
The changes include:
- New ship models
- Singleton manager structure to keep project scaleable in the future
- Managing players, their settings, character choices, statistics, match setups, controls etc. in a separate decoupled scene
- Main menu with transitions to the arena scene
- Beginnings of a custom audio solution
- Logging with Log4Net
It is really a complete overhaul of the projects structure and management.
82 lines
2.1 KiB
C#
82 lines
2.1 KiB
C#
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<Player, MatchPlayerStatistic> 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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Detects if a match has concluded.
|
|
/// Currently only checks if all but on player is out.
|
|
/// </summary>
|
|
/// <param name="mps">Dictonary of the players and their match data.</param>
|
|
/// <returns>Match result object, if the match has concluded</returns>
|
|
private static MatchResult DetectMatchResult(Dictionary<Player, MatchPlayerStatistic> mps)
|
|
{
|
|
int outPlayers = mps.Count(p => p.Value.IsOut);
|
|
if (outPlayers == mps.Count - 1)
|
|
{
|
|
return new MatchResult(mps);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Data class which records the results of a Match
|
|
/// </summary>
|
|
public class MatchResult
|
|
{
|
|
public Player Winner { get; private set; }
|
|
public List<Player> Opponents { get; private set; }
|
|
public GUID GameID { get; private set; }
|
|
public MatchResult(Dictionary<Player, MatchPlayerStatistic> mps)
|
|
{
|
|
GameID = GUID.Generate();
|
|
Winner = mps.First(p => p.Value.IsOut != true).Key;
|
|
Opponents = mps.Keys.Where(player => player != Winner).ToList();
|
|
}
|
|
}
|
|
} |