Skip to content

Commit

Permalink
end game on deck empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmlion committed Jan 28, 2024
1 parent b59156d commit fad6e76
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/MemeBE/Models/Deck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ private Queue<Card> PrepareDeckCards(List<Card> cards)
return result;
}

public int GetCount()
{
return deckCards.Count();
}
public Card? DrawCard()
{
return deckCards.Dequeue();
Expand Down
6 changes: 6 additions & 0 deletions backend/MemeBE/Models/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ public Result AddPlayer(Player player)

public Result DrawCard(out Card cardDrawn)
{
if (Deck.GetCount() < 1)
{
cardDrawn = null;

Check warning on line 57 in backend/MemeBE/Models/Room.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
return Result.Fail("No more cards in deck");
}
cardDrawn = Deck.DrawCard();

Check warning on line 60 in backend/MemeBE/Models/Room.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

if (cardDrawn == null)
{
return Result.Fail("No more cards in deck");
Expand Down
9 changes: 9 additions & 0 deletions backend/MemeBE/hubs/GameHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ public async Task EndTurn(Room room)
await Clients.Client(room.ActivePlayer.ConnectionID).SendAsync("TurnEnd");
// await Clients.Group(room.RoomId)
// .SendAsync("ReceiveServerRoomMessage", room.ActivePlayer.Nick + " - turn Ended");

foreach (var player in room.Players.Values)
{
if (player.LaughPoints > 14)
{
room.GameStarted = false;
}
}


if (room.GameStarted)
{
Expand Down

0 comments on commit fad6e76

Please sign in to comment.