-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. New Game Mechanics for hand drawing 2. A card pool provider on a per game-room basis 3. A black card player for each card czar turn 4. A replenishing hand function 5. General improvements and optimizations
- Loading branch information
1 parent
ddb4e70
commit 903eabf
Showing
19 changed files
with
433 additions
and
166 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
This file was deleted.
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 was deleted.
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
45 changes: 45 additions & 0 deletions
45
TheOmenDen.CrowsAgainstHumility.Services/CardPoolBuilding/BlackCardProvider.cs
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,45 @@ | ||
using Microsoft.Extensions.Logging; | ||
using TheOmenDen.CrowsAgainstHumility.Core.Models; | ||
using TheOmenDen.CrowsAgainstHumility.Services.Rooms; | ||
using TheOmenDen.Shared.Extensions; | ||
|
||
namespace TheOmenDen.CrowsAgainstHumility.Services.CardPoolBuilding; | ||
public static class BlackCardProvider | ||
{ | ||
private static readonly object SyncObject = new (); | ||
|
||
private static readonly Dictionary<String, List<BlackCard>> BlackCardToRoomDictionary = new(StringComparer.OrdinalIgnoreCase); | ||
|
||
public static void AddRoomReference(CrowGameRoom room, IEnumerable<BlackCard> blackCards) | ||
{ | ||
var blackCardList = blackCards.ToList(); | ||
|
||
if (!BlackCardToRoomDictionary.ContainsKey(room.RoomName)) | ||
{ | ||
BlackCardToRoomDictionary.Add(room.RoomName, blackCardList); | ||
} | ||
|
||
BlackCardToRoomDictionary[room.RoomName] = blackCardList; | ||
} | ||
|
||
public static BlackCard GetBlackCardForRound(String roomName) | ||
{ | ||
if (!BlackCardToRoomDictionary.TryGetValue(roomName, out var blackCardPool)) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(roomName)); | ||
} | ||
|
||
var blackCardToPlay = blackCardPool.GetRandomElement(); | ||
|
||
lock (SyncObject) | ||
{ | ||
RemoveUsedCardFromPool(roomName, blackCardToPlay); | ||
} | ||
|
||
return blackCardToPlay; | ||
} | ||
|
||
private static void RemoveUsedCardFromPool(String roomName, BlackCard blackCardToRemove) => | ||
_ = BlackCardToRoomDictionary.TryGetValue(roomName, out var blackCards) | ||
&& blackCards.Remove(blackCardToRemove); | ||
} |
50 changes: 50 additions & 0 deletions
50
TheOmenDen.CrowsAgainstHumility.Services/CardPoolBuilding/WhiteCardProvider.cs
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,50 @@ | ||
| ||
using TheOmenDen.CrowsAgainstHumility.Core.Models; | ||
using TheOmenDen.CrowsAgainstHumility.Services.Rooms; | ||
using TheOmenDen.Shared.Extensions; | ||
|
||
namespace TheOmenDen.CrowsAgainstHumility.Services.CardPoolBuilding; | ||
public static class WhiteCardProvider | ||
{ | ||
private static readonly Dictionary<String, IEnumerable<WhiteCard>> WhiteCardPoolByRoomDictionary = new(StringComparer.OrdinalIgnoreCase); | ||
private const int MaxHandSize = 10; | ||
|
||
public static void CreateCardPoolProviderForRoom(CrowGameRoom room, IEnumerable<WhiteCard> whiteCards) | ||
{ | ||
if (WhiteCardPoolByRoomDictionary.ContainsKey(room.RoomName)) | ||
{ | ||
WhiteCardPoolByRoomDictionary.Add(room.RoomName, whiteCards); | ||
} | ||
} | ||
|
||
public static bool RemoveCardPoolFromRoom(CrowGameRoom room) => WhiteCardPoolByRoomDictionary.Remove(room.RoomName); | ||
|
||
public static void AddHandsToPlayers(CrowGameRoom room) | ||
{ | ||
var cardPool = WhiteCardPoolByRoomDictionary[room.RoomName].ToArray(); | ||
|
||
foreach (var player in room.Players) | ||
{ | ||
player.Hand.AddRange(cardPool.GetRandomElements(10)); | ||
} | ||
} | ||
|
||
public static void ReplenishPlayerHand(CrowGameRoom room) | ||
{ | ||
var cardPool = WhiteCardPoolByRoomDictionary[room.RoomName].ToArray(); | ||
|
||
foreach (var playerHand in room.Players | ||
.Where(p => !p.IsCardCzar) | ||
.Select(p => p.Hand)) | ||
{ | ||
if (playerHand.Count >= MaxHandSize) | ||
{ | ||
continue; | ||
} | ||
|
||
var lessThanHandSize = MaxHandSize - playerHand.Count; | ||
|
||
playerHand.AddRange(cardPool.GetRandomElements(lessThanHandSize)); | ||
} | ||
} | ||
} |
Oops, something went wrong.