-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from MrDave1999/feat/Maps
feat: Create the Maps module
- Loading branch information
Showing
54 changed files
with
1,471 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace CTF.Application.Maps; | ||
|
||
/// <summary> | ||
/// Represents the current information of a map. | ||
/// </summary> | ||
public class CurrentMap | ||
{ | ||
private IMap _nextMap; | ||
private readonly Random _random = new(); | ||
public const int DefaultInterior = 0; | ||
public const int DefaultWeather = 10; | ||
public const int DefaultWorldTime = 12; | ||
public int Id { get; } | ||
public string Name { get; } | ||
public IReadOnlyList<SpawnLocation> AlphaTeamLocations { get; } | ||
public IReadOnlyList<SpawnLocation> BetaTeamLocations { get; } | ||
public int Interior { get; } | ||
public int Weather { get; } | ||
public int WorldTime { get; } | ||
public IMap NextMap => _nextMap; | ||
public int IsLoading { get; set; } | ||
|
||
public CurrentMap( | ||
IMap map, | ||
IReadOnlyList<SpawnLocation> alphaTeamLocations, | ||
IReadOnlyList<SpawnLocation> betaTeamLocations, | ||
int interior = DefaultInterior, | ||
int weather = DefaultWeather, | ||
int worldTime = DefaultWorldTime) | ||
{ | ||
ArgumentNullException.ThrowIfNull(map); | ||
ArgumentNullException.ThrowIfNull(alphaTeamLocations); | ||
ArgumentNullException.ThrowIfNull(betaTeamLocations); | ||
|
||
if (alphaTeamLocations.Count == 0) | ||
throw new ArgumentException(Messages.LocationListCannotBeEmpty, nameof(alphaTeamLocations)); | ||
|
||
if (betaTeamLocations.Count == 0) | ||
throw new ArgumentException(Messages.LocationListCannotBeEmpty, nameof(betaTeamLocations)); | ||
|
||
Id = map.Id; | ||
Name = map.Name; | ||
AlphaTeamLocations = alphaTeamLocations; | ||
BetaTeamLocations = betaTeamLocations; | ||
Interior = interior; | ||
Weather = weather; | ||
WorldTime = worldTime; | ||
int nextMapId = (Id + 1) % MapCollection.Count; | ||
_nextMap = MapCollection.GetById(nextMapId).Value; | ||
} | ||
|
||
public string GetMapNameAsText() => $"Map: ~w~{Name}"; | ||
public void SetNextMap(IMap nextMap) | ||
{ | ||
ArgumentNullException.ThrowIfNull(nextMap); | ||
_nextMap = nextMap; | ||
} | ||
|
||
public SpawnLocation GetRandomSpawnLocation(TeamId team) => team switch | ||
{ | ||
TeamId.Alpha => AlphaTeamLocations[_random.Next(AlphaTeamLocations.Count)], | ||
TeamId.Beta => BetaTeamLocations[_random.Next(BetaTeamLocations.Count)], | ||
_ => throw new NotSupportedException(Messages.SpawnLocationFailure) | ||
}; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace CTF.Application.Maps; | ||
|
||
public interface IMap | ||
{ | ||
int Id { get; } | ||
string Name { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
namespace CTF.Application.Maps; | ||
|
||
/// <summary> | ||
/// Represents the total wait time for the new map to load. | ||
/// </summary> | ||
public class LoadTime | ||
{ | ||
private readonly Action _onLoadingMap; | ||
private readonly Action _onLoadedMap; | ||
private int _interval = MaxLoadTime; | ||
public const int MaxLoadTime = 6; | ||
|
||
/// <summary> | ||
/// Displays the load time in the game. | ||
/// </summary> | ||
public string GameText { get; private set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Represents the interval in seconds. | ||
/// </summary> | ||
public int Interval => _interval; | ||
|
||
public LoadTime(Action onLoadingMap, Action onLoadedMap) | ||
{ | ||
ArgumentNullException.ThrowIfNull(onLoadingMap); | ||
ArgumentNullException.ThrowIfNull(onLoadedMap); | ||
_onLoadingMap = onLoadingMap; | ||
_onLoadedMap = onLoadedMap; | ||
} | ||
|
||
/// <summary> | ||
/// Reduces the load time until it reaches zero. | ||
/// </summary> | ||
public void Decrease() | ||
{ | ||
if (_interval == 0) | ||
{ | ||
Reset(); | ||
_onLoadedMap(); | ||
return; | ||
} | ||
|
||
if (_interval == MaxLoadTime) | ||
{ | ||
_onLoadingMap(); | ||
} | ||
|
||
_interval--; | ||
UpdateGameText(); | ||
} | ||
|
||
private void UpdateGameText() => GameText = $"Loading map... ({_interval})"; | ||
private void Reset() | ||
{ | ||
_interval = MaxLoadTime; | ||
GameText = string.Empty; | ||
} | ||
} |
Oops, something went wrong.