Skip to content

Commit

Permalink
Game is operational in a rough fashion. UI Sucks.
Browse files Browse the repository at this point in the history
  • Loading branch information
WillEastbury committed Nov 23, 2023
1 parent a4d6e1a commit 9b90b4b
Show file tree
Hide file tree
Showing 10 changed files with 699 additions and 714 deletions.
19 changes: 15 additions & 4 deletions api/Lobby.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
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<Player> Players { get; private set;} = new List<Player>();
public List<string> QuestionDeck { get; private set;}
public List<string> AnswerDeck { get; private set;}
public List<string> PlayedCards { get; private set;} = new List<string>();
public int RoundNumber {get; set;} = 01;
public Dictionary<string,string> LobbyHistory {get;set;} = new();
public int RoundNumber {get; set;} = 1;
public int JudgeIndex { get; set;}
public string CurrentQuestionCard => QuestionDeck[RoundNumber];
public Lobby(string id)
{
Id = id;
QuestionDeck = ShuffleCards(GetQuestionCards());
AnswerDeck = ShuffleCards(GetAnswerCards());
JudgeIndex = new Random().Next(0, Players.Count);
JudgeIndex = 0;

}
List<string> GetQuestionCards() => new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "Cards-PNG")).GetFiles("*Black*", new EnumerationOptions() {RecurseSubdirectories = true}).Select(e => e.Name.Replace(".png","")).ToList();
Expand All @@ -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;
Expand All @@ -58,7 +64,12 @@ public string JudgeVoteOnCard(string cardUrl)
{
player.LastPlayedCard = null;

Check warning on line 65 in api/Lobby.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
}
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 <a href='/Card/" + cardUrl + " '>this card </a>, they now have " + Winner.Score + " points!";
}
}
22 changes: 20 additions & 2 deletions api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var builder = WebApplication.CreateBuilder(args);
var players = new List<Player>();
var lobbies = new List<Lobby>();
var names = new List<string>() { "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<string>() {"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
Expand All @@ -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) =>
{
Expand Down Expand Up @@ -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<string> 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)

Check warning on line 206 in api/Program.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 206 in api/Program.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
Expand Down
Binary file modified api/bin/Debug/net7.0/api.dll
Binary file not shown.
Binary file modified api/bin/Debug/net7.0/api.pdb
Binary file not shown.
Loading

0 comments on commit 9b90b4b

Please sign in to comment.