Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to main #4

Closed
wants to merge 12 commits into from
16 changes: 13 additions & 3 deletions backend/MemeBE/Models/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public int PrepareLaugh(int value, out List<int?> cardsToDelete)
return result;
}

public void ReceiveLaugh(int laughValue)
public void ReceiveLaugh(int laughValue,out List<int?> cardsToDelete)
{
var laughReceived = laughValue;
cardsToDelete = new List<int?>();
var cardsCopy = new List<Card>(PersistentSlot);
PersistentSlot.Clear();
foreach (var card in cardsCopy)
Expand All @@ -66,7 +67,9 @@ public void ReceiveLaugh(int laughValue)
{
if (effect.EffectName.Equals("Shield"))
{
Console.WriteLine("Shiled used laugh");
laughReceived -= effect.Value;
cardsToDelete.Add(card.DeckId);
}
else
{
Expand Down Expand Up @@ -100,9 +103,10 @@ public int PrepareGrumpy(int value, out List<int?> cardsToDelete)
return result;
}

public void ReceiveGrumpy(int grumpyValue)
public void ReceiveGrumpy(int grumpyValue,out List<int?> cardsToDelete)
{
var grumpyReceived = grumpyValue;
cardsToDelete = new List<int?>();
var cardsCopy = new List<Card>(PersistentSlot);
PersistentSlot.Clear();
foreach (var card in cardsCopy)
Expand All @@ -111,7 +115,9 @@ public void ReceiveGrumpy(int grumpyValue)
{
if (effect.EffectName.Equals("Shield"))
{
Console.WriteLine("Shiled used - Grumpy");
grumpyReceived -= effect.Value;
cardsToDelete.Add(card.DeckId);
}
else
{
Expand All @@ -120,7 +126,11 @@ public void ReceiveGrumpy(int grumpyValue)

}
}
grumpyReceived = grumpyReceived < 0 ? 0 : grumpyReceived;

if (grumpyReceived < 0)
{
grumpyReceived = 0;
}
LaughPoints -= grumpyReceived;
if (LaughPoints < 0)
{
Expand Down
23 changes: 22 additions & 1 deletion backend/MemeBE/cards.csv
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,25 @@
27;SurprisedPikachu;/static/jpg/SurprisedPikachu.png;MakeLaugh,1;1
28;SurprisedKirk;/static/jpg/SurprisedKirk.png;MakeLaugh,2;0
29;Takemymoney;/static/jpg/Takemymoney.png;MakeLaugh,2;1
30;RollSafeThink;/static/jpg/OhGodNo.png;Shield,1;2
30;RollSafeThink;/static/jpg/RollSafeThink.png;Shield,1;2
31;Thatsnoneofmybuisness;/static/jpg/Thatsnoneofmybuisness.png;MakeLaugh,1;1
32;TheWhat;/static/jpg/TheWhat.png;MakeLaugh,2;1
33;Thisisfine;/static/jpg/Thisisfine.png;MakeLaugh,1;1
34;TrollFace;/static/jpg/TrollFace.png;MakeGrumpy,1;0
35;TrueStory;/static/jpg/TrueStory.png;MakeGrumpy,1;0
36;WakingUp;/static/jpg/WakingUp.png;MakeLaugh,3;0
37;Watlady;/static/jpg/Watlady.png;MakeGrumpy,1;1
38;WeedGuy;/static/jpg/WeedGuy.png;MakeLaugh,1;1
39;WillyWonka;/static/jpg/WillyWonka.png;MakeLaugh,1;1
40;Duckface;/static/jpg/Duckface.png;MakeGrumpy,1;1
41;Emotionaldamage;/static/jpg/Emotionaldamage.png;MakeGrumpy,3;1
42;Facepalm;/static/jpg/Facepalm.png;MakeGrumpy,2;1
43;Foreveralone;/static/jpg/Foreveralone.png;MakeGrumpy,1;1
44;Genius;/static/jpg/Genius.png;MakeGrumpy,1;1
45;GoodGuy;/static/jpg/GoodGuy.png;MakeGrumpy,2;0
46;DistractedBoyfriend;/static/jpg/DistractedBoyfriend.png;MakeLaugh,1;1
47;CryingCat;/static/jpg/CryingCat.png;MakeGrumpy,2;0
48;All;/static/jpg/All.png;MakeLaugh,1;0
49;AwkwardLittleGirl;/static/jpg/AwkwardLittleGirl.png;MakeGrumpy,1;1
50;Buffeddoge;/static/jpg/Buffeddoge.png;Buff,2;2
51;Cheers;/static/jpg/Cheers.png;MakeLaugh,1;1
42 changes: 36 additions & 6 deletions backend/MemeBE/hubs/GameHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{
await Clients.Caller.SendAsync("LobbyError", "Room does not exist... yet");
}
else if (room.GameStarted)

Check warning on line 68 in backend/MemeBE/hubs/GameHub.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
{
await Clients.Caller.SendAsync("LobbyError", "They started without You... figures");
}
Expand Down Expand Up @@ -118,12 +118,12 @@
// Zainicjuj gre dla kaźdego gracza
for (int i = 0; i < 5; i++)
{
DrawCard(player, room);

Check warning on line 121 in backend/MemeBE/hubs/GameHub.cs

View workflow job for this annotation

GitHub Actions / build

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

}
}

NextTurn(room);

Check warning on line 126 in backend/MemeBE/hubs/GameHub.cs

View workflow job for this annotation

GitHub Actions / build

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
}
else
{
Expand Down Expand Up @@ -206,8 +206,8 @@
{
Console.WriteLine("End turn - start");
await Clients.Client(room.ActivePlayer.ConnectionID).SendAsync("TurnEnd");
await Clients.Group(room.RoomId)
.SendAsync("ReceiveServerRoomMessage", room.ActivePlayer.Nick + " - turn Ended");
// await Clients.Group(room.RoomId)
// .SendAsync("ReceiveServerRoomMessage", room.ActivePlayer.Nick + " - turn Ended");

if (room.GameStarted)
{
Expand All @@ -220,6 +220,7 @@
{
GameEnded(room);
}
Console.WriteLine("######################");
}
public async Task DrawCard(Player player, Room room)
{
Expand Down Expand Up @@ -275,12 +276,15 @@

public async Task MakeLaugh(Room room, int value, string? targetNick = null)
{

int laughValue = room.ActivePlayer.PrepareLaugh(value, out List<int?> cardsToDelete);
if (string.IsNullOrEmpty(targetNick)) // all players
{
Console.WriteLine("Make laugh to all");
foreach (var player in room.Players.Values)
{
player.ReceiveLaugh(laughValue);
Console.WriteLine("Player " +player.Nick +" is gone take laugh: " + laughValue);
player.ReceiveLaugh(laughValue,out List<int?> cardsToDeleteFromShieldBuff);
// Emit
await Clients.Client(player.ConnectionID).SendAsync("TakeLaugh",player.LaughPoints);
var otherPlayers = GetOtherPlayers(room, player.ConnectionID);
Expand All @@ -290,12 +294,18 @@
}
await Clients.Group(room.RoomId)
.SendAsync("ReceiveServerRoomMessage", Helpers.GetLaughMessage(player.Nick, laughValue));
foreach (var cardId in cardsToDeleteFromShieldBuff)
{
Clients.Group(room.RoomId).SendAsync("RemoveCard", cardId);
}
}
}
else // Single player
{
Console.WriteLine("Make laugh to " + targetNick);
var targetPlayer = room.GetPlayerByNick(targetNick);
targetPlayer.ReceiveLaugh(laughValue);
Console.WriteLine("Player " +targetPlayer.Nick +" is gone take laugh: " + laughValue);
targetPlayer.ReceiveLaugh(laughValue, out List<int?> cardsToDeleteFromShieldBuff);
// emit
await Clients.Client(targetPlayer.ConnectionID).SendAsync("TakeLaugh",targetPlayer.LaughPoints);
var otherPlayers = GetOtherPlayers(room, targetPlayer.ConnectionID);
Expand All @@ -305,24 +315,33 @@
}
await Clients.Group(room.RoomId)
.SendAsync("ReceiveServerRoomMessage", Helpers.GetLaughMessage(targetPlayer.Nick, laughValue));
foreach (var cardId in cardsToDeleteFromShieldBuff)
{
Clients.Group(room.RoomId).SendAsync("RemoveCard", cardId);
}
}

foreach (var cardId in cardsToDelete)
{
Clients.Group(room.RoomId).SendAsync("RemoveCard", cardId);
}

EndTurn(room);
}


public async Task MakeGrumpy(Room room, int value, string? targetNick = null)
{
Console.WriteLine("MakeGrumpy - invoke");
int grumpyValue = room.ActivePlayer.PrepareGrumpy(value, out List<int?> cardsToDelete);
Console.WriteLine("Grumpy Value: " + grumpyValue);
if (string.IsNullOrEmpty(targetNick)) // all players
{
Console.WriteLine("MakeGrumpy - To All");
foreach (var player in room.Players.Values)
{
player.ReceiveGrumpy(grumpyValue);
Console.WriteLine("Player " +player.Nick +" is gone take laugh: " + grumpyValue);
player.ReceiveGrumpy(grumpyValue, out List<int?> cardsToDeleteFromShieldBuff);
// Emit
await Clients.Client(player.ConnectionID).SendAsync("TakeGrumpy",player.LaughPoints);
var otherPlayers = GetOtherPlayers(room, player.ConnectionID);
Expand All @@ -332,12 +351,18 @@
}
await Clients.Group(room.RoomId)
.SendAsync("ReceiveServerRoomMessage", Helpers.GetGrumpyMessage(player.Nick, grumpyValue));
foreach (var cardId in cardsToDeleteFromShieldBuff)
{
Clients.Group(room.RoomId).SendAsync("RemoveCard", cardId);
}
}
}
else // Single player
{
Console.WriteLine("MakeGrumpy - To: " + targetNick);
Console.WriteLine("Player " +targetNick +" is gone take laugh: " + grumpyValue);
var targetPlayer = room.GetPlayerByNick(targetNick);
targetPlayer.ReceiveGrumpy(grumpyValue);
targetPlayer.ReceiveGrumpy(grumpyValue,out List<int?> cardsToDeleteFromShieldBuff);
// emit
await Clients.Client(targetPlayer.ConnectionID).SendAsync("TakeGrumpy",targetPlayer.LaughPoints);
var otherPlayers = GetOtherPlayers(room, targetPlayer.ConnectionID);
Expand All @@ -347,6 +372,10 @@
}
await Clients.Group(room.RoomId)
.SendAsync("ReceiveServerRoomMessage", Helpers.GetGrumpyMessage(targetPlayer.Nick, grumpyValue));
foreach (var cardId in cardsToDeleteFromShieldBuff)
{
Clients.Group(room.RoomId).SendAsync("RemoveCard", cardId);
}
}
foreach (var cardId in cardsToDelete)
{
Expand All @@ -357,6 +386,7 @@

public async Task PlacePersistentCard(Room room, Card card, String targetNick)
{
Console.WriteLine("Place persistant to "+ targetNick);
var targetPlayer = room.GetPlayerByNick(targetNick);
if (targetPlayer.AddCardToPersistentSlot(card).Sucess)
{
Expand Down
15 changes: 11 additions & 4 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</head>
<body>
<div id="lobby">
<h1 class="rotating-text game-title" >Meme: The Gathering</h1>
<h1 class="rotating-text game-title">Meme: The Gathering</h1>
<div id="games-list"></div>
<input type="text" id="player-name-input" placeholder="Player Name"/>
<input type="text" id="room-id-input" placeholder="Room ID"/>
Expand All @@ -36,9 +36,16 @@ <h1 class="rotating-text game-title" >Meme: The Gathering</h1>

</ul>
</div>
<div class="lastMessage">
<div class="roomIdContainer">Invite your friends - Room ID: <span data-type="roomID"></span></div>
<div><button id="startGameButton">Start Game</button></div>
<div class="lastDetails">
<div id="lastCard">

</div>
<div class="lastMessage">
<div class="roomIdContainer">Invite your friends - Room ID: <span data-type="roomID"></span></div>
<div>
<button id="startGameButton">Start Game</button>
</div>
</div>
</div>
</div>

Expand Down
11 changes: 11 additions & 0 deletions client/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ body {
flex-direction: row;
}

.middle .lastDetails {
display: flex;
flex-direction: row;
flex-grow: 1;
}

.middle #lastCard {
width: 250px;
}

.middle .lastMessage {
flex-grow: 1;
display: flex;
Expand Down Expand Up @@ -210,6 +220,7 @@ body {
border-radius: 6px;
display: inline-block;
flex: 0 0 auto;
cursor: pointer;

}

Expand Down
Binary file added client/static/jpg/All.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/AwkwardLittleGirl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Buffeddoge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Cheers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/CryingCat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/DistractedBoyfriend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Duckface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Emotionaldamage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Facepalm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Foreveralone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Genius.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/GoodGuy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Thatsnoneofmybuisness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/TheWhat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Thisisfine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/TrollFace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/TrueStory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/WakingUp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/Watlady.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/WeedGuy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/static/jpg/WillyWonka.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions client/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $(document).ready(function () {

function initServer() {
connection = new signalR.HubConnectionBuilder()
.withUrl("https://magicthememeingapiprod.azurewebsites.net/GameHub")
.withUrl("https://578d-87-206-130-93.ngrok-free.app/GameHub")
//.withUrl("https://memethegatheringapi.azurewebsites.net/GameHub")
// .withUrl("https://578d-87-206-130-93.ngrok-free.app/GameHub")
.withAutomaticReconnect()
Expand Down Expand Up @@ -74,7 +74,7 @@ function initReceiveMethods() {
$("#startGameButton").show();
}
$("#playerName").text(playerName);
$("#playerPersistentCards").data('player-name', playerName);
document.querySelector("#playerPersistentCards").setAttribute('data-player-name', playerName);
otherPlayers.forEach((playerName) => addPlayerZone(playerName));
});

Expand Down Expand Up @@ -114,6 +114,19 @@ function initReceiveMethods() {
document.querySelector('#playersZones .other.player[data-player-name="' + target + '"] .points').innerHTML = points;
});

connection.on("TakeGrumpy", function (points) {
$("#playerHP").text(points);
});

connection.on("OtherTookGrumpy", function (target, points) {
document.querySelector('#playersZones .other.player[data-player-name="' + target + '"] .points').innerHTML = points;
});

connection.on("GameEnded", function (message) {
yourTurn = false;
ShowEndGameScreen(message);
});

connection.on("TurnStarted", function () {
yourTurn = true;
});
Expand Down
Loading