diff --git a/api/Lobby.cs b/api/Lobby.cs index 7663844..a16d151 100644 --- a/api/Lobby.cs +++ b/api/Lobby.cs @@ -1,14 +1,17 @@ +using Microsoft.Net.Http.Headers; + public class Lobby { public static int MaxPlayers = 8; public static int MaxRounds = 8; - public static int CardsDealtPerPlayer = 10; + public static int CardsDealtPerPlayer = 8; public string Id { get; private set;} public List Players { get; private set;} = new List(); public List QuestionDeck { get; private set;} public List AnswerDeck { get; private set;} public List PlayedCards { get; private set;} = new List(); - public int RoundNumber {get; set;} = 01; + public Dictionary LobbyHistory {get;set;} = new(); + public int RoundNumber {get; set;} = 1; public int JudgeIndex { get; set;} public string CurrentQuestionCard => QuestionDeck[RoundNumber]; public Lobby(string id) @@ -16,7 +19,7 @@ public Lobby(string id) Id = id; QuestionDeck = ShuffleCards(GetQuestionCards()); AnswerDeck = ShuffleCards(GetAnswerCards()); - JudgeIndex = new Random().Next(0, Players.Count); + JudgeIndex = 0; } List GetQuestionCards() => new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "Cards-PNG")).GetFiles("*Black*", new EnumerationOptions() {RecurseSubdirectories = true}).Select(e => e.Name.Replace(".png","")).ToList(); @@ -32,10 +35,13 @@ public bool PlayCardForPlayer(string playerId, string cardUrl) if (Players.IndexOf(player) == JudgeIndex) return false; // Validity: Check if the player has the card in their hand if (!player.Cards.Contains(cardUrl)) return false; + // Remove the card from the player's hand player.Cards.Remove(cardUrl); + // Add the card to the played cards PlayedCards.Add(cardUrl); + // set the lastplayed card for the player player.LastPlayedCard = cardUrl; return true; @@ -58,7 +64,12 @@ public string JudgeVoteOnCard(string cardUrl) { player.LastPlayedCard = null; } - JudgeIndex = new Random().Next(0, Players.Count); + JudgeIndex ++; + if (JudgeIndex >= Players.Count) { + // if the judge index is greater than the number of players, reset it to 0 + JudgeIndex = 0; + } + LobbyHistory.Add(CurrentQuestionCard, cardUrl); return Winner.Name + " won the round! with Card this card , they now have " + Winner.Score + " points!"; } } diff --git a/api/Program.cs b/api/Program.cs index 35fd86d..fb0ace3 100644 --- a/api/Program.cs +++ b/api/Program.cs @@ -4,7 +4,7 @@ var builder = WebApplication.CreateBuilder(args); var players = new List(); var lobbies = new List(); -var names = new List() { "Janus (Windows 3.1 and MSDOS 5)", "Anaheim (Microsoft Edge)", "Astro (MS DOS 6)", "Bandit (Schedule Plus)", "Sparta (Windows for Workgroups 3.1)", "Snowball (Windows for Workgroups 3.11)", "Chicago (Windows 95)", "Memphis (Windows 98)", "Millennium (Windows ME)", "Razzle (Windows NT 3.1)", "Daytona (Windows NT 3.5)", "Tukwila (Windows NT 4)", "Cairo", "[] (Windows 2000)", "Whistler (Windows XP)", "Longhorn (Windows Vista)", "Vienna (Windows 7)", "Midori (Application Shim for Singularity, used in SQLPAL)", "Blue (Windows 8.1)", "Threshold (Windows 10)", "Redstone (Windows 10 Creators Update)", "Sun Valley (Windows 11)", "Hudson Valley (Windows 12?)", "Pegasus (Windows CE 1.0)", "Rapier (Windows Pocket PC 2000)", "Maldives (Windows Phone 7)", "Red Dog (Azure)", "Singularity (MSR Managed OS)", "Denali (SQL Server 2012)", "Thunder (Visual Basic 1.0)", "Bullet (MS Mail 3.0)", "Opus (Word for Windows v1.0)", "Wren (Outlook)", "Utopia (Bob UI)", "Marvel (MSN)", "Argo (Zune Player)", "KittyHawk (Visual Studio Lightswitch)", "DirectX Box (Xbox)", "Natal (Kinect)", "Natick (Underwater DC Pod)", "Roslyn (.net compiler platform)", "Aspen (Visual Studio 6.0)", "Rainier (Visual Studio.NET 2002)", "Whidbey (Visual Studio 2005)" }; +var names = new List() {"Janus (Windows 3.1 and MSDOS 5)", "Anaheim (Microsoft Edge)", "Astro (MS DOS 6)", "Bandit (Schedule Plus)", "Sparta (Windows for Workgroups 3.1)", "Snowball (Windows for Workgroups 3.11)", "Chicago (Windows 95)", "Memphis (Windows 98)", "Millennium (Windows ME)", "Razzle (Windows NT 3.1)", "Daytona (Windows NT 3.5)", "Tukwila (Windows NT 4)", "Cairo", "[] (Windows 2000)", "Whistler (Windows XP)", "Longhorn (Windows Vista)", "Vienna (Windows 7)", "Midori (Application Shim for Singularity, used in SQLPAL)", "Blue (Windows 8.1)", "Threshold (Windows 10)", "Redstone (Windows 10 Creators Update)", "Sun Valley (Windows 11)", "Hudson Valley (Windows 12?)", "Pegasus (Windows CE 1.0)", "Rapier (Windows Pocket PC 2000)", "Maldives (Windows Phone 7)", "Red Dog (Azure)", "Singularity (MSR Managed OS)", "Denali (SQL Server 2012)", "Thunder (Visual Basic 1.0)", "Bullet (MS Mail 3.0)", "Opus (Word for Windows v1.0)", "Wren (Outlook)", "Utopia (Bob UI)", "Marvel (MSN)", "Argo (Zune Player)", "KittyHawk (Visual Studio Lightswitch)", "DirectX Box (Xbox)", "Natal (Kinect)", "Natick (Underwater DC Pod)", "Roslyn (.net compiler platform)", "Aspen (Visual Studio 6.0)", "Rainier (Visual Studio.NET 2002)", "Whidbey (Visual Studio 2005)" }; var app = builder.Build(); // Non-authenticated endpoints first @@ -18,6 +18,18 @@ return Results.File(filePath, "text/html"); }); +// GET => Serve the root +app.MapGet("/Restart", () => +{ + Console.WriteLine(".Restart Request Received"); + + // Clear all lobbies and players + lobbies.Clear(); + players.Clear(); + + return Results.Ok("Game Engine Restarted!"); +}); + // GET => Serve the root app.MapGet("/Card/{CardId}", (string CardId) => { @@ -183,7 +195,13 @@ app.Run(); -string GetRandomName() => names[new Random().Next(0, names.Count)]; +string GetRandomName() { + + // Fetch the list of used lobby names + List usedlobbynames = lobbies.Select(f => f.Id).ToList(); + // Return a random name from the list of names that are not in use + return names.Except(usedlobbynames).OrderBy(x => Guid.NewGuid()).FirstOrDefault(); +}; bool SetAuth(HttpContext context, string Claim = null, string Value = null) { diff --git a/api/bin/Debug/net7.0/api.dll b/api/bin/Debug/net7.0/api.dll index 0881f50..19b41a8 100644 Binary files a/api/bin/Debug/net7.0/api.dll and b/api/bin/Debug/net7.0/api.dll differ diff --git a/api/bin/Debug/net7.0/api.pdb b/api/bin/Debug/net7.0/api.pdb index e18af6e..0b30528 100644 Binary files a/api/bin/Debug/net7.0/api.pdb and b/api/bin/Debug/net7.0/api.pdb differ diff --git a/api/bin/Debug/net7.0/html/index.html b/api/bin/Debug/net7.0/html/index.html index 977561f..86228c1 100644 --- a/api/bin/Debug/net7.0/html/index.html +++ b/api/bin/Debug/net7.0/html/index.html @@ -1,396 +1,367 @@ - - - - - Bedlam - - - - - -
- -
- -
-
-
-
-
-
-
-
-
-
    -
  • - : -   - You -
  • -
- -
-